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

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.


    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(
    		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/", line 185, in <module>
        thestrats =
      File "/Users/m4punk/Documents/Coding/python/QuantTrading/Quant-Strategies/Quantstrats/lib/python3.4/site-packages/backtrader/", line 794, in run
        runstrat = self.runstrategies(iterstrat)
      File "/Users/m4punk/Documents/Coding/python/QuantTrading/Quant-Strategies/Quantstrats/lib/python3.4/site-packages/backtrader/", line 857, in runstrategies
      File "/Users/m4punk/Documents/Coding/python/QuantTrading/Quant-Strategies/Quantstrats/lib/python3.4/site-packages/backtrader/", line 420, in preload
        while self.load():
      File "/Users/m4punk/Documents/Coding/python/QuantTrading/Quant-Strategies/Quantstrats/lib/python3.4/site-packages/backtrader/", line 461, in load
        _loadret = self._load()
      File "/Users/m4punk/Documents/Coding/python/QuantTrading/Quant-Strategies/Quantstrats/lib/python3.4/site-packages/backtrader/feeds/", 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/", 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...


Log in to reply