Hi, I was looking at a tutorial that used to be on here called "Crude Oil Predicts Equity Returns" but when I clone and try to backtest the algorithim I get this error:
BacktestingRealTimeHandler.Run(): There was an error in a scheduled event SPY: MonthStart: SPY: 0 min after MarketOpen. The error was AttributeError : 'str' object has no attribute 'Close'
Any ideas on how to fix this?
from datetime import datetime
from clr import AddReference
AddReference("System")
AddReference("QuantConnect.Algorithm")
AddReference("QuantConnect.Indicators")
AddReference("QuantConnect.Common")
from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Data import *
from QuantConnect.Indicators import *
from QuantConnect.Orders import *
from QuantConnect.Securities import *
from QuantConnect.Python import PythonData
import decimal
import numpy as np
from scipy.stats import pearsonr
class CrudeOilPredictsEqeuityReturns(QCAlgorithm):
def Initialize(self):
# Set the cash we'd like to use for our backtest
self.SetCash(100000)
# Start and end dates for the backtest.
self.SetStartDate(2010, 1, 1)
self.SetEndDate(2017, 1, 1)
# Add assets we'd like to incorporate into our portfolio
self.oil = self.AddEquity("oil", Resolution.Daily).Symbol
self.spy = self.AddEquity("spy", Resolution.Daily).Symbol
self.AddData(TBill, "tbill")
self.tbill = self.Securities["tbill"].Symbol
# We may also use imported data from Quandl by using the following comments
# self.AddData(Oil, "oil")
# self.oil = self.Securities["oil"].Symbol
# Number of month in look-back peroid, Number of days in a month
self.regPeriod = 24
self.daysInMonth = 21
# Event is triggered every month
self.Schedule.On(self.DateRules.MonthStart(self.spy), self.TimeRules.AfterMarketOpen(self.spy),Action(self.MonthlyReg))
Jing Wu
Hi Mister,
We've updated the history request to be more streamlined with other parts of QuantConnect. Now self.History() returns a pandas dataframe which is more convenient for Python users. Please check this attached algorithm
Mister Math
Perfect, thanks a lot for the help Jing!
Mister Math
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!