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

[YahooFinanceData] FileNotFoundError

  • Hello, thanks for your work!

    I'm having an issue with YahooFinanceData feed – it raises an exception after calling I'm using sample code from GH repo:

    from datetime import datetime
    import backtrader as bt
    class SmaCross(bt.SignalStrategy):
        def __init__(self):
            sma1 = bt.ind.SMA(period=10)
            sma2 = bt.ind.SMA(period=30)
            crossover = bt.ind.CrossOver(sma1, sma2)
            self.signal_add(bt.SIGNAL_LONG, crossover)
    cerebro = bt.Cerebro()
    data0 = bt.feeds.YahooFinanceData(dataname='YHOO',
                                      fromdate=datetime(2011, 1, 1),
                                      todate=datetime(2012, 12, 31))

    How does actual exception look like:

    Traceback (most recent call last):
      File "backtrade/", line 25, in <module>
      File "/Users/env/lib/python3.6/site-packages/backtrader/", line 1117, in run
        runstrat = self.runstrategies(iterstrat)
      File "/Users/env/lib/python3.6/site-packages/backtrader/", line 1194, in runstrategies
      File "/Users/env/lib/python3.6/site-packages/backtrader/", line 203, in _start
      File "/Users/env/lib/python3.6/site-packages/backtrader/feeds/", line 456, in start
        super(YahooFinanceData, self).start()
      File "/Users/env/lib/python3.6/site-packages/backtrader/feeds/", line 90, in start
        super(YahooFinanceCSVData, self).start()
      File "/Users/env/lib/python3.6/site-packages/backtrader/", line 671, in start
        self.f =, 'r')
    FileNotFoundError: [Errno 2] No such file or directory: 'YHOO'

    Info: CPython v3.6.1

    I have investigated the problen so resolving chain looks like this:

    (/feeds/ YahooFinanceData.start --> YahooFinanceData.super().start --> YahooFinanceCSVData.super().start -->
    (/ CSVDataBase.start --> FileNotFoundError

    It actually tries to check if a string (dataname) has the readline attribute:

    # NOTE: Returns true
    if self.f is None:
        # NOTE: Returns false for the string
        if hasattr(self.p.dataname, 'readline'):
            self.f = self.p.dataname
            # Let an exception propagate to let the caller know
            self.f =, 'r')  # <- raises FileNotFoundError

  • administrators

    This is a hidden feature and a problem following the Yahoo API fiasco. First:

    • YHOO seems to no longer be available as ticker. Even if you aren't religious the proper exclamation here would be: "God knows why!"

      Try YHOO.MX for example


    • In case the on-line data feed cannot open the network connection and by means of using the base class it will try to open a file of the same name located in the current directory

    This was used several times for the samples when no network connection was available but the file had been pre-downloaded.

  • Hi,

    I tried using YHOO.MX and it still gives me the same error. What can I do now?

  • Use a provider which isn't Yahoo? Unless you have been under a rock during 2017, it is well known that Yahoo is no longer a data provider to be used.

    The API was taken down, a new was found but has quirks included by Yahoo (column swapping, price removals, ...) ...

  • Please can anyone advise how we can swap these yahoo codes to workable codes

  • Self answer again, do an explicit path reference:
    modpath = os.path.dirname(os.path.abspath(sys.argv[0]))
    datapath = os.path.join(os.getcwd(), 'backtrader-master/datas/orcl-1995-2014.txt')

    data0 = bt.feeds.YahooFinanceData(dataname=datapath , fromdate=datetime(2011, 1, 1),
    todate=datetime(2012, 12, 31))

  • live yahoo feeds had some issue, swapped to quandl feeds instead

Log in to reply

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