Backtrader Community

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. Cedric
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
    • Profile
    • Following 0
    • Followers 0
    • Topics 0
    • Posts 2
    • Best 0
    • Controversial 0
    • Groups 0

    Cedric

    @Cedric

    0
    Reputation
    10
    Profile views
    2
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    Cedric Unfollow Follow

    Latest posts made by Cedric

    • RE: Not able to fetch live data from IB but works with Yahoofinance

      Thank you for the fast response. I will describe my situation.
      Now, I want to get historical data from IB to do some backtesting. I have a paper trading account and followed this article 'https://medium.com/@danjrod/interactive-brokers-in-python-with-backtrader-23dea376b2fc' to get the right settings. As already said, I work in a jupyter notebook.

      This is my code:

      from __future__ import (absolute_import, division, print_function,
                              unicode_literals)
      
      !pip install https://github.com/blampe/IbPy/archive/master.zip
      
      import pandas as pd
      import backtrader as bt
      from datetime import datetime
      !pip install backtrader[plotting]
      %matplotlib inline  
      
      # Create a subclass of Strategy to define the indicators and logi
      class EMA(bt.Strategy):
          # list of parameters which are configurable for the strategy
          params = dict(
              pfast=7,  # period for the fast moving average
              pslow=10 # period for the slow moving average
          )
      
          def __init__(self):
              sma1 = bt.ind.ExponentialMovingAverage(period=self.p.pfast)  # fast moving average
              sma2 = bt.ind.ExponentialMovingAverage(period=self.p.pslow)  # slow moving average
              self.crossover = bt.ind.CrossOver(sma1, sma2)  # crossover signal
      
      
          def next(self):
      
              if not self.position:  # not in the market
                  if self.crossover > 0 :  # if fast crosses slow to the upside
                      self.buy()  # enter long
      
              elif self.crossover < 0 :  # in the market & cross to the downside
                  self.close()  # close long position
      
      cerebro = bt.Cerebro()
      ibstore = bt.stores.IBStore(host='127.0.0.1', port=7497, clientId=35)
      data = ibstore.getdata(dataname='AAPL-STK-SMART-USD', fromdate=datetime(2017, 5, 1), todate=datetime(2018, 8, 20))
      cerebro.adddata(data)
      cerebro.addstrategy(EMA)
      cerebro.run()
      cerebro.plot()
      

      Response: AttributeError: 'Plot_OldSync' object has no attribute 'mpyplot'

      Thanks in advance and sorry for not making clear the situation at first.

      posted in General Code/Help
      Cedric
      Cedric
    • RE: Not able to fetch live data from IB but works with Yahoofinance

      Did you find a solution yet? I have the same problem. I can 'connect' with yahoo by using YahooFinanceData() and I am able to plot it. Despite that, when trying to use IB, the same error appears. The output tells me that there is a connection but when I want to plot it I get 'Plot_OldSync' object has no attribute 'mpyplot'. I already reinstalled most packages, I followed installations on github and medium but nothing seems to work. I try to do this on Jupyter Notebook and made a new environment.

      posted in General Code/Help
      Cedric
      Cedric