Backtrader Community

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

    Pulling Data from Yahoo Broken?

    General Code/Help
    1
    1
    37
    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.
    • James Scarr
      James Scarr last edited by

      stock = '^GSPC'
              global startDate
              global endDate
              global startYear
              startYear = years[i]
              endYear = years[i+1]
              strategy = OptimisedPoundCostAveraging
              if strategy == OptimisedPoundCostAveraging:
                  startDate = datetime.datetime(startYear-1,1,1)
              else:
                  startDate = datetime.datetime(startYear,1,1)
              endDate = datetime.datetime(endYear,1,1)
              
              stockData = pdr.get_data_yahoo(stock, startDate, endDate)
      
              # Actual start date is the start of the following day 
              global actualStart
              actualStart = stockData.index[0]
              # Put data in a format that BackTrader understands
              data = bt.feeds.PandasData(dataname=stockData)
      
              # Pound Cost Averaging
              cerebro = bt.Cerebro()
              cerebro.adddata(data)
              cerebro.addstrategy(strategy)
      

      This code used to run until around a month ago when it started producing this error:

      Traceback (most recent call last):
        File "/Users/jamesscarr/Library/Mobile Documents/com~apple~CloudDocs/Moneykey/Backtesting/Final.py", line 301, in <module>
          run()
        File "/Users/jamesscarr/Library/Mobile Documents/com~apple~CloudDocs/Moneykey/Backtesting/Final.py", line 271, in run
          stockData = pdr.get_data_yahoo(stock, startDate, endDate)
        File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas_datareader/data.py", line 80, in get_data_yahoo
          return YahooDailyReader(*args, **kwargs).read()
        File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas_datareader/base.py", line 253, in read
          df = self._read_one_data(self.url, params=self._get_params(self.symbols))
        File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas_datareader/yahoo/daily.py", line 153, in _read_one_data
          data = j["context"]["dispatcher"]["stores"]["HistoricalPriceStore"]
      TypeError: string indices must be integers
      

      Does anyone know if this is an issue with Yahoo updating their data format? Or perhaps a bug in Backtrader? I would be extremely grateful if anyone could shed some light on this situation. If anyone can provide a solution to get this up and running I will buy them a coffee (please leave your PayPal email address at the end of the solution).

      Tagging @run-out as they helped me with a previous issue and seemed very knowledgeable.

      Kind regards,
      James

      1 Reply Last reply Reply Quote 0
      • 1 / 1
      • First post
        Last post
      Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors