Back

Question: Custom Indicators

Hi all,

New to QC and Python here. I'm working on an algo based off of the work of JDMar here: 

https://www.quantconnect.com/forum/discussion/4440/an-intermarket-approach-to-beta-rotation

The idea is to use the ratio of RSI indicators on an asset and its benchmark over the past 4 weeks and to hold the asset (benchmark) if the ratio is greater (less than) 1. The original author chooses just two assets to trade (XLU ande VTI) but I'd like to extend the functionality to choose form multiple sector ETFs. 

Approach I'm using is based off this tutorial example but I'm stuck at creating the custom indicator. I've created a class SymbolData and using a loop (line 62) to initialise the indicator like this, but am confused on the syntax to define the ratio of the two indicators. I'm thinking it should look something like the below but I'm not clear how to plug in the the second argument of IndicatorExtensions.Over() for the RSI of my benchmark (e.g. if I chose SPY as one of my Symbols at a previous step, so the SPY RSI indicator has already been initialised)

https://github.com/QuantConnect/Lean/blob/master/Algorithm.Python/MultipleSymbolConsolidationAlgorithm.py

 

# loop through all our symbols and initialize indicator
for symbol, symbolData in self.Data.items():

# define RSI
symbolData.RSI = RelativeStrengthIndex(self.CreateIndicatorName(symbol, "RSI" + str(RollingWindowSize), self.resolution),RollingWindowSize, MovingAverageType.Simple)

# define relative RSI
for symbol, symbolData in self.Data.items():

# RSI of ETF / RSI Benchmark
symbolData.relRSI = IndicatorExtensions.Over(symbolData.RSI,????????)

 

 

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 Patrick Chen ,

The RSI from the benchmark (SPY) can be defined before self.Data.items() loop and used to get the relative RSI: 

benchmarkRsi = RelativeStrengthIndex(self.CreateIndicatorName("SPY", "RSI" + str(RollingWindowSize), self.resolution),RollingWindowSize, MovingAverageType.Simple)

# loop through all our symbols and initialize indicator
for symbol, symbolData in self.Data.items():

# define RSI
symbolData.RSI = RelativeStrengthIndex(self.CreateIndicatorName(symbol, "RSI" + str(RollingWindowSize), self.resolution),RollingWindowSize, MovingAverageType.Simple)


# RSI of ETF / RSI Benchmark
symbolData.relRSI = IndicatorExtensions.Over(symbolData.RSI, benchmarkRsi)

Please note that we need to implement the indicator registration for automatic updates and a history request to warm them up.

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.


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