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

Live Strategy does not get quotes after run in backtest
http://www.smartquant.com/forums/viewtopic.php?f=60&t=14891
Page 1 of 1

Author:  abasqd [ Wed Mar 13, 2019 1:07 pm ]
Post subject:  Live Strategy does not get quotes after run in backtest

I would like to run a strategy in backtest mode to perform some calculations on historical data, then run in live. However when I run in backtest followed by live my strategy does not receive any bids or asks. See the code and output:


My Scenario:

public class Realtime : Scenario
{
public Realtime(Framework framework)
: base(framework)
{ }

public override void Run()
{
strategy = new MyStrategy(framework, "MyStrategy");
Instrument instrument = InstrumentManager.Get("EURUSD");
strategy.AddInstrument(instrument);

DataSimulator.SubscribeQuote = true;
DataSimulator.DateTime1 = new DateTime(2018, 01, 02, 00, 00 ,00);
DataSimulator.DateTime2 = new DateTime(2018, 01, 02, 00, 5 ,00);

StartStrategy(StrategyMode.Backtest);

BarFactory.Clear();
BarFactory.Add(instrument, BarType.Time, 1, BarInput.Middle);

strategy.DataProvider = ProviderManager.GetDataProvider("IB");

StartStrategy(StrategyMode.Live);

}
}

My Strategy:

public class MyStrategy : InstrumentStrategy
{
public MyStrategy(Framework framework, string name)
: base(framework, name)
{
}

protected override void OnStrategyStart()
{
Console.WriteLine($"StartStrategy({Mode})");
}

protected override void OnBid(Instrument instrument, Bid bid)
{
Console.WriteLine(bid);
}
protected override void OnAsk(Instrument instrument, Ask ask)
{
Console.WriteLine(ask);
}

protected override void OnBar(Instrument instrument, Bar bar)
{
Console.WriteLine(bar);
}
}


When I run the scenario I get this output:

03/13/2019 21:02:42.137 Scenario::StartStrategy Backtest
03/13/2019 21:02:42.137 StrategyManager::StartStrategy MyStrategy
StartStrategy(Backtest)
03/13/2019 21:02:42.147 DataSimulator::Subscribe EURUSD
03/13/2019 21:02:42.147 Data simulator thread started
Bid 01/02/2018 00:00:00.000 4 10 1.20095 0
Ask 01/02/2018 00:00:00.000 4 10 1.201 0
Bid 01/02/2018 00:01:00.000 4 10 1.2009 0
Ask 01/02/2018 00:01:00.000 4 10 1.20095 0
Ask 01/02/2018 00:03:00.000 4 10 1.201 0
Bid 01/02/2018 00:04:00.000 4 10 1.20095 0
Bid 01/02/2018 00:05:00.000 4 10 1.201 0
Ask 01/02/2018 00:05:00.000 4 10 1.20105 0
03/13/2019 21:02:42.224 StrategyManager::StopStrategy MyStrategy
03/13/2019 21:02:42.225 Data simulator thread stopped
03/13/2019 21:02:42.225 Data run done[OpenQuant], count = 6 ms = 49 event/sec = 0
03/13/2019 21:02:42.235 Scenario::StartStrategy Done
03/13/2019 21:02:42.235 Scenario::StartStrategy Live
03/13/2019 21:02:42.235 StrategyManager::StartStrategy MyStrategy
StartStrategy(Live)
Bar [03/13/2019 21:02:43.000 - 03/13/2019 21:02:44.000] Instrument=10 Type=Time Size=1 Open=1.165395 High=1.165395 Low=1.129735 Close=1.129755 Volume=60750000
Bar [03/13/2019 21:02:44.000 - 03/13/2019 21:02:45.000] Instrument=10 Type=Time Size=1 Open=1.129755 High=1.129755 Low=1.129725 Close=1.129725 Volume=22750000
Bar [03/13/2019 21:02:45.000 - 03/13/2019 21:02:46.000] Instrument=10 Type=Time Size=1 Open=1.129725 High=1.129725 Low=1.129715 Close=1.12972 Volume=46500000
Bar [03/13/2019 21:02:47.000 - 03/13/2019 21:02:48.000] Instrument=10 Type=Time Size=1 Open=1.129725 High=1.129725 Low=1.129725 Close=1.129725 Volume=16750000
03/13/2019 21:02:48.975 StrategyManager::StopStrategy MyStrategy

As you can see from the output, the strategy is getting the live bars but not bids, or asks.

If I comment out the line StartStrategy(StrategyMode.Backtest); so that it only runs in live I get the output:

