class_docstr: Order Generator With Interact
docstr: generate_order_list_from_target_weight_position
  
  No adjustment for for the nontradable share.
  All the tadable value is assigned to the tadable stock according to the weight.
  if interact == True, will use the price at trade date to generate order list
  else, will only use the price before the trade date to generate order list
  
  :param current:
  :type current: Position
  :param trade_exchange:
  :type trade_exchange: Exchange
  :param target_weight_position:
  :type target_weight_position: dict
  :param risk_degree:
  :type risk_degree: float
  :param pred_start_time:
  :type pred_start_time: pd.Timestamp
  :param pred_end_time:
  :type pred_end_time: pd.Timestamp
  :param trade_start_time:
  :type trade_start_time: pd.Timestamp
  :param trade_end_time:
  :type trade_end_time: pd.Timestamp
  
  :rtype: list
code: def generate_order_list_from_target_weight_position(
      self,
      current: Position,
      trade_exchange: Exchange,
      target_weight_position: dict,
      risk_degree: float,
      pred_start_time: pd.Timestamp,
      pred_end_time: pd.Timestamp,
      trade_start_time: pd.Timestamp,
      trade_end_time: pd.Timestamp,
  ) -> list:
      """generate_order_list_from_target_weight_position
  
      No adjustment for for the nontradable share.
      All the tadable value is assigned to the tadable stock according to the weight.
      if interact == True, will use the price at trade date to generate order list
      else, will only use the price before the trade date to generate order list
  
      :param current:
      :type current: Position
      :param trade_exchange:
      :type trade_exchange: Exchange
      :param target_weight_position:
      :type target_weight_position: dict
      :param risk_degree:
      :type risk_degree: float
      :param pred_start_time:
      :type pred_start_time: pd.Timestamp
      :param pred_end_time:
      :type pred_end_time: pd.Timestamp
      :param trade_start_time:
      :type trade_start_time: pd.Timestamp
      :param trade_end_time:
      :type trade_end_time: pd.Timestamp
  
      :rtype: list
      """
      if target_weight_position is None:
          return []
  
      # calculate current_tradable_value
      current_amount_dict = current.get_stock_amount_dict()
  
      current_total_value = (
          trade_exchange.calculate_amount_position_value(
              amount_dict=current_amount_dict,
              start_time=trade_start_time,
              end_time=trade_end_time,
              only_tradable=False,
          )
      )
      current_tradable_value = (
          trade_exchange.calculate_amount_position_value(
              amount_dict=current_amount_dict,
              start_time=trade_start_time,
              end_time=trade_end_time,
              only_tradable=True,
          )
      )
      # add cash
      current_tradable_value += current.get_cash()
  
      reserved_cash = (1.0 - risk_degree) * (
          current_total_value + current.get_cash()
      )
      current_tradable_value -= reserved_cash
  
      if current_tradable_value < 0:
          # if you sell all the tradable stock can not meet the reserved
          # value. Then just sell all the stocks
          target_amount_dict = copy.deepcopy(current_amount_dict.copy())
          for stock_id in list(target_amount_dict.keys()):
              if trade_exchange.is_stock_tradable(
                  stock_id,
                  start_time=trade_start_time,
                  end_time=trade_end_time,
              ):
                  del target_amount_dict[stock_id]
      else:
          # consider cost rate
          current_tradable_value /= 1 + max(
              trade_exchange.close_cost, trade_exchange.open_cost
          )
  
          # strategy 1 : generate amount_position by weight_position
          # Use API in Exchange()
          target_amount_dict = trade_exchange.generate_amount_position_from_weight_position(
              weight_position=target_weight_position,
              cash=current_tradable_value,
              start_time=trade_start_time,
              end_time=trade_end_time,
          )
      order_list = (
          trade_exchange.generate_order_for_target_amount_position(
              target_position=target_amount_dict,
              current_position=current_amount_dict,
              start_time=trade_start_time,
              end_time=trade_end_time,
          )
      )
      return order_list
  
file_path: qlib/qlib/contrib/strategy/order_generator.py
imports: from ...backtest.position import Position
  from ...backtest.exchange import Exchange
  import pandas
  import copy
label_desc: Use image node_id 1 for calling the OrderGenWInteract obj's underlying member method code with example usage: obj.generate_order_list_from_target_weight_position(current, trade_exchange, target_weight_position, risk_degree, pred_start_time, pred_end_time, trade_start_time, trade_end_time) and returns: order_list, list