Hello, thanks for your work!
I'm having an issue with
YahooFinanceDatafeed – it raises an exception after calling
cerebro.run. 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() cerebro.addstrategy(SmaCross) data0 = bt.feeds.YahooFinanceData(dataname='YHOO', fromdate=datetime(2011, 1, 1), todate=datetime(2012, 12, 31)) cerebro.adddata(data0) cerebro.run() cerebro.plot()
How does actual exception look like:
Traceback (most recent call last): File "backtrade/strategy.py", line 25, in <module> cerebro.run() File "/Users/env/lib/python3.6/site-packages/backtrader/cerebro.py", line 1117, in run runstrat = self.runstrategies(iterstrat) File "/Users/env/lib/python3.6/site-packages/backtrader/cerebro.py", line 1194, in runstrategies data._start() File "/Users/env/lib/python3.6/site-packages/backtrader/feed.py", line 203, in _start self.start() File "/Users/env/lib/python3.6/site-packages/backtrader/feeds/yahoo.py", line 456, in start super(YahooFinanceData, self).start() File "/Users/env/lib/python3.6/site-packages/backtrader/feeds/yahoo.py", line 90, in start super(YahooFinanceCSVData, self).start() File "/Users/env/lib/python3.6/site-packages/backtrader/feed.py", line 671, in start self.f = io.open(self.p.dataname, '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:
It actually tries to check if a string (dataname) has the
# 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 else: # Let an exception propagate to let the caller know self.f = io.open(self.p.dataname, 'r') # <- raises FileNotFoundError
This is a hidden feature and a problem following the Yahoo API fiasco. First:
YHOOseems to no longer be available as ticker. Even if you aren't religious the proper exclamation here would be: "God knows why!"
- 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.
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, ...) ...