Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. Ronny Li
    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 2
    • Posts 8
    • Best 3
    • Groups 0

    Ronny Li

    @Ronny Li

    4
    Reputation
    35
    Profile views
    8
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    Ronny Li Unfollow Follow

    Best posts made by Ronny Li

    • RE: ZeroDivisionError: float division by zero

      Hi Sabir, bt.DivByZero is what you're looking for. Here's an example where I use it

      class WeighInverseVol(bt.Strategy):
          params = (
              ('period', 30),
          )
      
          def __init__(self):
              rs = [bt.ind.PctChange(d, period=1) for d in self.datas]
              vs = [bt.ind.StdDev(ret, period=self.params.period) for ret in rs]
              inv = [bt.DivByZero(bt.LineNum(1), v) for v in vs]
              invsum = bt.LineNum(0)
              for inv_ in inv:
                  invsum += inv_
              # self.weights is an array of asset allocation weights
              # one weight per asset in self.datas
              self.weights = [inv_ / invsum for inv_ in inv]
      

      Here's the source code for bt.DivByZero: https://github.com/mementum/backtrader/blob/master/backtrader/functions.py#L43

      posted in General Code/Help
      Ronny Li
      Ronny Li
    • RE: Backtrader's Future

      @backtrader since you're in the thread, is it possible to modify the official backtrader repo to give some more people write access (probably just the admins of backtrader2 for now)?

      posted in General Discussion
      Ronny Li
      Ronny Li
    • RE: Backtrader's Future

      (I'm assuming that continuing the official backtrader repo with a new team of maintainers is preferable to forking it but I could be wrong about that)

      posted in General Discussion
      Ronny Li
      Ronny Li

    Latest posts made by Ronny Li

    • Chaining Strategies

      I have two strategies that I'd like to run sequentially. The first strategy allocates a portion of the portfolio between its assets (using self.order_target_percent) and the second strategy uses what remains of the portfolio.

      What is the best way in backtrader to achieve the above?

      posted in General Discussion
      Ronny Li
      Ronny Li
    • RE: ZeroDivisionError: float division by zero

      Hi Sabir, bt.DivByZero is what you're looking for. Here's an example where I use it

      class WeighInverseVol(bt.Strategy):
          params = (
              ('period', 30),
          )
      
          def __init__(self):
              rs = [bt.ind.PctChange(d, period=1) for d in self.datas]
              vs = [bt.ind.StdDev(ret, period=self.params.period) for ret in rs]
              inv = [bt.DivByZero(bt.LineNum(1), v) for v in vs]
              invsum = bt.LineNum(0)
              for inv_ in inv:
                  invsum += inv_
              # self.weights is an array of asset allocation weights
              # one weight per asset in self.datas
              self.weights = [inv_ / invsum for inv_ in inv]
      

      Here's the source code for bt.DivByZero: https://github.com/mementum/backtrader/blob/master/backtrader/functions.py#L43

      posted in General Code/Help
      Ronny Li
      Ronny Li
    • Dynamic Asset Allocation Weights Indicator

      Has anyone here implemented an indicator that returns weights for assets in a portfolio? Here is the Strategy version:

      class WeighInverseVol(bt.Strategy):
      
          def __init__(self):
              rs = [bt.ind.PctChange(d.close, period=1) for d in self.datas]
              vs = [bt.ind.StdDev(ret, period=30) for ret in rs]
              inv = [bt.DivByZero(bt.LineNum(1), v) for v in vs]
              invsum = bt.LineNum(0)
              for inv_ in inv:
                  invsum += inv_
              # self.weights is an array of asset allocation weights
              # one weight per asset in self.datas
              self.weights = [inv_ / invsum for inv_ in inv]
      

      I'd like WeighInverseVol to be an Indicator so I can use it within other strategies but I don't know how to return a dynamic number of lines within an indicator. Any advice?

      Thanks!

      posted in General Discussion
      Ronny Li
      Ronny Li
    • RE: Backtrader's Future

      I remember seeing that backtrader is used in several banks and quant firms... would any of these companies be willing to sponsor backtrader's continued maintenance? Might incentivize Daniel R to keep working on it or incentivize the new admin team.

      posted in General Discussion
      Ronny Li
      Ronny Li
    • RE: Backtrader's Future

      (I'm assuming that continuing the official backtrader repo with a new team of maintainers is preferable to forking it but I could be wrong about that)

      posted in General Discussion
      Ronny Li
      Ronny Li
    • RE: Backtrader's Future

      @backtrader since you're in the thread, is it possible to modify the official backtrader repo to give some more people write access (probably just the admins of backtrader2 for now)?

      posted in General Discussion
      Ronny Li
      Ronny Li
    • RE: Backtrader's Future

      This PR (https://github.com/mementum/backtrader/pull/401) seems like a nice bugfix to get the ball rolling with backtrader2. It's not mine but I'll steal it if the original author takes too long :P

      posted in General Discussion
      Ronny Li
      Ronny Li
    • RE: Is Yahoo API down right now? Cannot get any data feed through function

      @backtrader The PR addressing this issue has been approved and just needs to be merged: https://github.com/mementum/backtrader/pull/401

      posted in General Code/Help
      Ronny Li
      Ronny Li