Hello
I am still trying to learn the ins and out of the algorithmic framework. I have encountered something i dont really have a grasp of yet.
When is the third argument in “def Update(self, algorithm, data)” used in the alpamodel? It seems like a lot of the already implemented alphamodels like RsiAlphaModel.py do not use the last argument in the model. Why is this then necessary, for the model to run? I have implemented a couple of frameworks without utilizing this argument. Is their any example that highlight what this last argument contains and how to use it?
As always, thank you
Lucas
Fred Painchaud
Hi Lucas,
The data param is a Slice object. It contains the new data available in the last slice of time (the period being dependant on your resolution). The algorithm should also contain that info but data is “just that new slice of data”. So it is the last slice of data vs the entire algorithm structure…
Fred
Lucas
Hi Fred
Thank you for the quick response.
Is their any algorithm that actually use this argument? No alphamodel in the alpha framework use this keyword (see attached link). It would be nice to see an example. Please provide that, if you have an example, or i will just mess with it myself, and see its behavior 😊
As always, thank you, and have a good day
Lucas
Fred Painchaud
Hi Lucas,
I have no example right off the bat. My dev env is currently running all tests for LEAN so I don't want to disrupt it too much with me searching the code but I will see if the whole codebase makes use or not of that param somewhere (well of course it will to some extent but I mean to find a good example) and report back later.
Just so you know, it is the exact same type of argument that is passed to OnData… so anything that is done with the usual “data” arg to OnData can be done here… I'm guessing the intent is the same (but it could be slightly different). Provide the last slice of data. Using the same data type for something different, even if Slice has the structures you need, would not be good practice so I can assume the intent is the same.
It's a bit like some OnData examples you know. They have access to the data param but they use the algorithm structure through self.<something> to fetch information they can find in data…
Fred
Lucas
Hi Fred.
If you can post a quick example, I will appreciate it a lot. It does not have to be fancy, a simple script will do fine. Don't rush, let you test run first off course 😊
Thank you
Lucas
Fred Painchaud
Hi Lucas,
You wrote quick example. 😊
Before that, Alphas are custom classes. They don't inherit QCAlgorithm, but AlphaModel. Thus, they have no intrinsic knowledge of the "Algorithm", their almighty owner. Thus the first param to Update. This is simply to have access to the owning algorithm when you code Update. Now, data being the current slice of time, it is just like data in OnData. You should access it to know if you have new data in the last slice and if so, what it is (among other stuff which we won't dive into here). However, the Algorithm Framework is rich. When you use it, you most likely also register your indicators for auto-updating (from helper methods or manually registering them). When you do so, you do not need to consider updating them anymore. The data param would most likely serve that purpose IF you need to update something with latest price action manually before emitting insights. Hope this all makes sense. If it does, then you understand why data is not used so much - it is not necessary really when you are that much into using the advanced features of the platform.
Now the quick example.
Hope you get the idea even though this is a. quick. example. 😊
Fred
Fred Painchaud
sigh
I re-edited my post too many times (3 I believe). Here is the correct code:
Lucas
Hi Fred.
Thank you for the elaborating and the quick example, it's crystal clear now. I appreciate your help 😊
Have a good day
Lucas
Lucas
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!