Navigation

    Backtrader Community

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

    kumagai

    @kumagai

    0
    Reputation
    4
    Profile views
    5
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    kumagai Unfollow Follow

    Latest posts made by kumagai

    • RE: Can get_analysis() count multiple positions(trades)?

      Thank you for your reply.
      I could fix my bag.
      The cause of my bag was tradeid.
      Thank you.
      https://community.backtrader.com/topic/622/multiple-order-managment

      posted in Indicators/Strategies/Analyzers
      K
      kumagai
    • RE: There are many trades in the log, but it occuers keyError in the analyzer

      Thank you for your replay.
      I found the reason is I didn't use tradeid.
      In my trade, there are buy,buy,sell,sell.
      After I rewrite multitrade version by using tradeid, the bag fixed.
      Thank you

      posted in Indicators/Strategies/Analyzers
      K
      kumagai
    • Can get_analysis() count multiple positions(trades)?

      I want to count multiple trades.
      In my strategy, I buy() at time T and T+1, and I sell() at time T+20 and T+21.
      In this case, I desire the amount of tredes by get_analysis is 2.
      Otherwise, it return 0 and occuers keyError.
      Can't get_analysis() count multiple positions(trades)?
      plz help me.

      posted in Indicators/Strategies/Analyzers
      K
      kumagai
    • RE: There are many trades in the log, but it occuers keyError in the analyzer

      Thank you for your advice. This is my strategy. The analysis does not work, it couldn't count the amount of trades.
      I run get_analysis() and then,
      winrate = analysis.won.total / analysis.total.closed
      It occuers keyError.

      def next(self): # 行ごとに呼び出される

          #print(self.position)
          if self.judge_order_buy():
              trade_amount= int(self.cash/20/self.dataclose)
              self.count+=1
              #if self.position: # ポジションを持っている場合
               #   self.close() #
              self.order=self.buy(size=trade_amount)
              self.sell_unwind.append([len(self),trade_amount,0])
      
          elif self.judge_order_sell():
              trade_amount = int(self.cash/ 20 / self.dataclose)
              self.order = self.sell(trade_amount)
              self.buy_unwind.append([len(self), trade_amount, 0])
          #if self.order.status in [self.order.Canceled, self.order.Margin, self.order.Rejected]:
              #self.broker.cancel(self.order)
          self.unwind_buy_operate()
          self.unwind_sell_operate()
          
      
      
          if Close_all_positions:
              # i = list(range(0, len(self.datas)))
              # for (d, j) in zip(self.datas, i):
              for j, d in enumerate(self.datas):
                  if len(d) == d.buflen() - 1:
                      close = self.close(d, exectype=bt.Order.Market)
      

      class strategy_my(myStrategy):
      unwind_days = 20 # 1M
      count=0

      def judge_order_buy(self):
          return self.signal == 1
      
      def judge_order_sell(self):
          return False
      
      def unwind_buy_operate(self, expected_rate=None, loss_cut_rate=None):
          for i, buy in enumerate(self.buy_unwind):
              if buy[0] + self.unwind_days == len(self) and buy[1] > 0:
                  # Unwind at the last day
                  self.buy(size=buy[1])
                  self.buy_unwind[i][1] = 0
      
      def unwind_sell_operate(self, expected_rate=None, loss_cut_rate=None):
          for i, sell in enumerate(self.sell_unwind):
              if sell[0] + self.unwind_days == len(self) and sell[1] > 0:
                  # Unwind at the last day
                  print(len(self))
                  
                  if self.position: # ポジションを持っている場合
                  
                    self.order=self.close(size=sell[1])
                    self.sell_unwind[i][1] = 0
      
      posted in Indicators/Strategies/Analyzers
      K
      kumagai
    • There are many trades in the log, but it occuers keyError in the analyzer

      There are many trades in the log, but it occuers keyError.
      analysis["total"]["total"] is 1.
      How can I fix it?
      ![alt text](スクリーンショット 2020-05-15 17.28.13.png image url)

      posted in Indicators/Strategies/Analyzers
      K
      kumagai