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

Bars and quotes out of order
http://www.smartquant.com/forums/viewtopic.php?f=60&t=14892
Page 1 of 1

Author:  abasqd [ Wed Mar 13, 2019 1:44 pm ]
Post subject:  Bars and quotes out of order

I have Quote data which is sampled each minute. When I make bars from these quotes I find that OnBarOpen always occurs before OnBid/OnAsk or Instrument.Bid/Instrument.Ask have been updated. See the strategy and it's outputs:

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();
Console.WriteLine($"OnBid: @ {Clock.DateTime}");
Console.WriteLine($"{bid}");
Console.WriteLine($"Instrument.Bid: {Instrument.Bid}");
}
protected override void OnAsk(Instrument instrument, Ask ask)
{
Console.WriteLine();
Console.WriteLine($"OnAsk: @ {Clock.DateTime}");
Console.WriteLine($"{ask}");
Console.WriteLine($"Instrument.Ask {Instrument.Ask}");
}

protected override void OnBarOpen(Instrument instrument, Bar bar)
{
Console.WriteLine();
Console.WriteLine("============================================");
Console.WriteLine($"OnBarOpen @ {Clock.DateTime}");
Console.WriteLine($"bar: {bar}");
Console.WriteLine($"Instrument.Bid: {Instrument.Bid}");
Console.WriteLine($"Instrument.Ask {Instrument.Ask}");

}
}

Output:
============================================
OnBarOpen @ 01/02/2018 00:16:00.000
bar: Bar [01/02/2018 00:16:00.000 - 01/02/2018 00:16:00.000] Instrument=10 Type=Time Size=1 Open=1.201375 High=1.201375 Low=1.201375 Close=1.201375 Volume=0
Instrument.Bid: Bid 01/02/2018 00:15:00.000 4 10 1.2013 0
Instrument.Ask Ask 01/02/2018 00:15:00.000 4 10 1.20135 0

OnBid: @ 01/02/2018 00:16:00.000
Bid 01/02/2018 00:16:00.000 4 10 1.2014 0
Instrument.Bid: Bid 01/02/2018 00:16:00.000 4 10 1.2014 0

OnAsk: @ 01/02/2018 00:16:00.000
Ask 01/02/2018 00:16:00.000 4 10 1.2015 0
Instrument.Ask Ask 01/02/2018 00:16:00.000 4 10 1.2015 0

============================================
OnBarOpen @ 01/02/2018 00:17:00.000
bar: Bar [01/02/2018 00:17:00.000 - 01/02/2018 00:17:00.000] Instrument=10 Type=Time Size=1 Open=1.201475 High=1.201475 Low=1.201475 Close=1.201475 Volume=0
Instrument.Bid: Bid 01/02/2018 00:16:00.000 4 10 1.2014 0
Instrument.Ask Ask 01/02/2018 00:16:00.000 4 10 1.2015 0

OnBid: @ 01/02/2018 00:17:00.000
Bid 01/02/2018 00:17:00.000 4 10 1.20145 0
Instrument.Bid: Bid 01/02/2018 00:17:00.000 4 10 1.20145 0

============================================
OnBarOpen @ 01/02/2018 00:18:00.000
bar: Bar [01/02/2018 00:18:00.000 - 01/02/2018 00:18:00.000] Instrument=10 Type=Time Size=1 Open=1.201575 High=1.201575 Low=1.201575 Close=1.201575 Volume=0
Instrument.Bid: Bid 01/02/2018 00:17:00.000 4 10 1.20145 0
Instrument.Ask Ask 01/02/2018 00:16:00.000 4 10 1.2015 0

OnBid: @ 01/02/2018 00:18:00.000
Bid 01/02/2018 00:18:00.000 4 10 1.20165 0
Instrument.Bid: Bid 01/02/2018 00:18:00.000 4 10 1.20165 0

