Hello,
I'm having trouble using a QuoteBarConsolidator - the minute (or second) data is offset by one bar, meaning the period reported for the consolidated bar is different from the actual data used to construct the bar: the minute (or second) data is off by one bar.
For example:
Create a backtest for Oanda "EURJPY" forex data, using Resolution.Minute data
Build a QuoteBarConsolidator using a TimeSpan.FromHours(1)
The resulting hourly bar is emited every hour with the correct Time, but uses the wrong span:
Expected:
00:00 to 01:00 bar should use 00:00 open price and 00:59 close price for the hour.
Observed:
00:00 to 01:00 bar uses the 00:01 open price and the 01:01 close price for the hour - off by 1 bar
I've tested using 1 second and 1 minute Resolution data; and the behavour is the same.
You can see this in the log below:
2018-05-01 00:00:00 Launching analysis for 6f9472b6d2abdb66e7781da9c917d361 with LEAN Engine v2.4.0.0.3729
...
2018-05-01 00:00:00 Start of hour --> 2018-05-01T00:00:00 - 2018-05-01T00:01:00 : o 132.0975, c 132.1005
2018-05-01 00:01:00 Next bar --> 2018-05-01T00:01:00 - 2018-05-01T00:02:00 : o 132.097, c 132.0935
2018-05-01 00:59:00 End of hour --> 2018-05-01T00:59:00 - 2018-05-01T01:00:00 : o 132.0775, c 132.0775
2018-05-01 01:00:00 We got a new HOUR
2018-05-01 01:00:00 2018-05-01T01:00:00 new HOURLY bar from 2018-05-01T00:00:00 to 2018-05-01T01:00:00 : 132.097 132.121 132.071 132.085
2018-05-01 01:00:00 Start of hour --> 2018-05-01T01:00:00 - 2018-05-01T01:01:00 : o 132.081, c 132.085
2018-05-01 01:01:00 Next bar --> 2018-05-01T01:01:00 - 2018-05-01T01:02:00 : o 132.0815, c 132.081
2018-05-01 01:59:00 End of hour --> 2018-05-01T01:59:00 - 2018-05-01T02:00:00 : o 132.0535, c 132.0535
2018-05-01 02:00:00 We got a new HOUR
2018-05-01 02:00:00 2018-05-01T02:00:00 new HOURLY bar from 2018-05-01T01:00:00 to 2018-05-01T02:00:00 : 132.0815 132.082 132.022 132.06
2018-05-01 02:00:00 .
2018-05-01 02:00:00 ..
2018-05-01 02:00:00 ...
2018-05-01 02:00:00 Start of hour --> 2018-05-01T02:00:00 - 2018-05-01T02:01:00 : o 132.0565, c 132.06
Am I doing the wrong thing here, or is this a bug. I haven't seen anyone else mention this problem.
My use case is that I want to use fine grain data to make trading decisions, but need hourly data to provide context for those decisions. I thought a consolidator was the correct approach to take.
Thanks,
Kel.
Michael Manus
could you please use the TIME variable to log the time when the new candle was emitted.
and post back if the problem still accours: from the example library a sample with time:
https://github.com/QuantConnect/Lean/blob/c926b68ed452c3afdbbda3eeae2084f53eab859d/Algorithm.Python/UpdateOrderRegressionAlgorithm.py#L118
use this line to test it:
https://github.com/QuantConnect/Lean/blob/cbd953437f987392f2c2e154adcb7d43d684b7f1/Algorithm.Python/DelistingEventsAlgorithm.py#L74
the time on the left site is only the log time......but you want the time when it really happens which tells you the TIME property
Michael Manus
oh you are a c# user ok....
in c# its i think even easier...
you will get the idea.....just print what is in Time.ToString()
https://github.com/QuantConnect/Lean/blob/8dc78a3a76944cdece2f9d5a943c4cf1b03eb508/Algorithm.CSharp/BasicTemplateCryptoAlgorithm.cs#L93
but never count on log date....thats what i wanted to say...use algo Time only
Kel G
I was logging the start/end times from the bars contained within my OnNewHour and OnData methods. I've updated the c# example code with logging that also includes the global Time property.
I'm seeing:
Global Time property is equal to the QuoteBar EndTime property, which is what I expected because I'm emitting the consolidated bar after the previous hour finishes, so all good there.
Global Time property is equal to the OnData Slice bar.Time property, which is NOT what I expected: bar.Time is the start of an OHLC period, so global Time should match the bar.EndTime shouldn't it? Otherwise aren't we peeking into the future?
I have included global Time property values in my log output and attached to my reply.
Extract below:
2018-05-01 01:00:00 Time variable is: 2018-05-01T01:00:00: Start of hour --> 2018-05-01T01:00:00 - 2018-05-01T01:01:00 : o 132.081, c 132.085
2018-05-01 01:01:00 Time variable is 2018-05-01T01:01:00: Next bar --> 2018-05-01T01:01:00 - 2018-05-01T01:02:00 : o 132.0815, c 132.081
2018-05-01 01:59:00 Time variable is 2018-05-01T01:59:00: End of hour --> 2018-05-01T01:59:00 - 2018-05-01T02:00:00 : o 132.0535, c 132.0535
2018-05-01 02:00:00 Global Time variable says: 2018-05-01T02:00:00
2018-05-01 02:00:00 This is an HOURLY bar from 2018-05-01T01:00:00 to 2018-05-01T02:00:00 : 132.0815 132.082 132.022 132.06
2018-05-01 02:00:00 .
2018-05-01 02:00:00 ..
2018-05-01 02:00:00 ...
2018-05-01 02:00:00 Time variable is: 2018-05-01T02:00:00: Start of hour --> 2018-05-01T02:00:00 - 2018-05-01T02:01:00 : o 132.0565, c 132.06
Starting from the top of the log, I read the following:
1) At backtester time of 01:00 we emit a 1min bar via OnData(Slice data) that spans 01:00 to 01:01, with an open price of 132.081 - this is ignored by the Hourly consolidator
2) At backtester time of 01:01 we emit a 1min bar that spans 01:01 to 01:02 with an open price of 132.0185 - this is used by the hourly consolidator as the 01:00 to 02:00 open price. This is wrong because it's off by one period (in our case 1x one minute bar). If we used second bars, we'd be off by 1x one second bar.
The same problem occurs with the hourly close price - it uses the close of the 02:00 to 02:01 period, instead of the close of the 01:59 to 02:00 period.
My updated logging example (in c#) is attached, as is the backtest.
Michael Manus
there is a support tab inside the algorithm lab on the left side if you want to share it with the support team and get an answer
Michael Manus
hmm maybe the second bar is used because that is the price of first bar closing
lets what they will answer
Kel G
Thanks very much for looking at my post and offering some suggestions, much appreciated.
Kel G
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!