/// <summary> /// Function: Internal function to executed the logic for each strategy and its sub-nodes /// </summary> /// <param name="orderDate">reference day</param> /// /// <param name="recursive">true if recursive</param> private void ExecuteLogic_internal(DateTime orderDate, bool recursive, bool force) { if (_parentStrategy.Portfolio != null) { DateTime executionDate = orderDate.AddDays(1); ConcurrentQueue <Strategy> recalcs = new ConcurrentQueue <Strategy>(); Parallel.ForEach(_strategyDB.Values, strat => //foreach(var strat in _strategyDB.Values) { if (strat.InitialDate <= orderDate && strat.FinalDate >= executionDate && strat.Portfolio != null && !strat.IsResidual) { //double oldAUM = strat.GetSODAUM(orderDate, TimeSeriesType.Last); double oldAUM = strat.GetAUM(orderDate, TimeSeriesType.Last); if (double.IsNaN(oldAUM) || oldAUM == 0.0) { double old_strat_aum = strat.GetAUM(orderDate, TimeSeriesType.Last); double old_port_aum = strat.Portfolio[orderDate, TimeSeriesType.Last, TimeSeriesRollType.Last]; Console.WriteLine("ENQUEUE: " + strat + " " + oldAUM + " " + old_strat_aum + " " + old_port_aum); recalcs.Enqueue(strat); } //else // strat.Tree.ExecuteLogic(orderDate, false); //if strat.Tree.ExecuteLogic_internal(orderDate, false, force); } }); //BusinessDay orderDate_local = _parentStrategy.Calendar.GetBusinessDay(orderDate); BusinessDay orderDate_local = Calendar.FindCalendar("All").GetBusinessDay(orderDate); // if (_parentStrategy.Initialized && orderDate_local != null && !_parentStrategy.IsResidual) { _parentStrategy.ExecuteLogic(_parentStrategy.ExecutionContext(orderDate_local), force); if (!recursive) { return; } double newAUM = _parentStrategy.GetSODAUM(orderDate, TimeSeriesType.Last); if (!double.IsNaN(newAUM)) { Boolean recalc = false; Parallel.ForEach(recalcs, strat => { if (strat.InitialDate <= orderDate_local.DateTime && strat.FinalDate >= orderDate_local.AddBusinessDays(1).DateTime&& !strat.IsResidual) { //double oldAUM = strat.GetNextAUM(orderDate, TimeSeriesType.Last); double oldAUM = strat.GetSODAUM(orderDate, TimeSeriesType.Last); if (!double.IsNaN(oldAUM)) { recalc = true; } } }); if (recalc) { _parentStrategy.ClearMemory(orderDate_local.DateTime); _parentStrategy.Tree.ClearOrders(orderDate_local.DateTime, true); _parentStrategy.Tree.ExecuteLogic_internal(orderDate_local.DateTime, false, force); } } } } }
/// <summary> /// Function: Internal function to executed the logic for each strategy and its sub-nodes /// </summary> /// <param name="orderDate">reference day</param> /// /// <param name="recursive">true if recursive</param> private void ExecuteLogic(DateTime orderDate, bool recursive) { if (_parentStrategy.Portfolio != null) { DateTime executionDate = orderDate.AddDays(1); List <Strategy> recalcs = new List <Strategy>(); Parallel.ForEach(_strategyDB.Values, strat => { if (strat.InitialDate <= orderDate && strat.FinalDate >= executionDate && strat.Portfolio != null) { double oldAUM = strat.GetNextAUM(orderDate, TimeSeriesType.Last); if (double.IsNaN(oldAUM) || oldAUM == 0.0) { recalcs.Add(strat); } else { strat.Tree.ExecuteLogic(orderDate, false); } } }); BusinessDay orderDate_local = _parentStrategy.Calendar.GetBusinessDay(orderDate); if (_parentStrategy.Initialized && orderDate_local != null) { _parentStrategy.ExecuteLogic(_parentStrategy.ExecutionContext(orderDate_local)); if (!recursive) { return; } double newAUM = _parentStrategy.GetNextAUM(orderDate, TimeSeriesType.Last); if (!double.IsNaN(newAUM)) { Boolean recalc = false; Parallel.ForEach(recalcs, strat => { if (strat.InitialDate <= orderDate_local.DateTime && strat.FinalDate >= orderDate_local.AddBusinessDays(1).DateTime) { double oldAUM = strat.GetNextAUM(orderDate, TimeSeriesType.Last); if (!double.IsNaN(oldAUM)) { recalc = true; } } }); if (recalc) { _parentStrategy.ClearMemory(orderDate_local.DateTime); _parentStrategy.Tree.ClearOrders(orderDate_local.DateTime, true); _parentStrategy.Tree.ExecuteLogic(orderDate_local.DateTime, false); } } } } }