OnAsk: @ 01/02/2018 00:18:00.000
Ask 01/02/2018 00:18:00.000 4 10 1.2017 0
Instrument.Ask Ask 01/02/2018 00:18:00.000 4 10 1.2017 0

============================================
OnBarOpen @ 01/02/2018 00:19:00.000
bar: Bar [01/02/2018 00:19:00.000 - 01/02/2018 00:19:00.000] Instrument=10 Type=Time Size=1 Open=1.201575 High=1.201575 Low=1.201575 Close=1.201575 Volume=0
Instrument.Bid: Bid 01/02/2018 00:18:00.000 4 10 1.20165 0
Instrument.Ask Ask 01/02/2018 00:18:00.000 4 10 1.2017 0

OnBid: @ 01/02/2018 00:19:00.000
Bid 01/02/2018 00:19:00.000 4 10 1.20145 0
Instrument.Bid: Bid 01/02/2018 00:19:00.000 4 10 1.20145 0

OnAsk: @ 01/02/2018 00:19:00.000
Ask 01/02/2018 00:19:00.000 4 10 1.2015 0
Instrument.Ask Ask 01/02/2018 00:19:00.000 4 10 1.2015 0

============================================
OnBarOpen @ 01/02/2018 00:20:00.000
bar: Bar [01/02/2018 00:20:00.000 - 01/02/2018 00:20:00.000] Instrument=10 Type=Time Size=1 Open=1.201525 High=1.201525 Low=1.201525 Close=1.201525 Volume=0
Instrument.Bid: Bid 01/02/2018 00:19:00.000 4 10 1.20145 0
Instrument.Ask Ask 01/02/2018 00:19:00.000 4 10 1.2015 0

OnBid: @ 01/02/2018 00:20:00.000
Bid 01/02/2018 00:20:00.000 4 10 1.20155 0
Instrument.Bid: Bid 01/02/2018 00:20:00.000 4 10 1.20155 0

OnAsk: @ 01/02/2018 00:20:00.000
Ask 01/02/2018 00:20:00.000 4 10 1.2016 0
Instrument.Ask Ask 01/02/2018 00:20:00.000 4 10 1.2016 0

============================================
OnBarOpen @ 01/02/2018 00:21:00.000
bar: Bar [01/02/2018 00:21:00.000 - 01/02/2018 00:21:00.000] Instrument=10 Type=Time Size=1 Open=1.201625 High=1.201625 Low=1.201625 Close=1.201625 Volume=0
Instrument.Bid: Bid 01/02/2018 00:20:00.000 4 10 1.20155 0
Instrument.Ask Ask 01/02/2018 00:20:00.000 4 10 1.2016 0

OnBid: @ 01/02/2018 00:21:00.000
Bid 01/02/2018 00:21:00.000 4 10 1.20165 0
Instrument.Bid: Bid 01/02/2018 00:21:00.000 4 10 1.20165 0

OnAsk: @ 01/02/2018 00:21:00.000
Ask 01/02/2018 00:21:00.000 4 10 1.2017 0
Instrument.Ask Ask 01/02/2018 00:21:00.000 4 10 1.2017 0



From the output I can see that when a new quote arrives the order of events is:
OnBarOpen
Instrument.Bid, Instrument.Ask Updated
OnBid, OnAsk

Is this intentional behaviour? because it does not make sense to me.... the bar is made from quotes so the quotes should obviously be available in the strategy before the bar. This would make more sense.

Perhaps a setting similar to ReminderOrder.After would be useful?

Author:  skuvv [ Thu Mar 14, 2019 10:05 am ]
Post subject:  Re: Bars and quotes out of order

abasqd wrote:
I have Quote data which is sampled each minute. When I make bars from these quotes I find that OnBarOpen always occurs before OnBid/OnAsk or Instrument.Bid/Instrument.Ask have been updated.

Hello,
yes, it normal behavior.

Quote:
Perhaps a setting similar to ReminderOrder.After would be useful?

In your case it can be helpful.

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