Back

Weekly Indicator - Research Notebook

Could someone post some super basic code outlining how I would build a weekly RSI for SPY in the research notebook using consolidators?  

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 Stephen,

You can create a weekly indicator using a Calendar consolidator and then subscribing that indicator to the Calendar consolidator. We need to then update our consolidator using historical data. You can do this in the same way you update indicators with the Update method.

 

qb = QuantBook()
# Add Equity
spy = qb.AddEquity("SPY", Resolution.Daily).Symbol

# Create 14 Period RSI
rsi = RelativeStrengthIndex(14)

# Create weekly calendar consolidator
weeklyConsolidator = TradeBarConsolidator(Calendar.Weekly)

# Define DataConsolidated event handler to track RSI values
def OnWeeklyData(sender, updated):
if rsi.IsReady:
print(f"{updated.Time} RSI VALUE: {rsi.Current.Value}")
weeklyConsolidator.DataConsolidated += OnWeeklyData

# Register rsi to weekly consolidator
qb.RegisterIndicator(spy, rsi, weeklyConsolidator)

# Make history call to update consolidator, 180 days guarantees at least 14 weeks of data
history = qb.History(spy, 180, Resolution.Daily)
opens = history.loc["SPY"]["open"]
closes = history.loc["SPY"]["close"]
lows = history.loc["SPY"]["low"]
highs = history.loc["SPY"]["high"]
volumes = history.loc["SPY"]["volume"]
times = history.unstack(0).index.values

# Update consolidator with historical data
for i in range(len(history)):
bar = TradeBar(times[i], spy, opens[i], highs[i], lows[i], closes[i], volumes[i])
weeklyConsolidator.Update(bar)

 

1

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