Hi all,
I am just getting started with Quantconnect. I have some experience with programming, but not with Python. This combination makes for a steep learning curve! The following code is not a serious algorithm, rather an attempt at getting everything working. The problem is, I get a syntax error at the first if statement. I cannot, for the life of me, see why. I'm sure this is a basic noob error, and I would be very grateful if someone could point me in the right direction.
Kind regards
Richard
class HyperActiveAsparagusAlligator(QCAlgorithm):
self.ratioEarliest = none
self.ratioMiddle = none
self.ratioLatest = none
def Initialize(self):
self.SetStartDate(2019, 1, 3)
self.SetEndDate(2021, 1, 3)
self.SetCash(100000)
spy = self.AddEquity("SPY", Resolution.Daily)
spy.SetDataNormalizationMode(DataNormalizationMode.Raw)
aapl = self.AddEquity("PEP", Resolution.Daily)
aapl.SetDataNormalizationMode(DataNormalizationMode.Raw)
def OnData(self, data):
self.Ratio = self.Securities["SPY"].Price / self.Securities["PEP"].Price
# self.Debug (self.Ratio)
#Update the 3 ratio variables
self.ratioEarliest = self.ratioMiddle
self.ratioMiddle = self.ratioLatest
self.ratioLatest = self.ratio
#Plot the ratio
self.Plot("Data Chart", "Ratio", self.Ratio)
#self.Plot("Data Chart", "Asset Price", data["AAPL"].Close)
#If ratio has increased 3 times, sell a and buy b
If self.ratioEarliest < self.ratioMiddle and If self.ratioMiddle < self.ratioLatest:
#check that there has been a 3 down since the last buy
#sell a and buy b
self.MarketOrder("SPY", 100)
self.MarketOrder("PEP", -100)
#If ratio has decreased 3 times, buy a and sell b
If self.ratioEarliest > self.ratioMiddle and If self.ratioMiddle > self.ratioLatest:
#check that 1 day has passed since last trade
#check that there has been a 3 up since the last buy
#buy a and sell b
self.MarketOrder("SPY", -100)
self.MarketOrder("PEP", 100)
Louis Szeto
Hi R
I hope these helps :)
Cheers
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.
R WILLIAMSON
Hi Louis,
thanks very much for taking the time to answer. All of your suggestions cured my problems :) Case sensitivity takes some getting used to.
Regards
Richard
R WILLIAMSON
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!