In my efforts to create consolidated bars with historical data, I've tested creating them with minute and hour resolution data, it is very strange that the close prices produced by the 2 are different.
Attached is an algorithm where I try to replicate the issue.
Before anyone suggests me to use self.SetWarmup, yes I am aware that ite exists and how to use it, my goal here is to understand why minute and hour resolution data produce different consolidated bars of the same period.
Li Cheng
Sorry I forgot to attach the backtest.
Fred Painchaud
Hi Li,
In a nutshell, you are comparing apples to oranges (hence the name of the backtest below - Ugly Orange Hippopotamus (? 😊)).
The detail:
1- Your usage of TradeBar() was incorrect.
2- Your history call uses data prior to the beginning of your algo because it is in Initialize while your sub uses data in your algo period.
3- You were using the same consolidator to consolidate two sources of data (your sub and your history).
Study the included backtest to understand what I mean above. When the puzzle is in order, consolidation is the same.
Fred
Vladimir
Li Cheng,
Here is my way of proving that both four hour consolidators (from minute bars and from hour bars) are identical.
Li Cheng
Hi Fred and Vladimir,
Thank you guys for the replies! I really appreciate it since yesterday was a holiday (Good Friday) and you guys are still active in the community!
From the code that you guys sent, I realized the issue was with the first parameter in the TradeBar() function, this is what I had:
What I should've done was the following for hour historical data:
And the following for minute historical data:
However, I do have an additional question, do you guys know the purpose or significance of the last parameter of the TradeBar function? I find that the consolidated bars created are the same with or without it like so:
Fred Painchaud
Hi Li,
Sure. The last param is the period, so the length of the bar in time. It is 1 minute by default.
https://lean-api-docs.netlify.app/classQuantConnect_1_1Data_1_1Market_1_1TradeBar.html#aaa17d59d6bc7360681dc465cf549e823
So when your bars are actually 1-minute bars, the last param is not really needed since it is 1 minute by default.
Fred
Li Cheng
Hi Fred, thanks for sharing the link to the TradeBar() function from Lean's api documentation!
This is extremely helpful!
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!