SmartQuant Discussion
http://www.smartquant.com/forums/

Simulator DateTime on StartStrategy Strategy vs Strategy_
http://www.smartquant.com/forums/viewtopic.php?f=60&t=14959
Page 1 of 1

Author:  ambl [ Fri Sep 27, 2019 3:40 pm ]
Post subject:  Simulator DateTime on StartStrategy Strategy vs Strategy_

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_?

Author:  skuvv [ Mon Sep 30, 2019 9:43 am ]
Post subject:  Re: Simulator DateTime on StartStrategy Strategy vs Strategy

Hi,
changes will be available in next release of OQ2014.

Author:  ambl [ Mon Sep 30, 2019 1:42 pm ]
Post subject:  Re: Simulator DateTime on StartStrategy Strategy vs Strategy

Great, Thankyou.

Page 1 of 1 All times are UTC + 3 hours
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/