Navigation

    Backtrader Community

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

    backtraderuser

    @backtraderuser

    2
    Reputation
    134
    Profile views
    3
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    backtraderuser Unfollow Follow

    Best posts made by backtraderuser

    • Bug (with code and screenshot): only 1 trade executes modifying example on homepage

      (looked to submit this bug on github directly, but didn't see the option there. also didn't see any bug sections of forums, apologies if this isn't posted to the ideal spot...)

      Bug: only 1 trade executes from code snippet on home page with a few reasonable modifications

      Screenshot: https://imgur.com/a/bd2hUqi
      0_1545308018150_backtraderbug.png

      Modifications:

      • params = (('pfast', 10), ('pslow', 30),) change to ==> params = (('pfast', 50), ('pslow', 200),)
      • data = bt.feeds.YahooFinanceData(dataname='MSFT', fromdate=datetime(2011, 1, 1), todate=datetime(2012, 12, 31)) change to ==> data = bt.feeds.YahooFinanceData(dataname='ESNT', fromdate=datetime(2014, 1, 1),
        todate=datetime(2018, 12, 1))
      • add setting: cerebro.addsizer(bt.sizers.AllInSizer)

      Note:

      • switching ticker symbol from 'ESNT' to 'SPY' over the same period makes zero trades despite several signal crossovers.
      • switching ticker symbol to 'SPY' and using date range (2003,1,1) to (2018,12,1) makes a few trades, but also misses a few trades that should execute.

      Full code to reproduce:
      from datetime import datetime
      import backtrader as bt
      class SmaCross(bt.SignalStrategy):
      params = (('pfast', 50), ('pslow', 200),)
      def init(self):
      sma1, sma2 = bt.ind.SMA(period=self.p.pfast), bt.ind.SMA(period=self.p.pslow)
      self.signal_add(bt.SIGNAL_LONG, bt.ind.CrossOver(sma1, sma2))
      cerebro = bt.Cerebro()
      data = bt.feeds.YahooFinanceData(dataname='ESNT', fromdate=datetime(2014, 1, 1),
      todate=datetime(2018, 12, 1))
      cerebro.adddata(data)
      cerebro.addsizer(bt.sizers.AllInSizer)
      cerebro.addstrategy(SmaCross)
      cerebro.run()
      cerebro.plot()

      posted in General Discussion
      B
      backtraderuser
    • RE: Bug (with code and screenshot): only 1 trade executes modifying example on homepage

      "That's a bug in your code.

      AllIn Strategies are doomed to fail in real-life."

      Interesting perspective. There's a difference between a bad strategy and a code implementation that fails to execute the intuitive meaning represented to the user. Not naive enough to attempt an All-in strategy in real life, but interested in modeling one as a benchmark to compare against other (better) strategies.

      Food for thought: If merely including the default implementation of AllInSizer in my code introduces a bug, why offer AllInSizer at all?

      Not interested in debating semantics and appreciate the (otherwise) great software. If this is not a "bug", so be it.

      posted in General Discussion
      B
      backtraderuser

    Latest posts made by backtraderuser

    • RE: Bug (with code and screenshot): only 1 trade executes modifying example on homepage

      "That's a bug in your code.

      AllIn Strategies are doomed to fail in real-life."

      Interesting perspective. There's a difference between a bad strategy and a code implementation that fails to execute the intuitive meaning represented to the user. Not naive enough to attempt an All-in strategy in real life, but interested in modeling one as a benchmark to compare against other (better) strategies.

      Food for thought: If merely including the default implementation of AllInSizer in my code introduces a bug, why offer AllInSizer at all?

      Not interested in debating semantics and appreciate the (otherwise) great software. If this is not a "bug", so be it.

      posted in General Discussion
      B
      backtraderuser
    • RE: Bug (with code and screenshot): only 1 trade executes modifying example on homepage

      Update: the bug appears to be triggered primarily by cerebro.addsizer(bt.sizers.AllInSizer)

      Not sure why or how to fix, but omitting that line at least gets trades firing on all signals as expected.

      posted in General Discussion
      B
      backtraderuser
    • Bug (with code and screenshot): only 1 trade executes modifying example on homepage

      (looked to submit this bug on github directly, but didn't see the option there. also didn't see any bug sections of forums, apologies if this isn't posted to the ideal spot...)

      Bug: only 1 trade executes from code snippet on home page with a few reasonable modifications

      Screenshot: https://imgur.com/a/bd2hUqi
      0_1545308018150_backtraderbug.png

      Modifications:

      • params = (('pfast', 10), ('pslow', 30),) change to ==> params = (('pfast', 50), ('pslow', 200),)
      • data = bt.feeds.YahooFinanceData(dataname='MSFT', fromdate=datetime(2011, 1, 1), todate=datetime(2012, 12, 31)) change to ==> data = bt.feeds.YahooFinanceData(dataname='ESNT', fromdate=datetime(2014, 1, 1),
        todate=datetime(2018, 12, 1))
      • add setting: cerebro.addsizer(bt.sizers.AllInSizer)

      Note:

      • switching ticker symbol from 'ESNT' to 'SPY' over the same period makes zero trades despite several signal crossovers.
      • switching ticker symbol to 'SPY' and using date range (2003,1,1) to (2018,12,1) makes a few trades, but also misses a few trades that should execute.

      Full code to reproduce:
      from datetime import datetime
      import backtrader as bt
      class SmaCross(bt.SignalStrategy):
      params = (('pfast', 50), ('pslow', 200),)
      def init(self):
      sma1, sma2 = bt.ind.SMA(period=self.p.pfast), bt.ind.SMA(period=self.p.pslow)
      self.signal_add(bt.SIGNAL_LONG, bt.ind.CrossOver(sma1, sma2))
      cerebro = bt.Cerebro()
      data = bt.feeds.YahooFinanceData(dataname='ESNT', fromdate=datetime(2014, 1, 1),
      todate=datetime(2018, 12, 1))
      cerebro.adddata(data)
      cerebro.addsizer(bt.sizers.AllInSizer)
      cerebro.addstrategy(SmaCross)
      cerebro.run()
      cerebro.plot()

      posted in General Discussion
      B
      backtraderuser