class_docstr: (S)elect the (B)etter one among every two adjacent trading (B)ars to sell or buy.
class_docstr_tok: ["(","S",")","elect","the","(","B",")","etter","one","among","every","two","adjacent","trading","(","B",")","ars","to","sell","or","buy","."]
code: def generate_trade_decision(self, execute_result=None):
      # get the number of trading step finished, trade_step can be [0, 1, 2, ..., trade_len - 1]
      trade_step = self.trade_calendar.get_trade_step()
      # get the total count of trading step
      trade_len = self.trade_calendar.get_trade_len()
  
      # update the order amount
      if execute_result is not None:
          for order, _, _, _ in execute_result:
              self.trade_amount[order.stock_id] -= order.deal_amount
  
      (
          trade_start_time,
          trade_end_time,
      ) = self.trade_calendar.get_step_time(trade_step)
      (
          pred_start_time,
          pred_end_time,
      ) = self.trade_calendar.get_step_time(trade_step, shift=1)
      order_list = []
      # for each order in in self.outer_trade_decision
      for order in self.outer_trade_decision.get_decision():
          # get the price trend
          if trade_step % 2 == 0:
              # in the first of two adjacent bars, predict the price trend
              _pred_trend = self._pred_price_trend(
                  order.stock_id, pred_start_time, pred_end_time
              )
          else:
              # in the second of two adjacent bars, use the trend predicted in the first one
              _pred_trend = self.trade_trend[order.stock_id]
          # if not tradable, continue
          if not self.trade_exchange.is_stock_tradable(
              stock_id=order.stock_id,
              start_time=trade_start_time,
              end_time=trade_end_time,
          ):
              if trade_step % 2 == 0:
                  self.trade_trend[order.stock_id] = _pred_trend
              continue
          # get amount of one trade unit
          _amount_trade_unit = (
              self.trade_exchange.get_amount_of_trade_unit(
                  stock_id=order.stock_id,
                  start_time=order.start_time,
                  end_time=order.end_time,
              )
          )
          if _pred_trend == self.TREND_MID:
              _order_amount = None
              # considering trade unit
              if _amount_trade_unit is None:
                  # divide the order into equal parts, and trade one part
                  _order_amount = self.trade_amount[order.stock_id] / (
                      trade_len - trade_step
                  )
              # without considering trade unit
              else:
                  # divide the order into equal parts, and trade one part
                  # calculate the total count of trade units to trade
                  trade_unit_cnt = int(
                      self.trade_amount[order.stock_id]
                      // _amount_trade_unit
                  )
                  # calculate the amount of one part, ceil the amount
                  # floor((trade_unit_cnt + trade_len - trade_step - 1) / (trade_len - trade_step)) == ceil(trade_unit_cnt / (trade_len - trade_step))
                  _order_amount = (
                      (trade_unit_cnt + trade_len - trade_step - 1)
                      // (trade_len - trade_step)
                      * _amount_trade_unit
                  )
              if order.direction == order.SELL:
                  # sell all amount at last
                  if self.trade_amount[order.stock_id] > 1e-5 and (
                      _order_amount < 1e-5
                      or trade_step == trade_len - 1
                  ):
                      _order_amount = self.trade_amount[order.stock_id]
  
              _order_amount = min(
                  _order_amount, self.trade_amount[order.stock_id]
              )
  
              if _order_amount > 1e-5:
                  _order = Order(
                      stock_id=order.stock_id,
                      amount=_order_amount,
                      start_time=trade_start_time,
                      end_time=trade_end_time,
                      direction=order.direction,
                  )
                  order_list.append(_order)
  
          else:
              _order_amount = None
              # considering trade unit
              if _amount_trade_unit is None:
                  # N trade day left, divide the order into N + 1 parts, and trade 2 parts
                  _order_amount = (
                      2
                      * self.trade_amount[order.stock_id]
                      / (trade_len - trade_step + 1)
                  )
              # without considering trade unit
              else:
                  # cal how many trade unit
                  trade_unit_cnt = int(
                      self.trade_amount[order.stock_id]
                      // _amount_trade_unit
                  )
                  # N trade day left, divide the order into N + 1 parts, and trade 2 parts
                  _order_amount = (
                      (trade_unit_cnt + trade_len - trade_step)
                      // (trade_len - trade_step + 1)
                      * 2
                      * _amount_trade_unit
                  )
              if order.direction == order.SELL:
                  # sell all amount at last
                  if self.trade_amount[order.stock_id] > 1e-5 and (
                      _order_amount < 1e-5
                      or trade_step == trade_len - 1
                  ):
                      _order_amount = self.trade_amount[order.stock_id]
  
              _order_amount = min(
                  _order_amount, self.trade_amount[order.stock_id]
              )
  
              if _order_amount > 1e-5:
                  if trade_step % 2 == 0:
                      # in the first one of two adjacent bars
                      # if look short on the price, sell the stock more
                      # if look long on the price, buy the stock more
                      if (
                          _pred_trend == self.TREND_SHORT
                          and order.direction == order.SELL
                          or _pred_trend == self.TREND_LONG
                          and order.direction == order.BUY
                      ):
                          _order = Order(
                              stock_id=order.stock_id,
                              amount=_order_amount,
                              start_time=trade_start_time,
                              end_time=trade_end_time,
                              direction=order.direction,  # 1 for buy
                          )
                          order_list.append(_order)
                  else:
                      # in the second one of two adjacent bars
                      # if look short on the price, buy the stock more
                      # if look long on the price, sell the stock more
                      if (
                          _pred_trend == self.TREND_SHORT
                          and order.direction == order.BUY
                          or _pred_trend == self.TREND_LONG
                          and order.direction == order.SELL
                      ):
                          _order = Order(
                              stock_id=order.stock_id,
                              amount=_order_amount,
                              start_time=trade_start_time,
                              end_time=trade_end_time,
                              direction=order.direction,  # 1 for buy
                          )
                          order_list.append(_order)
  
          if trade_step % 2 == 0:
              # in the first one of two adjacent bars, store the trend for the second one to use
              self.trade_trend[order.stock_id] = _pred_trend
  
      return TradeDecisionWO(order_list, self)
  
imports: from pathlib import Path
  import warnings
  import numpy
  import pandas
  from typing import IO, List, Tuple, Union
  from qlib.data.dataset.utils import convert_index_format
  from qlib.utils import lazy_sort_index
  from ...utils.resam import resam_ts_data, ts_data_last
  from ...data.data import D
  from ...strategy.base import BaseStrategy
  from ...backtest.decision import BaseTradeDecision, Order, TradeDecisionWO, TradeRange
  from ...backtest.exchange import Exchange, OrderHelper
  from ...backtest.utils import CommonInfrastructure, LevelInfrastructure
  from qlib.utils.file import get_io_object
  from qlib.backtest.utils import get_start_end_idx
label_desc: Use image node_id 3 for calling the SBBStrategyBase obj's underlying member method code with example usage: obj.generate_trade_decision(execute_result) and returns: TradeDecisionWO