I think I understand this, but first, lets me say what I think is occurring:
- I create my universe.
- For each symbol, it now calls EmaCrossAlphaModel.OnSecuritiesChanged() for each symbol
- In it it calls algorithm.EMA() - both fast & slow.
- The data from these is saved off in symbolData to be used on each subsequent day.
- The data in this will be updated after the market closes each day - with my not having to call anything to have the update occur.
- It then calls EmaCrossAlphaModel.Update() on each symbol.
- The first time around, the EMA data may not be IsReady and need to pass.
Which then leads to the questions:
- What should I do if I want to return insights when it first starts up?
- Is there a way to have it call Update() again when everything is loaded?
- Is the a call to block the code until the EMA code is fully loaded?
- After the market close, will it then always update the EMA data and then call Update() for the next day's trading (assuming all time resolutions are set to 1 day or more often)?
- Is there a way to insure Update() is called just once/day if I only want to make trades once/day?
thanks - dave
Varad Kabade
Hi David Thielen,
Alpha models primarily consist of an Update method and OnSecuritiesChanged method. Whenever there is a change in the security universe, all changes are notified to the alpha model through the OnSecuritiesChanged method. The update method works similarly to the OnData method in the classic algorithm. We can check if our indicators are ready in the Update method before scanning for signals. We can also ensure that the Update method scans for signal once per day by implementing a simple if/else logic where the condition is based on the algorithm time. Please refer to the following doc on the Alpha model and the following doc for more information on the OnData method( as it is similar to the Update method).
Best,
Varad Kabade
David Thielen
Hi Varad;
Thank you for your reply. You provide a good way to check if, when my OnSecuritiesChanged () is called, to exit and do nothing if it's not after the close of market and/or has not updated the data.
However, that doesn't solve my issue. Because if it is not after close, then my algo does nothing and it never executes trades. What I need is the flip side of that. How do I insure that it will call OnSecuritiesChanged () daily after the market closes and after the data is updated for the closed day?
I'm assuming this is how QC works. But nowhere have I found it to say it does. And so I may be making an invalid assumption.
thanks - dave
Alexandre Catarino
Hi David Thielen ,
OnSecuritiesChanged is called when a data subscription is added or removed, so there is no way to call in other circumstances. For example, if you have a universe that selected the same securities, there is no change, so OnSecuritiesChanged will not be called.
OnSecuritiesChanged will be called after the market close if the universe is changed after the market close. For example, the Coarse(+Fine) universe selection triggers OnSecuritiesChanged at midnight in backtesting and when this data is ready (around 7 am EST) in live trading.
Best regards,Alex
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!