Historical testing with IB
tjmille2 last edited by backtrader
I attempted to connect to an Interactive Brokers data feed to backtest a strategy of mine.
My code is below:
ibstore = bt.stores.IBStore(host='127.0.0.1', port=7497, clientId=3921) data = ibstore.getdata(dataname=ticker_name, historical=True, fromdate=datetime(2000, 1, 1), todate=datetime(2016, 12, 31), timeframe=bt.TimeFrame.Seconds, compression=5) cerebro.adddata(data) print("---- Starting Backtest ----") cerebro.run() print("---- Plotting Results ----") cerebro.plot()
When I run, I get the following error:
Traceback (most recent call last): File "<PATH_TO>/Backtest.py", line 62, in cerebro.plot() File "/Users/Tim/miniconda3/lib/python3.5/site-packages/backtrader/cerebro.py", line 665, in plot plotter.show() File "/Users/Tim/miniconda3/lib/python3.5/site-packages/backtrader/plot/plot.py", line 707, in show self.mpyplot.show() AttributeError: 'Plot_OldSync' object has no attribute 'mpyplot'
Is backtesting with IB officially supported? If so, where is my code incorrect?
Is backtesting with IB officially supported?
This is an open source packages. "Officially" may not be the right description. Yes, you can connect TWS and download data. It is seen as another data feed.
Your code seems to fail here:
which seems to indicate
matplotlibmay be missing.
From the docs Docs - Installation
Additional requirements if plotting is wished:
Matplotlib >= 1.4.1
It may work with previous versions, but this the one used for development