There is a bug when using consolidators with Calendar.Monthly and Calendar.Yearly with daily resolution data.
Specifically, a 1-day consolidated bar will be thrown out of the consolidated handler on the start date of the backtest:
This is the code:
class PensiveFluorescentPinkBeaver(QCAlgorithm):
def Initialize(self):
# Set Start Date
self.SetStartDate(2019, 1, 1)
self.SetEndDate(2019, 5, 1)
# Set Strategy Cash
self.SetCash(100000)
# AAPL
symbol = self.AddEquity("AAPL", Resolution.Daily).Symbol
# Consolidate daily bars to monthly Bars
self.Consolidate(symbol, Calendar.Monthly, self.MonthlyHandler)
def OnData(self, data: Slice):
pass
def MonthlyHandler(self, bar):
self.Debug(bar.Close)
Varad Kabade
Hi Li Cheng,
If we look at the following logs, we can see that we receive the monthly bars:
2018-12-01 00:00:00, 2019-01-01 00:00:00, 38.23389271352019-01-01 00:00:00, 2019-02-01 00:00:00, 40.3426467812019-02-01 00:00:00, 2019-03-01 00:00:00, 42.149051736252019-03-01 00:00:00, 2019-04-01 00:00:00, 46.238592996252019-04-01 00:00:00, 2019-05-01 00:00:00, 48.84810980025
Would you please explain why do you think it is wrong?
Refer to the attached backtest.
Best,
Varad Kabade
Li Cheng
Hi Varad, when creating consolidators with Calandar.Monthly or Calandar.Yearly, the first bar received in the consolidated bar handler is on the start date of the backtest and it is created only with data from the the daily candlebar of that day.
Try printing the OHLCV of the first consolidated bar and you'll see what I mean.
Louis Szeto
Hi Li Cheng
The data received at 2019-01-01 00:00 is coming off the OHLCV of 2018-12-31, so in daily resolution case, it would be correct logic to put it as a indpendent bar from the “real” 2019-01 data. Likewise, 2019-02-01 00:00 received bar will be aggregated into the 2019-01-01:2019-02-01 bar.
Best
Louis
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.
Li Cheng
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!