Back

Alpha Framework Help

Hi Team

I have been playing with the QC Framework and would like some help. I am currently trying to make an alpha model that does various comparisons of current price to 52 week highs and lows. I'm sure it is farily simple to do, but can anyone give me some more guidance. I have been reading the docs and github projects to get a better understanding of how the framework works.

Many thanks

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.


Hi Flame,

Thank you for your question, and your idea is really good. To implement various comparisons of current price to 52-week highs and lows, I build a SymbolData class for this as follows.

class SymbolData:
def __init__(self, algorithm, symbol, lookback):
self.symbol = symbol
self.Max = Maximum(lookback)
self.Min = Minimum(lookback)
### or
# self.Max = algorithm.MAX(symbol, lookback, Resolution.Daily)
# self.Min = algorithm.MIN(symbol, lookback, Resolution.Daily)
self.window = RollingWindow[TradeBar](lookback)
algorithm.Consolidate(symbol, CalendarType.Weekly, self.CalendarTradeBarHandle)

def CalendarTradeBarHandle(self, bar):
self.Max.Update(bar.EndTime, bar.Close)
self.Min.Update(bar.EndTime, bar.Close)
self.window.Add(bar)

First, I use MAX and MIN indicators to get the daily highs and lows. Then, I use Conlidator to get weekly highs and lows from daily data. As you can see, the indicators get updated through RollingWindow. After building this SymbolData Class, all we need to do is to fill the Update and OnSecuritiesChanged methods in the Alpha Model class. Since there is no specific trading logic in your description, for now, I can only write a basic structure for you in the following backtest. You can improve the algorithm based on your trading logic. For more information on Alpha Model, please see examples in this page

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.


Thanks Daniel - appreciate the insight

0

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