Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    Pandas Dataframe with Google Finance Data

    General Code/Help
    2
    2
    1642
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      hexcrafter last edited by

      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]
      
      B 1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators @hexcrafter last edited by

        @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

        • Docs - Data Feeds Reference
        • Docs - Pandas DataFeed Example
        1 Reply Last reply Reply Quote 1
        • 1 / 1
        • First post
          Last post
        Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors