Backtrader Community

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

    duality_

    @duality_

    3
    Reputation
    702
    Profile views
    35
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    duality_ Unfollow Follow

    Best posts made by duality_

    • RE: Why do I get 'None' as value for SharpeRatio?

      So I used the TimeReturn, but get a negative result.
      My data candles are spaced 30 minutes apart, so I did:

      cerebro.addanalyzer(btanalyzers.SharpeRatio, _name='sharpe', timeframe=bt.TimeFrame.Minutes, compression=30)
      

      But this is what I get when calling print on the result:

      SharpeRatio:
        - sharperatio: -0.922698416321026
      

      What's the reason for this? One possibility I see is that the convertrate does not support sub-day conversions. If I change riskfreerate to 0.0, I get a ratio of 0.024310682470976966.

      posted in General Code/Help
      D
      duality_
    • RE: Trade object: why is sell size 0?

      I don't know the size because I use order_target_percent.

      posted in General Discussion
      D
      duality_

    Latest posts made by duality_

    • Use indicator without cerebro or strategies?

      Is it possible to use the indicators in Backtrader without Cerebro or strategies?

      I would like to currently notify myself of any possible buy/sell signals that I would then check manually. I would be doing this programmatically to be able to analyze many markets and exchanges at the same time.

      posted in Indicators/Strategies/Analyzers
      D
      duality_
    • RE: Bug: can't get attribute on lineseries.

      I simplified the example so it's really easy to read and follows most of the conventions that the Backtrader's samples also take.

      Here's the simplified code with the same problems as above. Why does this happen?

      from __future__ import (absolute_import, division, print_function, unicode_literals)
      
      import datetime
      
      import backtrader as bt
      import backtrader.feeds as btfeeds
      import backtrader.indicators as btind
      
      
      def run():
          cerebro = bt.Cerebro(optreturn=False)
          StrategyContainer.register(SMA_CrossOver)
          cerebro.optstrategy(StrategyContainer, strategy_index=StrategyContainer.indices())
      
          data0 = btfeeds.YahooFinanceCSVData(dataname='../../datas/daily-PEP.csv', fromdate=datetime.datetime(1997, 1, 1), todate=datetime.datetime(1998, 1, 1))
          cerebro.adddata(data0)
          cerebro.adddata(data0)
      
          # run
          results = cerebro.run()
      
      
      class StrategyContainer(object):
          _strategies = []
          @classmethod
          def register(cls, strategy):
              cls._strategies.append(strategy)
          @classmethod
          def indices(cls):
              return range(len(cls._strategies))
          def __new__(cls, *args, **kwargs):
              strategy_index = kwargs.pop('strategy_index')
              obj = cls._strategies[strategy_index](*args, **kwargs)
              return obj
      
      
      class SMA_CrossOver(bt.Strategy):
          pass
      
      
      run()
      
      posted in General Discussion
      D
      duality_
    • RE: Using multiple strategies runs only one?

      I mean new Backtrader developers, not developers in general. I'm still struggling to get something that I would call basic running, namely running multiple strategies on multiple markets and comparing the results of the strategies. This use case is what brought me into Backtrader.

      posted in General Discussion
      D
      duality_
    • RE: Bug: can't get attribute on lineseries.

      I get the same problem if I switch optreturn of Cerebro from the default of True to False.

      posted in General Discussion
      D
      duality_
    • RE: Bug: can't get attribute on lineseries.

      It might be in backtrader or more likely in my code. Any ideas?

      posted in General Discussion
      D
      duality_
    • RE: Broker is left intact for optstrategy?

      Okay makes sense now. Kind of weird that you still can access a broker, that's not active at all, can be confusing.

      posted in General Discussion
      D
      duality_
    • RE: Trade object: why is sell size 0?

      I don't know the size because I use order_target_percent.

      posted in General Discussion
      D
      duality_
    • Broker is left intact for optstrategy?

      If I do cerebro.broker.getvalue() before and after a cerebro.run(), I get:

      • No change in value (i.e. 10000) if using optstrategy.
      • Change in value (e.g. 15000) if using addstrategy.

      Is there an underlying reason for this? Is it to simplify things when using addstrategy?

      posted in General Discussion
      D
      duality_
    • RE: Bug: can't get attribute on lineseries.

      Yes, that's what I'm asking.

      posted in General Discussion
      D
      duality_
    • RE: Trade object: why is sell size 0?

      @vbs yes this does basically what I would do: check every order and see if it's already executed and if it is, use that.

      posted in General Discussion
      D
      duality_