How much will we lose if we buy and sell shares too frequently? Optimal strategy for cashing out shares, tax harvesting and more.
When we sell a share, we need to pay capital tax.
Assume we sell a share, and then immediately buy the same share, or equivalentyield share, does it affect our gain? Are many transactions good for the gain or bad for the gain? When we have a portfolio of shares, and we need cash, which share should we sell? You can skip the math, and jump right to the last conclusion section.
Example: Excessive transaction in a profitable share
Let’s look at a simple example of a share which is in profit (profitable share): We bought a share at $100, a share that doubles every year, and have a capitaltax of 25%. Today, after 1 year, we have two options:
 Sell at \$200, cash left: \$175 (tax paid: \$25). Buy at \$175, sell after another 1 year at \$350 (tax paid: \$43.75), cash: \$306.25.
 Don’t sell at \$200, only after another 1 year when it reaches \$400. Cash after two years: \$325 (tax paid: \$75).
So we can see in this simple example that holding the share for two years, and not sellingbuying after one year, is optimal.
Why is this happening? How can we explain it? One way to look at it is that when we paid more capitaltax, it means we had more profit. So let’s look at the tax. In the second scenario, we paid tax on the growth of 100>400=+300 in share price. In the first scenario, we had growth of 100>200=+100, 175>350=+175, total +275.
If we split the second scenario into two growths: 100>200, 200>400, we can see that the only difference is the run 200>400 instead of 175>350. So in the 2nd scenario, we kept the tax to ourselves, so the run starts from 200 (bad), but the tax doubles itself every year, and the run ends at 400. While in the 1st scenario, the run starts from 175 (good), but we don’t have the tax to ourselves, so the run ends at 350, instead of 400 of the 2nd scenario. In other words, we earned +5025=\$25 more in the 2nd scenario, and the profit is 0.75*\$25 more.
What happens if the share goes down and halves every year? In this case, there’s no tax to pay, and with both scenarios we’re left with $25 after two years. So the conclusion is that even when the share goes up or down, it’s better to minimize unneeded transactions. Furthermore, in practice, sometimes there are additional fees associated with buy/sell, which strengthen the conclusion even more.
Example: Excessive transaction in a lossy share (share with current value lower than the purchase value)
We bought a share at \$100, and have a capitaltax of 25%. Today, after 1 year, the price is \$75, and we know it will double in a year. We have two options:
 Sell at \$75 cash left: \$75 (no tax paid, and we can keep the capital loss to offset tax in the future). Buy at \$75, sell after another 1 year at \$150. We have a profit of \$75, but we keep the loss from the previous year of \$25, so we only need to pay tax on a profit of \$50 which is \$12.5, cash: \$137.5.
 Don’t sell at \$75, only after another 1 year when it reaches \$150. Cash after two years: \$137.5 (tax paid: \$12.5).
So we can see that in the case of a lossy share, it doesn’t matter if we keep it, or sell and buy it again. Since there was no tax event involved, it does not matter, unlike the case of a profitable share, in which selling and buying again is not a smart move.
The general case of excessive transactions of a profitable share
Define $b$ as the buyprice of the share, $y$ as the yieldmultiple per year (e.g. a multiple of 1.1), $n$ as the number of years in our experiment, $s$ as the sell price, $t$ as the capitaltax ratio (e.g. $0.25$), $c$ as the net cash after the sell. Then, the sell price and the net cash we have after the tax reduction are:
\[s = b * y^n\] \[c = s  (sb) * t\]Injecting the first equation into the second, we can write the cash after a single sell:
\[c = by^n  (by^nb) * t = by^nby^nt+bt = b(y^ny^nt+t) = b(y^n(1t)+t)\]How much do we lose from frequent/unnecessary intermediate sales?
Define $f$ as the frequency of sales (number of sales during the $n$ years of our experiment), so the effective yield for each sub period of $\frac{n}{f}$ years is:
\[p = (y^n)^{1/f} = y^{n/f}\]So the cash after $f$ periods of buy/sell is:
\[b (y^{\frac{n}{f}} (1t)+t)^{f}\]So how much money do we lose from unnecessary sales? Let’s calculate the portion of money we stay with, in comparison to a single sell:
\[\frac{(y^{\frac{n}{f}} (1t)+t)^{f}}{y^n(1t)+t} \quad \square\]For example, if the annual yield is 10% (y=1.1), capitaltax is 25% (t=0.25), number of sales is f=10, and the experiment is for n=10 years, we get a portion of $0.94$. That means we lose 6% due to the 10 sales we did, instead of holding the share and selling it once at the end of the experiment.
If we look at 20 years, and we sell and buy once a year, $y=1.1, t=0.25, f=20, n=20$ we get a portion of $0.80$, meaning that we lose $20\%$, by doing too many transactions. That’s definitely not negligible.
Another example: $y=1.2, t=0.25, f=10, n=10$ we get a portion of $0.83$, meaning that we lose $17\%$.
Cashing out
We have a portfolio of two or more shares, and we need to cash out. Which share should we sell?
Two Different CapitalTax Shares
What happens if we hold two shares, each with different capital tax rules, and we need to liquidate and get some cash out? Is it better to sell the hightax share or the lowtax share? Instinctively, it’s intuitive to want to sell the lowtax share, to pay less tax, right?
We buy share A at \$100 with capitaltax of 25% and buy share B at \$100 with capitaltax of 0%, both double every year. After 1 year we need \$100 in cash to buy a TV. Our options are either sell from share A or sell from share B:

