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/

    YahooFinance

    General Discussion
    yahoofinance typeerror filenotfound
    1
    1
    109
    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.
    • M
      marsario last edited by

      Hi,

      I haven't used Backtrader for over six months, and wow, none of my programs works any more :(

      The problem seems to be with YahooFinance. I saw some people have had similar problems online, but other posts didn't help me, so I thought of opening a new one.

      When I run any strategy, I get FileNotFoundError.

      In this post (https://community.backtrader.com/topic/3979/help-with-yahoofinance-data/3)
      @run-out recommended to add the following line to the file feeds/yahoo.py: sess.headers['User-Agent'] = 'backtrader'

      However, when I do that, I get TypeError.

      I'm attaching below a basic code I tested this with, and more information about the two exceptions:

      import backtrader as bt
      import datetime
      
      
      
      enddate=datetime.date.today()
      startdate = enddate - datetime.timedelta(days=(365*2))
      cerebro = bt.Cerebro()
      
      cerebro.adddata(bt.feeds.YahooFinanceData(
              dataname="AAPL",
              timeframe=bt.TimeFrame.Days,
              fromdate=startdate,
              todate=enddate,
              reverse=False,
              ))
      
      
      
      class basicStrategy(bt.Strategy):
          print("basicStrategy has been added")
              
          def __init__(self):
              print("Strategy has started. This is init")
      
          def prenext(self):
              print("Prenext")
      
          def next(self):
              firstdataname = self.datas[0]._name
              stockpricetoday = self.datas[0].close[0]
              today = bt.num2date(self.datas[0].datetime[0]).date()
              print(today,firstdataname,"is trading for",stockpricetoday)
      
      cerebro.broker.setcash(100000.0)
      cerebro.addstrategy(basicStrategy)
      print("Launching the strategy")
      cerebro.run()
      print("Strategy is over")
      
      
      
      
        File "/Users/simoneromeo/Investment Files/Learning Backtrader/67 debugging_yahoof_errors.py", line 38, in <module>
          cerebro.run()
      
        File "/Users/simoneromeo/opt/anaconda3/lib/python3.8/site-packages/backtrader/cerebro.py", line 1127, in run
          runstrat = self.runstrategies(iterstrat)
      
        File "/Users/simoneromeo/opt/anaconda3/lib/python3.8/site-packages/backtrader/cerebro.py", line 1210, in runstrategies
          data._start()
      
        File "/Users/simoneromeo/opt/anaconda3/lib/python3.8/site-packages/backtrader/feed.py", line 203, in _start
          self.start()
      
        File "/Users/simoneromeo/opt/anaconda3/lib/python3.8/site-packages/backtrader/feeds/yahoo.py", line 355, in start
          super(YahooFinanceData, self).start()
      
        File "/Users/simoneromeo/opt/anaconda3/lib/python3.8/site-packages/backtrader/feeds/yahoo.py", line 94, in start
          super(YahooFinanceCSVData, self).start()
      
        File "/Users/simoneromeo/opt/anaconda3/lib/python3.8/site-packages/backtrader/feed.py", line 674, in start
          self.f = io.open(self.p.dataname, 'r')
      
      FileNotFoundError: [Errno 2] No such file or directory: 'AAPL'
      
      runfile('/Users/simoneromeo/Investment Files/Learning Backtrader/67 debugging_yahoof_errors.py', wdir='/Users/simoneromeo/Investment Files/Learning Backtrader')
      basicStrategy has been added
      Launching the strategy
      Traceback (most recent call last):
      
        File "/Users/simoneromeo/Investment Files/Learning Backtrader/67 debugging_yahoof_errors.py", line 38, in <module>
          cerebro.run()
      
        File "/Users/simoneromeo/opt/anaconda3/lib/python3.8/site-packages/backtrader/cerebro.py", line 1127, in run
          runstrat = self.runstrategies(iterstrat)
      
        File "/Users/simoneromeo/opt/anaconda3/lib/python3.8/site-packages/backtrader/cerebro.py", line 1210, in runstrategies
          data._start()
      
        File "/Users/simoneromeo/opt/anaconda3/lib/python3.8/site-packages/backtrader/feed.py", line 203, in _start
          self.start()
      
        File "/Users/simoneromeo/opt/anaconda3/lib/python3.8/site-packages/backtrader/feeds/yahoo.py", line 355, in start
          # Prepared a "path" file -  CSV Parser can take over
      
      TypeError: super(type, obj): obj must be an instance or subtype of type
      
      1 Reply Last reply Reply Quote 0
      • 1 / 1
      • First post
        Last post
      Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors