Pandas Dataframe with Google Finance Data



  • I have been having problems importing data ever since Yahoo got rid of their Yahoo Finance API. I am trying to load a CSV data file from Google Finance into a dataframe and then into backtrader.

    data

    I use pandas "read_csv" to load the data into a dataframe, then btfeeds.PandasData to load it into backtrader:

    dataframe = pd.read_csv('/path/to/twtr.csv')
    
    data = btfeeds.PandasData(
    		dataname=dataframe,
    		fromdate=(datetime.datetime(2013, 11, 7)),
    		todate=(datetime.datetime(2017, 8, 22))
    
    	)
    

    I receive the following error:

    Starting Portfolio Value: 10000.00
    Traceback (most recent call last):
      File "/Users/m4punk/Documents/Coding/python/QuantTrading/Quant-Strategies/technical/MACD Strategy/MACD_slope.py", line 185, in <module>
        thestrats = cerebro.run()
      File "/Users/m4punk/Documents/Coding/python/QuantTrading/Quant-Strategies/Quantstrats/lib/python3.4/site-packages/backtrader/cerebro.py", line 794, in run
        runstrat = self.runstrategies(iterstrat)
      File "/Users/m4punk/Documents/Coding/python/QuantTrading/Quant-Strategies/Quantstrats/lib/python3.4/site-packages/backtrader/cerebro.py", line 857, in runstrategies
        data.preload()
      File "/Users/m4punk/Documents/Coding/python/QuantTrading/Quant-Strategies/Quantstrats/lib/python3.4/site-packages/backtrader/feed.py", line 420, in preload
        while self.load():
      File "/Users/m4punk/Documents/Coding/python/QuantTrading/Quant-Strategies/Quantstrats/lib/python3.4/site-packages/backtrader/feed.py", line 461, in load
        _loadret = self._load()
      File "/Users/m4punk/Documents/Coding/python/QuantTrading/Quant-Strategies/Quantstrats/lib/python3.4/site-packages/backtrader/feeds/pandafeed.py", line 221, in _load
        line[0] = self.p.dataname.ix[self._idx, colindex]
      File "/Users/m4punk/Documents/Coding/python/QuantTrading/Quant-Strategies/Quantstrats/lib/python3.4/site-packages/backtrader/linebuffer.py", line 222, in __setitem__
        self.array[self.idx + ago] = value
    TypeError: a float is required
    [Finished in 1.5s with exit code 1]

  • administrators

    @hexcrafter said in Pandas Dataframe with Google Finance Data:

        self.array[self.idx + ago] = value
    TypeError: a float is required
    

    Speaks for itself.

    You have to tell PandasData where to find the values or to skip the ones that aren't there. With the parameters open, high...

    See


Log in to reply
 

Looks like your connection to Backtrader Community was lost, please wait while we try to reconnect.