# How to keep the ratio of two assets constant when one asset is appreciating towards the other

I am looking for a formula that lets me keep the ratio between two assets in my portfolio constant when one of the assets is appreciating continually in comparison to the other asset.

Imagine a portfolio consisting of USD and say Amazon stock in the year 1998. Over the next few years the stock will double in terms of USD again and again. I discovered that if the owner would sell ~28.5714 % of the stock per doubling the composition of the portfolio would approach 50% USD and 50% AMZN over time.

How can this number (28.5714 %) be mathematically derived? Is there a formula that lets me compute the portion that would have to be sold per doubling in order to arrive at a different portfolio composition? Say I would like to be only 10% exposed to AMZN.

I wrote and used this tool: https://davalb.github.io/continuous-divestment/ to experimentally arrive at the 28.5714 figure.

(I am not entirely sure if this is the right community to ask this question. If not I apologize. Any hints where I could get an answer to this question are very welcome!)

In $t=1$ you have $n_1$ amazon shares that are sold for $p_1$ each. You also have $C_1$ in cash, for a total portfolio value of $$W_1 = n_1 p_1 + C_1$$ In $t=2$ the price of the amazon shares rose to $p_2$. Now your portfolio value is $$W_2 = n_1 p_2 + C_1$$ You want a new situation $$W_2^{'} = n_2 p_2 + C_2$$ In which you have sold $n_1 - n_2$ Amazon shares, and put the proceedings of the selling in cash. You want to impose that the value of the Amazon shares over the total value of the portfolio is the same in $W_2^{'}$ and $W_1$ So you have 2 conditions: (1) $$\dfrac{n_2 \cdot p_2}{W_2^{'}} = \dfrac{n_1 \cdot p_1}{W_1}$$ and (2) $$C_2 = C_1 + p_2 (n_1 - n_2)$$ The second condition arises from the fact that the cash in $t=2$ is equal to the cash in $t=1$ plus the proceedings of the shares you sold. You do not add additional cash from your pockets. Putting (2) in (1) and solving for $n_2$ yields to: $$n_2 = n_1 \cdot \dfrac{p_1}{p_2} \cdot \dfrac{C_1 + n_1 p_2}{C_1 + n_1 p_1}$$ Suppose $p_1 = 1\$$,p_2 = 2\$$,$n_1 = 1 \,\text{share}$,$C_1 = 1\$$, the formula yields  n_2 = 0.75 \,\text{shares}. In fact, both the initial weight of the Amazon share is 50%. Also the final weight of the Amazon shares, after the price doubled and you sold 0.25 shares, is 50%. EDIT: The amount of shares you have to sell is$$ n_1 - n_2 = \Delta n = n_1 \left[ \dfrac{C_1 (p_2 - p_1)}{p_2(C_1 +n_1 p_1)} \right]$$Hypothesizing that the price double (p_2 = 2 p_1) and the initial cash weight for 50% (C_1 = n_1 p_1), we obtain$$ \dfrac{\Delta n}{n_1} = \dfrac{1}{4} $$That is, you have to sell 25% of your Amazon shares. EDIT2: There is the implicit assumption that you are able to sell all your \Delta n shares for the same price of p_2. This may not be true, especially if you have to sell a large amount of shares. You may not be able to find people willing to buy later shares at p_2, because they entered a buy order for a lower price Moreover, if the price falls (p_2 < p_1), you need to buy shares. In this case, if you don't want to borrow money, you have to impose the restriction C_2 \ge 0, which leads to a minimum p_2 value. If the price falls below this value, you have lost all your cash and you are not able to buy further shares. • Amazing! Thanks a lot. One question: how do you arrive at this:$$ n_1 - n_2 = \Delta n = n_1 \left[ \dfrac{C_1 (p_2 - p_1)}{p_2(C_1 +n_1 p_1)} \right]$$Aug 3 '17 at 15:04 • @DavidAlbrecht you take the formula for n_2 and you subtract it from n_1. After a little of algebra you obtain this result$$ n_1 - n_2 = n_1 - n_1 \cdot \dfrac{p_1}{p_2} \cdot \dfrac{C_1 + n_1 p_2}{C_1 + n_1 p_1} = \ldots Aug 3 '17 at 15:08