24 using System.Collections.Generic;
54 public List<Exception>
Errors {
get;
set; }
87 Errors =
new List<Exception>();
112 var complete = loader.TryCreateAlgorithmInstanceWithIsolator(assemblyPath, algorithmNodePacket.
RamAllocation, out algorithm, out error);
113 if (!complete)
throw new AlgorithmSetupException($
"During the algorithm initialization, the following exception has occurred: {error}");
142 throw new ArgumentException(
"Expected BacktestNodePacket but received " + parameters.
AlgorithmNodePacket.GetType().Name);
147 if (algorithm ==
null)
153 algorithm.Name = job.Name;
156 if (job.PeriodStart ==
default(DateTime))
162 var controls = job.Controls;
170 algorithm.SetParameters(job.Parameters);
174 algorithm.SetAlgorithmMode(job.AlgorithmMode);
182 optionChainProvider.Initialize(initParameters);
187 futureChainProvider.Initialize(initParameters);
194 algorithm.Initialize();
197 if (job.PeriodStart.HasValue)
199 algorithm.SetStartDate(job.PeriodStart.Value);
201 if (job.PeriodFinish.HasValue)
203 algorithm.SetEndDate(job.PeriodFinish.Value);
206 if(job.OutOfSampleMaxEndDate.HasValue)
208 if(algorithm.EndDate > job.OutOfSampleMaxEndDate.Value)
210 Log.
Trace($
"BacktestingSetupHandler.Setup(): setting end date to {job.OutOfSampleMaxEndDate.Value:yyyyMMdd}");
211 algorithm.SetEndDate(job.OutOfSampleMaxEndDate.Value);
213 if (algorithm.StartDate > algorithm.EndDate)
215 algorithm.SetStartDate(algorithm.EndDate);
227 algorithm.PostInitialize();
229 catch (Exception err)
233 }, controls.RamAllocation,
234 sleepIntervalMillis: 100,
244 if (!initializeComplete)
return false;
246 MaximumRuntime = TimeSpan.FromMinutes(job.Controls.MaximumRuntimeMinutes);
252 MaxOrders = job.Controls.BacktestingMaxOrders;
259 Log.
Trace(
"SetUp Backtesting: User: " + job.UserId +
" ProjectId: " + job.ProjectId +
" AlgoId: " + job.AlgorithmId);
260 Log.
Trace($
"Dates: Start: {algorithm.StartDate.ToStringInvariant("d
")} " +
261 $
"End: {algorithm.EndDate.ToStringInvariant("d
")} " +
262 $
"Cash: {StartingPortfolioValue.ToStringInvariant("C
")} " +
263 $
"MaximumRuntime: {MaximumRuntime} " +
264 $
"MaxOrders: {MaxOrders}");
266 return initializeComplete;