Back

Alpha Model Architecture

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()?
Update Backtest







0

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.


Hey Adam,

  • Generally, it is a good idea to follow the principle of separation of concerns when designing an algorithm. Insights can be emitted from anywhere, including both OnData and AlphaModel.Update. However, if you are creating an algorithm using the framework, you should keep all your alpha emission calculations within the AlphaModel class.
  • self.Securities will only return a list of securities if self refers to an instantiation of QCAlgorithm, such as in the OnData method. If you are calling MyFunc in MyAlpaModel however, you must also pass in the algorithm to access Securities with algorithm.Securities.
def MyFunc(self, algorithm, data):
for security in algorithm.Securities:
# do something
return # some scalar value for each security


Best
Rahul

2

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.


Update Backtest





0

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.


Loading...

This discussion is closed