Could someone post some super basic code outlining how I would build a weekly RSI for SPY in the research notebook using consolidators?
QUANTCONNECT COMMUNITY
Could someone post some super basic code outlining how I would build a weekly RSI for SPY in the research notebook using consolidators?
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.
Rahul Chowdhury
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)
Paulduring
Quick question: can I use Consolidate() too, or do I have to use TradeBarConsolidator() ?
Louis Szeto
Hi Paulduring
In research environment, we need to use TradeBarConsolidator.
Best
Louis
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.
Paulduring
Understood, thanks.
Are there other reasons to use TradeBarConsolidator() over Consolidate()?
Alexandre Catarino
Hi paulduring ,
You can use either the Consolidate method or the TradeBarConsolidator constructor. The difference is that the Consolidate method looks at the security subscriptions to choose the consolidator type and register it for automatic updates. However, the automatic updates are only available for backtesting and live modes.
If we have subscribed to Equity with any resolution except tick, the consolidator type is TradeBarConsolidator so that we can create a TradeBarConsolidator directly.
Best regards,
Alex
Want to invest in QuantConnect as we build the Linux of quant finance? Check out our Wefunder campaign to join the revolution.
Paulduring
Thanks Alexandre Catarino – very clear.
Stephen Hyer
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!