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/

    Historical testing with IB

    General Code/Help
    3
    3
    1893
    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.
    • T
      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?

      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        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:

        self.mpyplot.show()

        which seems to indicate matplotlib may 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

        1 Reply Last reply Reply Quote 0
        • S
          snehalharshe last edited by

          @tjmille2 said in Historical testing with IB:

          Interactive Brokers data feed

          IB doesn't have a ready made backtesting/replay tool. Basically, you have to download historical data and run it through your strategy. IB don't offer a real backtesting environment for your Python API.

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