Need help importing custom historical sp500 data

Back

Greetings,

I'm trying to import VFINX  data which has historical data back to 1986. I'm using the format described in this question ["need help importing custom data"].  However when I run my algorithm it simply outputs the following message:

```                          
Launching analysis for d6b5c8bc457293d7d0b4d154404e9828 with LEAN Engine v2.4.0.0.7199
Data for symbol SPY has been limited due to numerical precision issues in the factor file. The starting date has been set to 1/1/1998.
Algorithm (d6b5c8bc457293d7d0b4d154404e9828) Completed.                           
The starting date for symbol SPY, 1998-01-01, has been adjusted to match map file first date 1998-01-02.

```

My Data class and import code are below, but one thing I should mention is I am using schedule functions in my algorithm. Does custom data work with scheduled functions?:

###
class spy3x(PythonData):
'''EURUSD Custom Data Class'''
def GetSource(self, config, date, isLiveMode):
return SubscriptionDataSource("https://www.dropbox.com/s/1et85hf5s31jate/3x-vfinx-sp500-history.csv?dl=1", SubscriptionTransportMedium.RemoteFile)


def Reader(self, config, line, date, isLiveMode):
if not (line.strip() and line[0].isdigit()): return None

# New Nifty object
currency = spy3x()
currency.Symbol = config.Symbol

try:
# Example File Format:
# Date, Close
# 2011-09-13 7792.9
data = line.split(',')
currency.Time = datetime.strptime(data[0], "%Y.%m.%d")
currency.Value = data[1]
#currency["Open"] = float(data[2])
#currency["High"] = float(data[3])
#currency["Low"] = float(data[4])
currency["Close"] = float(data[1])


except ValueError:
# Do nothing
return None

return currency

###
# AddData call and history call below
###
self.spy3x = self.AddData(spy3x, "D_UPRO", Resolution.Daily).Symbol
self.tlt3x = self.AddData(tlt3x, "D_TMF", Resolution.Daily).Symbol

self.BASE_SYMBOL = self.spy3x
self.symbols = [self.spy3x, self.tlt3x]


# example history call to get prices
self.prices = (
self.History(self.symbols, self.LOOKBACK, self.HISTORY_RESOLUTION)["close"]
.unstack(level=0)
.astype(np.float32)
)

###
# Schedule Function example below
###

self.Schedule.On(
self.DateRules.WeekStart(self.BASE_SYMBOL),
self.TimeRules.AfterMarketOpen(self.BASE_SYMBOL, 10), # could this be an issue??
Action(self.rebalance))

 

Update Backtest







 
0

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.


When debugging I highly recommend not using try catch; it tends to hide errors and made debugging painful. I removed it and the error was immediately obvious: 

time data '2012-05-09' does not match format '%Y.%m.%d'

I changed it to "-" to match the file and the backtest works nicely =) I changed the benchmark to "0" to hide the SPY error message; and I set 1981 as the start date so you can do your history call. 

2

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.


Update Backtest





0

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.


Loading...

This discussion is closed