docstr: Generates the target position according to the weight and the cash.
  NOTE: All the cash will be assigned to the tradable stock.
  Parameter:
  weight_position : dict {stock_id : weight}; allocate cash by weight_position
      among then, weight must be in this range: 0 < weight < 1
  cash : cash
  start_time : the start time point of the step
  end_time : the end time point of the step
  direction : the direction of the deal price for estimating the amount
              # NOTE: this function is used for calculating target position. So the default direction is buy
docstr_tok: ["Generates","the","target","position","according","to","the","weight","and","the","cash",".","NOTE",":","All","the","cash","will","be","assigned","to","the","tradable","stock",".","Parameter",":","weight_position",":","dict","{","stock_id",":","weight","}",";","allocate","cash","by","weight_position","among","then",",","weight","must","be","in","this","range",":","0","<","weight","<","1","cash",":","cash","start_time",":","the","start","time","point","of","the","step","end_time",":","the","end","time","point","of","the","step","direction",":","the","direction","of","the","deal","price","for","estimating","the","amount","#","NOTE",":","this","function","is","used","for","calculating","target","position",".","So","the","default","direction","is","buy"]
code: def generate_amount_position_from_weight_position(
      self,
      weight_position: dict,
      cash: float,
      start_time: pd.Timestamp,
      end_time: pd.Timestamp,
      direction: OrderDir = OrderDir.BUY,
  ) -> dict:
      """
      Generates the target position according to the weight and the cash.
      NOTE: All the cash will be assigned to the tradable stock.
      Parameter:
      weight_position : dict {stock_id : weight}; allocate cash by weight_position
          among then, weight must be in this range: 0 < weight < 1
      cash : cash
      start_time : the start time point of the step
      end_time : the end time point of the step
      direction : the direction of the deal price for estimating the amount
                  # NOTE: this function is used for calculating target position. So the default direction is buy
      """
  
      # calculate the total weight of tradable value
      tradable_weight = 0.0
      for stock_id, wp in weight_position.items():
          if self.is_stock_tradable(
              stock_id=stock_id,
              start_time=start_time,
              end_time=end_time,
          ):
              # weight_position must be greater than 0 and less than 1
              if wp < 0 or wp > 1:
                  raise ValueError(
                      "weight_position is {}, "
                      "weight_position is not in the range of (0, 1).".format(
                          wp
                      ),
                  )
              tradable_weight += wp
  
      if tradable_weight - 1.0 >= 1e-5:
          raise ValueError(
              "tradable_weight is {}, can not greater than 1.".format(
                  tradable_weight
              )
          )
  
      amount_dict = {}
      for stock_id in weight_position:
          if weight_position[stock_id] > 0.0 and self.is_stock_tradable(
              stock_id=stock_id,
              start_time=start_time,
              end_time=end_time,
          ):
              amount_dict[stock_id] = (
                  cash
                  * weight_position[stock_id]
                  / tradable_weight
                  // self.get_deal_price(
                      stock_id=stock_id,
                      start_time=start_time,
                      end_time=end_time,
                      direction=direction,
                  )
              )
      return amount_dict
  
imports: from __future__ import annotations
  from collections import defaultdict
  from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Type, Union, cast
  from ..utils.index_data import IndexData
  import random
  import numpy
  import pandas
  from qlib.backtest.position import BasePosition
  from ..config import C
  from ..constant import REG_CN, REG_TW
  from ..data.data import D
  from ..log import get_module_logger
  from .decision import Order, OrderDir, OrderHelper
  from .high_performance_ds import BaseQuote, NumpyQuote
label_desc: Use image node_id 16 for calling the Exchange obj's underlying member method code with example usage: obj.generate_amount_position_from_weight_position(weight_position, cash, start_time, end_time, direction) and returns: amount_dict