Tried QuickStart strategy with Quandl and getting Attribute Error
cking last edited by
I tried to run the full code for the strategy in the QuickStart documentation with the only change being Quandl as data feed instead of Yahoo Finance and I got some errors. I am direct downloading the data as opposed to pre-loading in a CSV file as in the QuickStart.
Below is the (only) part of the code I replaced:
# Datas are in a subfolder of the samples. Need to find where the script is # because it could have been called from anywhere #modpath = os.path.dirname(os.path.abspath(sys.argv)) #datapath = os.path.join(modpath, '../../datas/orcl-1995-2014.txt') # Create a Data Feed #data = bt.feeds.YahooFinanceCSVData( # dataname=datapath, # # Do not pass values before this date # fromdate=datetime.datetime(2000, 1, 1), # # Do not pass values before this date # todate=datetime.datetime(2000, 12, 31), # # Do not pass values after this date # reverse=False) data = bt.feeds.Quandl( dataname='WIKI/AAPL', apikey='XXXX-XXXXX_XXXXXXXXX', fromdate=datetime.datetime(2000, 1, 1), todate=datetime.datetime(2000, 12, 31))
I get the error below after running the full strategy in Python 2.7.
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-18-b4feed4b37c3> in <module>() 152 153 # Run over everything --> 154 cerebro.run() C:\Users\XXX\Anaconda2\envs\quant\lib\site-packages\backtrader\cerebro.pyc in run(self, **kwargs) 1135 data._start() 1136 if self._dopreload: -> 1137 data.preload() 1138 1139 pool = multiprocessing.Pool(self.p.maxcpus or None) C:\Users\XXX\Anaconda2\envs\quant\lib\site-packages\backtrader\feed.pyc in preload(self) 690 691 # preloaded - no need to keep the object around - breaks multip in 3.x --> 692 self.f.close() 693 self.f = None 694 AttributeError: 'NoneType' object has no attribute 'close'
Any help in fixing this error would be much appreciated.
Your data download seems to have failed and there is no file to close.
You may retry without using optimization.
pookeye last edited by pookeye
@cking any luck with this? I'm also seeing the same issue... not quite understanding what does without using optimization response is.
data = bt.feeds.Quandl( dataname='AAPL', fromdate = datetime(2017,1,1), todate = datetime(2018,1,1), buffered= True, apikey="XXXXXXXX" ) # Add the Data Feed to Cerebro cerebro.adddata(data) # Set our desired cash start cerebro.broker.setcash(100000.0) # Print out the starting conditions print('Starting Portfolio Value: %.2f' % cerebro.broker.getvalue()) # Run over everything cerebro.run()
when I run this, i get the following...
AttributeError: 'NoneType' object has no attribute 'close'
I am using python 3.6, which could be an issue.
cking last edited by
Don't know if this is any help but I was able to fix this problem by taking out the "WIKI/" from the dataname string value and it now works.