Could someone post some super basic code outlining how I would build a weekly RSI for SPY in the research notebook using consolidators?
Don't have an account? Join QuantConnect Today
QuantConnect Community Discussions
QUANTCONNECT COMMUNITY
LEAN is the open-source algorithmic trading engine powering QuantConnect. Founded in 2012 LEAN has been built by a global community of 180+ engineers and powers more than 300+ hedge funds today.
Join QuantConnect's Discord server for real-time support, where a vibrant community of traders and developers awaits to help you with any of your QuantConnect needs.
The Open-Quant League is a quarterly competition between universities and investment clubs for the best-performing strategy. The previous quarter's code is open-sourced, and competitors must adapt to survive.
Code for building weekly RSI for SPY using consolidators in research notebook requested.
Continue ReadingRefer to our Research Guidelines for high quality research posts.
Create an account on QuantConnect for the latest community delivered to your inbox.
Sign Up Today
|
|
|||||||
|
|
||||||||
|
Weekly Indicator - Research Notebook
Stephen Hyer | February 2020
Could someone post some super basic code outlining how I would build a weekly RSI for SPY in the research notebook using consolidators?
QuantConnectâ„¢ 2025. All Rights Reserved
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)
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
Quick question: can I use Consolidate() too, or do I have to use TradeBarConsolidator() ?
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.
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()?
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.
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.
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
Thanks Alexandre Catarino – very clear.
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!