03/13/2019 21:04:08.969 Scenario::StartStrategy Live
03/13/2019 21:04:08.969 StrategyManager::StartStrategy MyStrategy
Provider::Connect timed out : QuantRouter
StartStrategy(Live)
Bid 03/13/2019 21:04:10.584 4 10 1.1297 1000000
Bid 03/13/2019 21:04:10.588 4 10 1.1297 1000000
Ask 03/13/2019 21:04:10.593 4 10 1.12975 3000000
Ask 03/13/2019 21:04:10.597 4 10 1.12975 3000000
Bid 03/13/2019 21:04:10.844 4 10 1.12975 2000000
Ask 03/13/2019 21:04:10.852 4 10 1.12976 3000000
Bid 03/13/2019 21:04:10.873 4 10 1.12975 2000000
Bar [03/13/2019 21:04:10.000 - 03/13/2019 21:04:11.000] Instrument=10 Type=Time Size=1 Open=1.129725 High=1.129755 Low=1.129725 Close=1.129755 Volume=11500000
Ask 03/13/2019 21:04:11.101 4 10 1.12976 7000000
Ask 03/13/2019 21:04:11.118 4 10 1.12976 8000000
Bid 03/13/2019 21:04:11.356 4 10 1.12975 1000000
Ask 03/13/2019 21:04:11.368 4 10 1.12976 11000000
Bid 03/13/2019 21:04:11.379 4 10 1.12974 4500000
Ask 03/13/2019 21:04:11.395 4 10 1.12975 20000000
Bid 03/13/2019 21:04:11.407 4 10 1.12974 4500000
Ask 03/13/2019 21:04:11.412 4 10 1.12975 20000000
Bar [03/13/2019 21:04:11.000 - 03/13/2019 21:04:12.000] Instrument=10 Type=Time Size=1 Open=1.129755 High=1.129755 Low=1.129745 Close=1.129745 Volume=64500000
Bid 03/13/2019 21:04:12.017 4 10 1.12974 4000000
Bid 03/13/2019 21:04:12.261 4 10 1.12975 2000000
Ask 03/13/2019 21:04:12.272 4 10 1.12976 2000000
Bid 03/13/2019 21:04:12.302 4 10 1.12975 2000000
Ask 03/13/2019 21:04:12.321 4 10 1.12976 2000000
Bid 03/13/2019 21:04:12.331 4 10 1.12975 1500000
Bid 03/13/2019 21:04:12.359 4 10 1.12975 2000000
Ask 03/13/2019 21:04:12.388 4 10 1.12976 11000000

So something about running the strategy in backtest before live is causing my strategy to not get bids/asks during live. Any help?

Author:  skuvv [ Thu Mar 14, 2019 9:48 am ]
Post subject:  Re: Live Strategy does not get quotes after run in backtest

Hello,
This is a known issue.
I can recommend you to change type of strategy from InstrumentStrategy to InstrumentStrategy_.
You can find examples with InstrumentStrategy_ in demo solutions.

Author:  abasqd [ Thu Mar 14, 2019 11:09 am ]
Post subject:  Re: Live Strategy does not get quotes after run in backtest

The strangest thing is that I'm quite sure that it was working ok in the morning.

What is InstrumentStrategy_? How is it different?

Author:  skuvv [ Thu Mar 14, 2019 12:34 pm ]
Post subject:  Re: Live Strategy does not get quotes after run in backtest

abasqd wrote:
The strangest thing is that I'm quite sure that it was working ok in the morning.

What is InstrumentStrategy_? How is it different?

Most of differences are placed inside, so for user it is almost the same as InstrumentStrategy.
Just look at SMACrossover_ solution.

Author:  abasqd [ Fri Mar 15, 2019 8:11 am ]
Post subject:  Re: Live Strategy does not get quotes after run in backtest

I've changed to InstrumentStrategy_ and its working, but I'd like to know some more information.

You say it is a known issue, does this mean the developers are working on fixing it?

Can I get more information on Strategy_? Why does it exist, whats it's purpose, why is it useful to have both Strategy and Strategy_ available? Is there any documentation (besides api reference)?

Author:  skuvv [ Fri Mar 15, 2019 9:44 am ]
Post subject:  Re: Live Strategy does not get quotes after run in backtest

abasqd wrote:
I've changed to InstrumentStrategy_ and its working, but I'd like to know some more information.

You say it is a known issue, does this mean the developers are working on fixing it?

Can I get more information on Strategy_? Why does it exist, whats it's purpose, why is it useful to have both Strategy and Strategy_ available? Is there any documentation (besides api reference)?


As I know, Strategy_ is a way to solve a problem.
It should replace the Strategy, but for compatibility we left both versions.

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