Let's say I have two Alpha models which I add to my algorithm using a Composite Alpha Model. As the OnSecuritiesChanged Function is triggered every time there is a change in my universe do each of the OnSecuritiesChanged Function in my alphas update after each universe selection?
If so, do they run concurrently or in the order which I add them to the Composite Alpha Model? Also, if I were to execute code that would remove old equities from the universe, rebalance my holdings, etc. (Basically nonessential code in terms of producing insights) in OnSecuritiesChanged would I need this code in both functions, or would one of the functions overwrite the other?
Shile Wen
Dear Jason,
With two different Alpha models, OnSecuritiesChanged will be called on both of the Alpha models. Users don't need to worry about the logistics of managing multiple Alphas, the only concern should be managing each Alpha internally.
I believe the Alpha models run in order in which they are added, so unfortunately they are not run concurrently.
As for removing old equities in the Universe, that should be automatically handled by the Universe Selection Model. The OnSecuritiesChanged method inside an Alpha model is mainly to set up signals that require past data for newly added securities. Thus, if maintaining a portfolio alongside Alpha models, to separate concerns, an OnSecuritiesChanged should be inserted outside of any custom user defined Alpha model classes, in the following manner:
class DynamicVerticalGearbox(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2019, 12, 14)
self.SetCash(100000)
self.AddAlpha(CustomAlphaOne())
self.AddAlpha(CustomAlphaTwo())
def OnData(self, data):
pass
def OnSecuritiesChanged(self, changed):
# do rebalancing here:
pass
class CustomAlphaOne:
def Update(self, algorithm, slice):
return []
def OnSecuritiesChanged(self, algorithm, changes):
# set up indicators for new securities (e.g. SMA)
pass
class CustomAlphaTwo:
def Update(self, algorithm, slice):
return []
def OnSecuritiesChanged(self, algorithm, changes):
pass
Best,
Shile Wen
Jason
Thank you Shile,Â
This makes a lot more sense!
Â
Jason
Jason
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!