|
Hi,
I've noticed that when the StrategyManager starts a Strategy_ in StrategyMode.Backtest, Framework.Clock.DateTime is not set to DataSimulator.DateTime1 until after OnStrategyInit and OnStrategyStart are called, whereas when the StrategyManager starts a Strategy in StrategyMode.Backtest, Framework.Clock.DateTime is set to DataSimulator.DateTime1 before OnStrategyInit and OnStrategyStart are called.
See the code and output for an example:
public class MyStrategy : SmartQuant.Strategy_.Strategy_ { public MyStrategy(Framework framework, string name) : base(framework, name) { }
protected override void OnStrategyInit() { Console.WriteLine($"OnStrategyInit({Framework.Clock.DateTime})"); } protected override void OnStrategyStart() { Console.WriteLine($"OnStrategyStart({Framework.Clock.DateTime})"); } } public partial class MyScenario : SmartQuant.Strategy_.Scenario_ { public MyScenario(Framework framework) : base(framework) { }
public override void Run() { strategy = new MyStrategy(framework, "Backtest");
Initialize(); strategy.DataSimulator.DateTime1 = new DateTime(2011,11,11); strategy.DataSimulator.DateTime2 = new DateTime(2011,11,11);
Start(strategy, StrategyMode.Backtest); } } Prints: 09/27/2019 21:52:13.341 Scenario::StartStrategy Backtest in Backtest OnStrategyInit(01/01/0001 00:00:00.000) OnStrategyStart(01/01/0001 00:00:00.000) 09/27/2019 21:52:13.349 Data simulator thread started 09/27/2019 21:52:13.363 Data simulator thread stopped 09/27/2019 21:52:13.365 Data run done[OpenQuant], count = 0 ms = 3 event/sec = 0 09/27/2019 21:52:13.370 Scenario::StartStrategy Done
VERSUS
public class MyStrategy : Strategy { public MyStrategy(Framework framework, string name) : base(framework, name) { } protected override void OnStrategyInit() { Console.WriteLine($"OnStrategyInit({framework.Clock.DateTime})"); } protected override void OnStrategyStart() { Console.WriteLine($"OnStrategyStart({framework.Clock.DateTime})"); } }
public partial class MyScenario : Scenario { public MyScenario(Framework framework) : base(framework) { }
public override void Run() { strategy = new MyStrategy(framework, "Backtest");
Initialize(); strategy.DataSimulator.DateTime1 = new DateTime(2011,11,11); strategy.DataSimulator.DateTime2 = new DateTime(2011,11,11);
StartStrategy(strategy, StrategyMode.Backtest); } } Prints: 09/27/2019 22:01:17.096 Scenario::StartStrategy Backtest 09/27/2019 22:01:17.096 StrategyManager::StartStrategy Backtest OnStrategyInit(11/11/2011 00:00:00.000) OnStrategyStart(11/11/2011 00:00:00.000) 09/27/2019 22:01:17.098 StrategyManager::StartStrategy Backtest has no data requests in backtest mode, stopping... 09/27/2019 22:01:17.098 StrategyManager::StopStrategy Backtest 09/27/2019 22:01:17.098 Scenario::StartStrategy Done
This is a problem for me because I am using Strategy_ and programmatically selecting which futures contract to begin with based on Clock.DateTime. It appears to be a bug to me because logically I think OnStrategyInit and OnStrategyStart should be called on the DateTime that the backtest starts as it is with the Strategy class. Is this a bug or intentional by design of StrategyManager_?
|