Backtrader Community

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

    timzhang

    @timzhang

    0
    Reputation
    730
    Profile views
    11
    Posts
    1
    Followers
    1
    Following
    Joined Last Online

    timzhang Unfollow Follow

    Latest posts made by timzhang

    • Oanda live trading reconciling positions

      Hi,

      When implementing living trading in oanda, is backtrader reconciling its position with the actual oanda account in any way? I noticed that sometimes the position not updated property locally, which causes certain trade logic not executed. If I want to check the live position from oanda, what's the best way to implement that in the codes?

      Many Thanks,

      posted in General Code/Help
      T
      timzhang
    • RE: OANDA live feed tick data

      thank you dan

      posted in General Discussion
      T
      timzhang
    • OANDA live feed tick data

      Anyone tried to add tick data for live oanda feed and also use another resampled minutes data as indicator? In oandastore class, it looks like the granularities only go down to 5s level.

      Thank you

      posted in General Discussion
      T
      timzhang
    • RE: Multi-asset ranking and rebalancing

      @backtrader
      cool, got order_target_percent working for my long-only portfolio. Just wondering if I'd like to implement a long short strategy, do I use negative portfolio weight as target in order_target_percent?

      posted in General Discussion
      T
      timzhang
    • bt.observers.Benchmark

      Just trying to add a benchmark observer into my strategy and plot. My method is to add data to cerebro first, then addobserver using the same benchmark data. It all seems to be fine, but the plot still only shows the strategy TimeReturn. I had a look at the benchmark documentation, but couldn't figure it out. Just wondering if any additional example that I can reference besides the below link?

      https://www.backtrader.com/docu/observer-benchmark/benchmarking.html#observers-benchmarking

      posted in Indicators/Strategies/Analyzers
      T
      timzhang
    • RE: Multi-asset ranking and rebalancing

      @backtrader
      Thank you for mentioning that the trades are executed in the order been given to the system. I think if I want to change how it is filled, I can override the self.broker.pending variable at the end of next function under my strategy. I can convert deque to a list, sort it and then convert it back to deque. The only problem I have now is to sort a list of broker.order objects. What's the best way to do that?

      posted in General Discussion
      T
      timzhang
    • RE: Multi-asset ranking and rebalancing

      Thank you @backtrader
      would it make more sense to execute the sell trades first then buy within bbroker's 'next' when backtesting strategy? After all, you have to sell first to fund the buy trades.

      posted in General Discussion
      T
      timzhang
    • RE: Multi-asset ranking and rebalancing

      @backtrader
      Thank you, I got the order_target working. My previous error is due to not specifying the particular data series, as multiple assets are traded in this strategy.

      But still having some problems with set_checksubmit. Even I set it to False and set_coc to True, my pending buy order still not get executed. It fell off due to Margin. I can see there's enough Cash once I execute the sell orders. But the buy order was dropped first before the sell orders get executed. Any ideas on work around this issue?

      posted in General Discussion
      T
      timzhang
    • RE: Multi-asset ranking and rebalancing

      @backtrader
      In terms of use order targer to rebalance, how does backtesting broker execute the orders? Do I set_coc to True and set_checksubmit to False? I loaded 10 different monthly return series and try to trade top 5 equal weight based on last 3 month returns. But my below strategy gave me some really extreme large final portfolio value. I think probably something wrong with the way I execute my orders?

      Anything is about how I use ranking in bt, do you reckon it is the correct approach or should I implement everything under 'next'?

      class TestStrategy(bt.Strategy):
      
          def __init__(self):
              # calculate last 3 month return
              for i in range(0, 10):
                  self.datas[i].rtn = (self.datas[i].close(0) / self.datas[i].close(-3)) - 1
      
      
          def next(self):
              rtn_ls = np.array([self.datas[i].rtn[0] for i in range(0, 10)])
              rtn_target = np.percentile(rtn_ls, 50)
              for i in range(0, 10):
                  if self.datas[i].rtn[0] > rtn_target:
                      self.order_target_percent(target=0.2)
                  else:
                      self.order_target_percent(target=0.0)
      

      Thank you

      posted in General Discussion
      T
      timzhang
    • RE: Multi-asset ranking and rebalancing

      @backtrader Thank you, I'll try it out!

      posted in General Discussion
      T
      timzhang