After 1 year, share A is valued at \$200. If we decide to sell 57% of our share A position, we cash out 0.57 * (\$200  25% * (\$200  \$100)) = \$100 to buy our TV, and we’re left with 0.43 shares A and 1.0 of share B which we didn’t sell. Wait another year, and we now sell 0.43 shares of A to have cash of 0.43*( \$400  (\$400  \$100) * 25%)= \$139.75 . Then sell share B, pay \$0 in taxes, and get \$400. Total cash after two years: \$539.75.

After 1 year, share B is valued at \$200. Sell \$100 out of share B, pay no taxes, and get the \$100 cash to buy our TV. So we’re left with 0.5 shares of B and 1.0 of share A. Wait another year. Sell 1.0 shares of A to get cash of 1.0*( \$400  25% * (\$400  \$100))= \$325 . Sell 0.5 share B, pay zero taxes, and get \$200. Total cash after two years: \$525.
In this very specific example, we see that we need to sell share A with the higher capitaltax, but this is not always the case, and it depends on all the other parameters, as shown in the following paragraphs.
It is not true to state that we should keep the share with the lower/higher capital tax, in all cases.
Two shares with identical yield but different purchase price, current price, taxation level
We bought share A at $b_a$, valued today at $v_a$ with capitaltax of $t_a$ (e.g. 0.25) and bought share B at $b_b$, valued today at $v_b$ with capitaltax of $t_b$, both has yieldmultiple per year of $y$ (e.g. 1.1). We now need $c$ in cash to buy something, and we plan to hold the shares for $n$ years, until the end of our experiment. Our options are either sell from share A or sell from share B:
If we decide to sell a fraction of $\frac{c}{v_a  t_a(v_a  b_a)}$ of our share A position, we cash out exactly $\frac{c}{v_a  t_a(v_a  b_a)}* (v_a  t_a(v_a  b_a)) = c $ to buy our TV, and we’re left with $1\frac{c}{v_a  t_a(v_a  b_a)}$ shares of A and 1.0 shares of B. Wait $n$ years, and we now sell $1\frac{c}{v_a  t_a(v_a  b_a)}$ shares of A to have cash of
\[(1  \frac{c}{v_a  t_a(v_a  b_a)}) * ( v_a y^n(1t_a) + b_a t_a)\]Then sell 1.0 share B to get cash of $ (v_b y^n (1t_b) + b_b t_b) $.
Total cash after $n$ years:
\[\begin{equation} \label{eq:1} \begin{aligned} (1  \frac{c}{v_a(1t_a) + b_a t_a}) * ( v_a y^n(1t_a) + b_a t_a) + \underbrace{v_b y^n (1t_b) + b_b t_b}_{\text{X}} \end{aligned} \end{equation}\]If we decide to cash out from share B, we just need to swap variables, and the cash we get after $n$ years is:
\[\begin{equation} \label{eq:2} \begin{aligned} (1  \frac{c}{v_b (1t_b) + b_b t_b }) * ( v_b y^n(1t_b) + b_b t_b) + \underbrace{v_a y^n (1t_a) + b_a t_a}_{\text{Y}} \end{aligned} \end{equation}\]Let’s compare which expression is higher, and subtract X and Y from both sides, to find the maximal expression:
\[\begin{equation} \label{eq:3} \begin{aligned} (  \frac{c}{v_a(1t_a) + b_a t_a}) * ( v_a y^n(1t_a) + b_a t_a) \: ? \: (  \frac{c}{v_b (1t_b) + b_b t_b }) * ( v_b y^n(1t_b) + b_b t_b) \end{aligned} \end{equation}\]As you can see, we can eliminate c. That’s why the amount of cash we need to cash out does not affect the decision. Let’s divide by $(c)$ and locate the minimal expression:
\[\begin{equation} \label{eq:4} \begin{aligned} \frac{ v_a y^n(1t_a) + b_a t_a}{v_a(1t_a) + b_a t_a} \: \: ? \: \: \frac{ v_b y^n(1t_b) + b_b t_b}{v_b (1t_b) + b_b t_b } \end{aligned} \end{equation}\]It’s nice to see that each side does not mix variables between shares. Let’s look on one side, divide the nominator and the denominator by b, and define $m=\frac{v}{b}$.
So, in the general case, the optimal strategy is to sell the share that has a minimum value of the gain:
\[\begin{equation} \label{eq:7} \begin{aligned} G := \frac{ m y^n t(m y^n 1)}{m t(m 1)} \end{aligned} \end{equation}\]As we can see, v and b does not appear in the formula anymore, just m. That means that the only parameters that can affect the decision are the quadruplet of (y, t, m, n).
Alternatively, we can denote what we expect the price of the share to be in n years as $F=v y^n$ and we get:
\[\begin{equation} \label{eq:6} \begin{aligned} G := \frac{ \underbrace{F t(F b)}_{\text{Future Profit}} }{ \underbrace{v t(v  b) }_{\text{Current Profit}} } \end{aligned} \end{equation}\]If you observe carefully, you see that the nominator is the net profit if we sell the share in n years, and the denominator is the net profit if we sell the share today. In other words, the golden rule is: Out of a portfolio of shares, sell the share of which the ratio of future net profit to the current net profit is the lowest. If we define the ratio between future profit to current profit as the gain G, we should strive to hold the shares having the highest G.
If two shares have the same yield and taxation
What if two shares have the same yield and taxation? It means that given the same yield and taxation, because of formula (5), two shares with the same m have the same gain. But, do we need to sell the higher m or the lower? Let’s differentiate by m to see how the G changes:
\[\begin{aligned} \frac{\partial G}{\partial m} = \frac{(y^n t y^n)(m t(m 1))(m y^n t(m y^n 1))(1 t)}{(m t(m 1))^2} = \end{aligned}\] \[\begin{aligned} \frac{ (1t) \quad [ y^nmty^nm + y^nt  m y^n + tm y^n  t] }{(m t(m 1))^2}= \end{aligned}\] \[\begin{aligned} \frac{ (1t) \quad t [ y^n  1] }{(m t(m 1))^2} \end{aligned}\]Now, since t is positive, (1t) is positive, the denominator is positive and if the yield is positive then y>1, then also $y^n  1$ is positive, we can see that the derivative is positive. That means that increasing m increases G and vice versa. And that means that G is monotonously increasing w.r.t. to m, and if we have two (or more) shares with the same yield and taxation, the only thing we need to know is m. We want to sell the share with the lowest m, that is, we want to sell the share with the lowest current price to purchase price ratio, the share that its price has grown by the least multiple since we purchased it.
Observation 1: If you apply this rule to the case when we bought two lots of the same share/company, each with a different pricepershare, then since obviously the current price per share is identical (because it’s the same share/symbol), selling the lower m means selling the share/lot with the higher purchase price. This is sometimes called Highest Cost Basis Policy, and it’s obvious: if you have 2 shares, and you need to sell 1, if you sell the share with the higher cost, you will pay less tax, and still remain with 1 share.
Observation 2: If you have multiple shares, all with the same yield and taxation, selling the share with the lowest m strategy is equivalent to selling the share in which the current tax event is the smallest in absolute dollars $ (the proof is similar, by doing a derivative of the current tax payment, w.r.t. to m).
One share has zero taxation, but both have the same yield
If share A has zero taxation, and B has nonzero taxation, and share A has the same yield (or better) than share B, it’s always better to keep share A, and sell B. According to equation (5) we can see share A has G of $y^n$. Let’s prove that the gain of A is higher than the gain of B:
\[\begin{aligned} y^n > \frac{ m y^n t(m y^n 1)}{m t(m  1)} \rightarrow (mt(m1))y^n > my^n  t(my^n 1) \end{aligned}\] \[\newcommand{\b}[1]{\textbf{#1}} \begin{aligned} ty^n > t \rightarrow y^n>1 \quad \square \end{aligned}\]So if the expected yield is positive, the inequality holds, which proves our statement.
Concrete examples
And now for some concrete examples:
Example of lower nonzero taxation of B, identical yield of A and B, but still with different optimal strategy:
$b_a=400, v_a=1800, t_a=0.25, b_b=400, v_b=1500, t_b=0.15, y=1.05, n=8, c=600$ > best strategy: A
$b_a=200, v_a=3900, t_a=0.25, b_b=200, v_b=1400, t_b=0.15, y=1.30, n=10, c=300$ > best strategy: B
What happens if we expect a different yield for each share? Should we always keep the share with better yield (assume identical risk=variance)? Surprisingly and counterintuitively, the answer is no! Again, it depends on all other factors.
Example of better yield in share B, but we still need to cash out B:
$b_a=100, v_a=2000, t_a=0.25, y_a=1.35, b_b=800, v_b=1000, t_b=0.20, y_b=1.40, n=2, c=300$ > best strategy: sell B
And another surprising result: What happens if both shares have the same taxation (as in many real life cases), but the yield on share B is higher? Should we keep share B? No! Have a look:
$b_a=100, v_a=1700, t_a=0.30, y_a=1.35, b_b=1000, v_b=1600, t_b=0.30, y_b=1.40, n=2, c=500$ > best strategy: sell B
Another surprising result: share B has capital tax of 0%, while share A has capital tax of 20%, and we need to sell B. This is because share A has better yield than share B, which incentives to keep it. This is a signal of the countereffects: In general, we’d like to keep shares with lower taxation and better yield, but in this case the yield factor outweighed the tax factor.
$b_a=200, v_a=2500, t_a=0.20, y_a=1.35, b_b=700, v_b=3500, t_b=0.00, y_b=1.20, n=8, c=700 $ > best strategy: sell B, \$29569 vs \$34144
There are examples of when share B has better yield, and better taxation, and we still need to sell it:
$b_a=100, v_a=2600, t_a=0.25, y_a=1.35, b_b=700, v_b=900, t_b=0.20, y_b=1.40, n=2, c=400$ > best strategy: sell B, \$4405 vs \$4408
However, if share B has a capital tax of exactly zero, share A has nonzero tax, and yield of share A is equal or less to B, we should always keep B (with zero capital tax) and sell A, as proved above.
Sometimes, only the length of the experiment affects the decision, when all the other parameters are identical:
$b_a=800, v_a=2600, t_a=0.10, y_a=1.30, b_b=800, v_b=1000, t_b=0.30, y_b=1.35, n=9, c=200 $ > best strategy: sell A, \$33502 vs \$33290
$b_a=800, v_a=2600, t_a=0.10, y_a=1.30, b_b=800, v_b=1000, t_b=0.30, y_b=1.35, n=5, c=200 $ > best strategy: sell B, \$11422 vs \$11428
What happens when we’re forced to materialize a profit? Should we sell a lossy share?
We know from previous conclusions, that when we have two shares (with identical future expectations), one in profit, and one in loss, that if we need to cash out, we should sell the one in loss. However, what happens when we are forced to sell the share in profit, because of some external constraints, or that we have some information that this company is going to collapse? Or, what happens when we have a profit from some other capital profit (e.g. rent) that can be offset when we sell a share in loss? Should we sell a lossy share to offset positive capital tax?
Let’s define the problem statement: The capital tax is $t$. We materialized a profit of $w$ and bought with it a TV, and because of that we need to pay a tax of $\b{tw}$. We hold 1 unit of a lossy share that we bought at price $b$ and its current value is $v$ ( $\b{v < b} ) $. We consider selling a portion $\b{p}$ of the lossy share. If we sell a little portion, we won’t have cash to pay for the tax $tw$, so we’ll have to take a loan with interestmultiple of $\b{r>1}$ (e.g. 1.05, this can be seen as riskfree interest, or discount rate). If we sell too much, we’ll have spare cash that we will use to buy with it the lossy share. Anyhow, we will sell the share in $n$ years from now (assume the share will be in profit $vy^n>b$), in order to compare the experiments.
The tax that we need to pay now is $T\equiv t(w  \underbrace{p(bv)}_{\text{positive}} )$. If the tax is positive, we need to pay it, if it’s negative, we don’t get it as cash from the authorities, but it can be reduced from the tax we’ll pay when we sell the share, in full, after $n$ years from now.
If $T$ is positive, the cash we have now is $C_{tp} \equiv pvT$. If $C_{tp} <0$ we need a loan for the tax payment, otherwise if $C_{tp} >0$ we can purchase more units of our share.
If $T$ is negative, the cash we have now (positive for sure) is $C_{tn} \equiv pv$ and we can purchase the share with it, and save the tax benefit for the future.
Consider the loancase where $T>0,C_{tp}<0$. The cash we have after $n$ years is:
\[\begin{aligned} C_{tpcn}\equiv \underbrace{C_{tp}r^n }_{\text{pay the debt}} + \underbrace{(1p)(vy^n(1t)+tb)}_{\text{sell the remaining portion}} \end{aligned}\]Let’s differentiate it by $p$, to find the optimal strategy:
\[\begin{aligned} C_{tpcn}' = \underbrace{r^n (v(1t)+tb) }_{\text{cash if we'd sell share today and lend it}}  \underbrace{(vy^n(1t)+tb) }_{\text{cash if wait n years and then sell}} \end{aligned}\]It’s interesting to see that the derivative is negative, if it’s better to hold a share, then to sell it now (and lend the money), which is usually the case, otherwise there would be no point in holding any share. So, since $C_{tpcn}’ < 0$ we would like to reduce $p$ to 0 in order to maximize our utility. This means we should not share any portion of the lossy share, but just take a loan. At $p=0$ we will have: $C_{tpcn}(p=0)=twr^n+vy^n(1t)+tb$ $\square$
Consider the positive cash case where $T>0,C_{tp}>0$. We’ll use all the available cash to buy the share.
\[\begin{aligned} C_{tpcp} = \underbrace{C_{tp}(y^n(1t)+t)}_{\text{from buying more portion today}} + \underbrace{(1p)(vy^n(1t)+tb)}_{\text{sell the remaining portion}} \end{aligned}\]Let’s differentiate w.r.t. to p:
\[\begin{aligned} C_{tpcp}' = (v(1t) + tb)(y^n(1t)+t) (vy^n(1t)+tb) \end{aligned}\]This will be positive when our assumption ($v < b$) holds.
Click for proof
$$ \begin{aligned} C_{tpcp}' = vy^n(1t)^2 + vt(1t) + tby^n(1t) + t^2b  vy^n(1t)  tb \end{aligned} $$ $$ \begin{aligned} = vy^n(1t)^2 + vt(1t) + tby^n(1t)  vy^n(1t)  tb(1t) \end{aligned} $$ $$ \begin{aligned} = (1t)( vy^n(1t) + vt + tby^n  vy^n  tb)=t(1t)( vy^n + v + by^n  b) \end{aligned} $$ $$ \begin{aligned} =t(1t)(y^n1)(bv) \end{aligned} $$ Since all elements are positive, the whole expression is positive. $\square$$ $
That means increasing $p$ will increase $C_{tpcp}$ and will decrease $T$, until we reach to $T=0$ and in this case p will reach: $wp(bv)=0 \rightarrow p = \frac{w}{bv}$ and at this $p$ we will have:
\[\begin{aligned} C_{tpcp} = pv(y^n(1t)+t) + (1p)(vy^n(1t)+tb) = t(bw)+vy^n(1t) \end{aligned}\]Now consider the case of $ T <0 $ (when $p$ is above $\frac{w}{bv}$):
\[\begin{aligned} C_{tncp}= \underbrace{pv(y^n(1t)+t)}_{\text{from buying more portion today}} + \underbrace{(1p)(vy^n(1t)+tb)}_{\text{sell the remaining portion}}  \underbrace{t(wp(bv))}_{\text{tax we get back}} \end{aligned}\] \[\begin{aligned} C_{tncp}'= v(y^n(1t)+t) (vy^n(1t)+tb) + t(bv) = vt tb + t(bv)=0 \end{aligned}\]Since the derivative is 0, it means there’s no point in increasing p to a value more than $\frac{w}{bv}$, as nothing is changed.
So we have two stationary points: one of $p=\frac{w}{bv}$ with $ C_{tpcp}$ with no loan, and the other with $p=0$ with $C_{tpcn}$ when we take a loan to pay the tax. Let’s compare the two optimums:
\[\begin{aligned} \underbrace{t(bw)+vy^n(1t)}_{\text{when we sell a portion to have zero total tax}} \quad ? \quad \underbrace{twr^n+vy^n(1t)+tb}_{\text{when p=0 and we take a loan}} \end{aligned}\] \[\begin{aligned} \underbrace{1}_{\text{when we sell a portion to have zero total tax}} \quad ? \quad \underbrace{r^n}_{\text{when p=0 and we take a loan}} \end{aligned}\]Since $r>1$, we see that the best strategy is not to take a loan, but instead to sell a portion of $p=\frac{w}{bv}$ (or more), which means to sell a portion of the lossy share, so that the tax payment is zero (or a higher portion), then we have free cash due to the cashing out portion $p$ of the lossy share, and use the cash, to buy the share again (or a different share, assuming all have the same yield expectation for the future). The tax strategy is sometimes called Taxloss Harvesting. Selling and buying the same share is sometimes called Wash Sale.
Should we first sell the profitable or first sell the lossy? In some countries, the bank or the tradining institution, collects the tax at the moment you sell a share, and transfers it to the tax authorities. Only at the end of the year, when you do the annual tax report, you get the extra tax back. In these countries, it is better to first sell the lossy share and only then the profitable share. This way, the bank, when you sell the profitable share, takes into account the capital loss from the lossy share, so you pay less tax, and don’t have to wait until the end of the year.
If we sold a lossy share, should we also sell & buy a profitable share to increase its purchase price?
Let’s follow our usual example. We hold 1 lossy share A (b=\$100, v=\$50), and 1 profitable share B (b=\$100, v=\$200). We sell share A and buy a TV for \$50. Two cases:
 We keep the profitable share for one year, and then sell it at \$400. Our profit is \$300 minus the capital loss from previous year of \$50, so we pay tax of \$62.5 and have cash of \$337.5
 We sell the profitable share at \$200, and we have capital profit of \$100\$50=\$50, so we pay tax of \$12.5 we have cash of \$187.5. So we buy the share at \$187.5. After one year we sell it at \$375 and pay tax of \$46.875 so we have cash of \$328.125
We can see it’s better not to touch the profitable share, which corroborates our previous conclusion that excessive transactions in profitable shares is disadvantageous.
Conclusions
Unless we have other considerations, for example diversifying the portfolio to reduce variance (risk) or reduce correlation between shares:

Better to minimize unneeded transactions of selling and buying a share in profit, or switching a share in profit to a different share, due to the tax event we have to pay. Having transaction fees even strengthens this statement.

If we need to cash out, usually all parameters matter, and in general we need to cash out the share with the lowest gain, G, as defined in (5). However, if:
2.1 If a share has capital tax of exactly zero, with better or equal yield to the other share, we should always keep it, and the current shares prices or purchase prices do not matter. If the capital tax is zero but the yield is worse, we should consider all other parameters.
2.2. If two shares have the same yield and taxation, we should sell the share with the lowest m (lowest price increase in percentage), meaning the lowest current price to purchase price ratio. This is equivalent to choosing the share to sell, in which the present tax event size in $ is the lowest. That also means that we should prefer selling shares in loss rather than shares in profit.
2.3 All parameters matter, even if one share has a better yield than the other, and even if one share has a better yield and better taxation than the other. In some cases we need to sell the share with the higher yield. In some cases we need to sell the share with the lower taxation ratio.
2.4 Higher capitaltax on a share A increases the chances we need to sell A, but other parameters can change the decision.
2.5 Higher yield on a share A increases the chances we need to sell B, but other parameters can change the decision. Combining the two last statements: In general it’s more likely to keep shares with lower taxation and better yield, but other parameters can change the decision.

If we had a capital profit, we should offset it by selling a share in loss, in such an amount that will zero out our capital profit for this year, and buy the share again (or equivalent share). In countries when tax is collected by the trader, it is better to first sell the lossy share, and then the profitable share.
In general, you should try to avoid actions which results in a tax payment today.
\[\square\]Here’s a sheet table in which you can enter the parameters and make the right decision of which share to cash out.