Hi all;
If the below is wrong, please correct. But I think this explains what is not clear, to me at least, in the documentation about all this.
When you want to start your algo, you almost always have indicators and/or other data, usually in RollingWindows that need to have the last N days of data in them. As an example, say you want the 50 day ExponentialMovingAverage (EMA). Then when your algo starts, you need the last 50 days of close price in the EMA.
So how is this initialized with the last 50 days of data? There could be separate initialization code but that would require additional programming, additional testing, and additional bugs (as you get a bug per X lines of code). So instead it goes back N days and runs using the data from those days to “warm up” (i.e. initialize) the data.
Hence the purpose of the IsWarmingUp property. When true, you should do everything in your methods except place orders. The primary purpose is to update indicators and add to rolling windows. But if you have other data that is changed as the day(s) progress, you need to do that too.
How many days is this done for? That is where SetWarmingUp() comes in. You set how many calendar days you need to warm up for. As indicators and pretty much everything else works off days the markets are open, you need to set the number of days to: calendar
numCalendarDays = (numMarketDays * 7 / 5) * 1.1 + 2
The “* 1.1 + 2” is to cover holidays. It's fine if you need 50 days and the warmup runs for 52 days.
Three important notes about warmup:
- If you set a warm up period of 50 days and you have a 200 day indicator - you'll get no error from any of this and it will then start processing orders for real.
- IsWarmingUp will be true until warmup is complete, then will be false thereafter. It will never revert back to true.
- Time events do not fire during the warmup period. Only data based events fire.
Next there's IsReady which is a property for RollingWindows, indicators, and maybe some other stuff. This is letting you know if you have fully populated a collection. If you have a 200 day EMA and you set the warmup period to 50 days, then the indicator.IsReady will be false until you have had 150 days of live trading.
Fundamentally, if you set the warm up period correctly, then once the warm up is complete, every collection.IsReady should be true.
In addition, IsReady does not tell you if you've updated your collection at the end of the day. It merely tells you it's been fully initialized. So this is not a measure of today's numbers have been added.
And like IsWarmingUp, once IsReady is true, it will never revert to false.
All the examples show the code testing IsReady every time it uses a collection. I think this is a bad way to approach this issue. I recommend that in the event OnWarmupFinished(self), walk all collections and if any has IsReady == false, throw an exception and exit the app - because you have a run time error.
And if all are true, then they never need to be tested while running as they cannot revert to false.
Fred Painchaud
Hi David,
I read quickly but it looks like it is right, except for custom-made indicators. In those, you can, if you want and need to, make an indicator not ready at any point once it is ready. So then, IsReady does not necessarily stay true when true once…
But warm up does happen only once at the beginning of the algo, yes.
FInally, I am not sure I understand what you mean by “In addition, IsReady does not tell you if you've updated your collection at the end of the day. It merely tells you it's been fully initialized. So this is not a measure of today's numbers have been added.” If the code you wrote for IsReady includes a check to make sure that your collections are full, then IsReady checks that. Same thing with automatic warm up, if WarmUpPeriod is not properly set in your indicator, warming up will not use the right number of bars.
Thanks for your overview of all this. It can help many people.
Fred
David Thielen
Hi;
I would view IsReady being able to go false in a custom indicator as a bug, not a feature. For that case they should add a property for their additional on/off status. (Yes, they can use IsReady this way, but they shouldn't).
On the second point, I read IsReady at first as a way of telling me that it was updated with the latest day's data. That is not what it is indicating.
BTW - You are welcome to add the above to the documentation.
Fred Painchaud
Hi David,
If you use an additional “on/off” status, then the rest of LEAN won't know about it and then, IsReady could be true (since you don't change it anymore) but your custom “on/off” status is OFF… IsReady establish a protocol where when IsReady is true, the indicator is ready and when IsReady is false, the indicator is not ready. But it's not critical, this is for more custom stuff - I was only saying as I am using those - I changed the usual “indicator polling” model into an “indicator event triggering” model.
Sorry, I have no control in adding information into the docs. However, this thread is certainly read by people who do.
Cheers,
Fred
David Thielen
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!