Suppose we have an algorithm architecture like:
class MyAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetUniverseSelection(**kwargs)
self.SetAlpha(MyAlphaModel()):
def OnData(self, data):
class MyAlphaModel(AlphaModel):
def __init__(self):
pass
def OnSecuritiesChanged(self, algorithm, changes):
pass
def Update(self, algorithm, data):
insights = []
return insights
The objective is to take the dataframe of security close prices, apply some function MyFunc() to it, and emit a single scalar value for each security as an Insight object.
def MyFunc(self, data):
for security in self.Securities:
# do something
return # some scalar value for each security
- Should MyFunc() be called inside MyAlphaModel.Update or OnData?
- Is self.Securities automatically populated with security objects from the set Universe, or should an empty list be instantiated and securities appended in MyAlphaModel.OnSecuritiesChanged()?
Rahul Chowdhury
Hey Adam,
def MyFunc(self, algorithm, data): for security in algorithm.Securities: # do something return # some scalar value for each security
Best
Rahul
Adam W
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!