For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See:

Tried QuickStart strategy with Quandl and getting Attribute Error

  • 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[0]))
        #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(
    		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>()
        153     # Run over everything
    --> 154
    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()
       1139             pool = multiprocessing.Pool(self.p.maxcpus or None)
    C:\Users\XXX\Anaconda2\envs\quant\lib\site-packages\backtrader\feed.pyc in preload(self)
        691         # preloaded - no need to keep the object around - breaks multip in 3.x
    --> 692         self.f.close()
        693         self.f = None
    AttributeError: 'NoneType' object has no attribute 'close'

    Any help in fixing this error would be much appreciated.


  • administrators

    Your data download seems to have failed and there is no file to close.

    You may retry without using optimization.

  • @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(
        fromdate = datetime(2017,1,1),
        todate = datetime(2018,1,1),
        buffered= True,
        # Add the Data Feed to Cerebro
        # Set our desired cash start
        # Print out the starting conditions
        print('Starting Portfolio Value: %.2f' %
        # Run over everything

    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.

  • 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.

Log in to reply