Hi All,
I am new to QC, but not to the trading world. My colleagues and I are attempting to migrate our strategies to QC but are running into road blocks when trying to create/use very simple indicators and stock properties, such as RSI, Volume, Last days closing price, and Spread. QC seems to make using these fundamental and extremely simple properties incredibly difficult.
For example, I am trying to re-create a simple RSI buy and sell strategy in QC but to no avail.
The strategy is simple, buy an equity when the RSI is between 50 and 20 on the 5 minute, and ≤ 35 on the 2 minute (see following code). However, this apparently simple concept seems incredibly difficult to implement, and the backtest fails. The API documentation and BootCamp were not helpful at all really, and there seems to be scant amount on tutorial information on implementing simple things such as volume, spread, etc.
My colleagues and I have an entire portfolio of strategies that we would like to migrate to the QC platform, but these issues when implementing simple concepts are preventing us from doing so.
Any help that anyone could give would be extremely appreciated.
class TradeStrategyTest(QCAlgorithm):
openingBar = None
currentBar = None
def Initialize(self):
self.SetStartDate(2017,1, 1) #Set Start Date
self.SetEndDate(2017,7,31) #Set End Date
self.SetCash(100000) #Set Strategy Cash
self.AddEquity("SPY", Resolution.Minute)
RSI1 = self.RSI("SPY", 5)
RSI2 = self.RSI("SPY", 2)
self.SetWarmUp(14)
def OnData(self, data):
if self.IsWarmingUp:
return
if not self.Portfolio["SPY"].Invested:
if ((self.RSI1.Current.Value <=50 and self.RSI1.Current.Value >=20) and self.RSI2.Current.Value <=35):
self.MarketOrder("SPY", 100)
else:
if RSI1.Current.Value > 50:
self.Liquidate()
Jared Broad
The error thrown in the backtest is:
That suggests the algorithm can't find the property RSI1. If you look at the declaration vs use of RSI1 you'll see you're accessing it as a class variable ("self.RSI1") and it was declared as a local variable (RSI1).
The solution is to declare and use RSI1 as a class variable.
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.
Christopher Phillips
Hi Jared Broad , Thanks for the prompt reply. I'll try the fix.
Christopher Phillips
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!