To manage several assets, you think in target weights: for example 40% in an equity ETF, 40% in a bond ETF, 20% in gold. self.order_target_percent(data=d, target=0.40) adjusts the position in d so that it weighs 40% of the total value.
The order works out the difference by itself: if the asset weighs 30%, it buys what is missing; if it weighs 50%, it sells the excess; target=0 closes the position. There are also order_target_size (in units) and order_target_value (in amount).
The calculation uses the price known at decision time, but execution happens at the next open: the weight obtained is therefore only approximate. Keep a small cash buffer, otherwise an order may be refused (Margin status).
Order of operations: send the sells first, then the buys. Sells free up cash; if the buys go first, the broker may refuse them for lack of cash.
Examples
OMEGA-X (fictional market) : The candles and the dotted line are two assets in the portfolio. When one rises faster than the other, its weight climbs; order_target_percent brings each back to its planned share.
1952: Harry Markowitz and diversification : In 1952, Harry Markowitz published “Portfolio Selection” in the Journal of Finance. He showed that an asset should be judged by its contribution to the risk of the whole portfolio, not in isolation. This work earned him the Nobel Prize in economics in 1990.
Key terms
Target weight
Desired share of an asset in the portfolio value
order_target_percent
Order that adjusts a position towards a target percentage
Concentration
Situation where one asset weighs too much in the portfolio