有些时候,为了对组合进行管理,只设定组合中相应资产的数量、市值或者比例,而不管当前的持仓情况,通过order_target_xxx方法进行操作。
Target:
-
size -> amount of shares, contracts in the portfolio of a specific asset
-
value -> value in monetary units of the asset in the portfolio
-
percent -> percentage (from current portfolio) value of the asset in the current portfolio
拿order_target_size 来看:
- If the target is greater than the position a buy is issued, with the difference target - position_size
Examples:
-
Pos: 0, target: 7 -> buy(size=7 - 0) -> buy(size=7)
-
Pos: 3, target: 7 -> buy(size=7 - 3) -> buy(size=4)
-
Pos: -3, target: 7 -> buy(size=7 - -3) -> buy(size=10)
-
Pos: -3, target: -2 -> buy(size=-2 - -3) -> buy(size=1)
-
If the target is smaller than the position a sell is issued with the difference position_size - target
Examples:
-
Pos: 0, target: -7 -> sell(size=0 - -7) -> sell(size=7)
-
Pos: 3, target: -7 -> sell(size=3 - -7) -> sell(size=10)
-
Pos: -3, target: -7 -> sell(size=-3 - -7) -> sell(size=4)
-
Pos: 3, target: 2 -> sell(size=3 - 2) -> sell(size=1)
When targetting a value with order_target_value, the current value of the asset in the portfolio and the position size are both taken into account to decide what the final underlying operation will be. The reasoning:
If position size is negative (short) and the target value has to be greater than the current value, this means: sell more
As such the logic works as follows:
-
If target > value and size >=0 -> buy
-
If target > value and size < 0 -> sell
-
If target < value and size >= 0 -> sell
-
If target < value and size < 0 -> buy
The logic for order_target_percent is the same as that of order_target_value. This method simply takes into account the current total value of the portfolio to determine the target value for the asset.
网友评论