SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Mon Dec 09, 2019 5:06 pm

All times are UTC + 3 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Wed Mar 13, 2019 1:07 pm 
Offline

Joined: Thu Dec 06, 2018 1:57 am
Posts: 28
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?


Top
 Profile  
 
PostPosted: Thu Mar 14, 2019 9:48 am 
Offline

Joined: Wed May 05, 2010 9:49 pm
Posts: 562
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.


Top
 Profile  
 
PostPosted: Thu Mar 14, 2019 11:09 am 
Offline

Joined: Thu Dec 06, 2018 1:57 am
Posts: 28
The strangest thing is that I'm quite sure that it was working ok in the morning.

What is InstrumentStrategy_? How is it different?


Top
 Profile  
 
PostPosted: Thu Mar 14, 2019 12:34 pm 
Offline

Joined: Wed May 05, 2010 9:49 pm
Posts: 562
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.


Top
 Profile  
 
PostPosted: Fri Mar 15, 2019 8:11 am 
Offline

Joined: Thu Dec 06, 2018 1:57 am
Posts: 28
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)?


Top
 Profile  
 
PostPosted: Fri Mar 15, 2019 9:44 am 
Offline

Joined: Wed May 05, 2010 9:49 pm
Posts: 562
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 3 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group