Why You Don't Need to Harvest Everything
Most investors think of tax-loss harvesting as an all-or-nothing proposition. You either sell a stock to harvest the loss, or you do not. But there is a middle ground: partial harvesting, where you sell only enough shares to achieve the desired tax offset.
Partial harvesting matters for two important reasons. First, you may not need the full loss. If you have Rs 5,000 in short-term capital gains to offset, and a stock offers Rs 50,000 in harvestable short-term losses, selling everything captures Rs 45,000 more loss than you need. While excess losses can be carried forward, it may not be optimal to trigger a large sale with FIFO sell-through effects for a small offset.
Second, FIFO sell-through costs scale with the number of shares sold. Selling fewer shares means selling through fewer long-term lots, which means less forced LTCG. There may be a sweet spot where you sell just enough to capture the needed loss while keeping the sell-through cost manageable.
This article explains how to find the optimal quantity to sell, a problem that TaxHarvestLab solves using a binary search algorithm. We will walk through the logic, the math, and the practical implications of partial harvesting.
The Setup: When Partial Harvesting Applies
Partial harvesting is relevant when you have a stock with both long-term and short-term lots, the short-term lots are at a loss, and you want to capture only a specific amount of that loss.
Consider this portfolio position in ITC: - Lot 1: 300 shares at Rs 350, bought 1 January 2024 (long-term, 14+ months) - Lot 2: 100 shares at Rs 500, bought 1 November 2024 (short-term)
Current price: Rs 400.
Lot 1: LT gain = (400 - 350) x 300 = Rs 15,000 Lot 2: ST loss = (400 - 500) x 100 = -Rs 10,000
You have Rs 5,000 in STCG from another stock that you want to offset. You only need Rs 5,000 of the Rs 10,000 available STCL. So ideally, you would sell 50 of the 100 ST shares (Rs 100 loss per share x 50 = Rs 5,000 loss).
But FIFO does not let you sell just 50 ST shares. You must sell through all 300 LT shares first. So to sell 50 ST shares, you must sell 350 shares total (300 LT + 50 ST).
The question becomes: is selling 350 shares to harvest Rs 5,000 in STCL worth the forced Rs 15,000 LTCG from Lot 1?
Binary Search: Finding the Optimal Quantity
TaxHarvestLab uses a binary search algorithm to find the optimal number of shares to sell. Here is how it works conceptually.
The search space is the range of possible sale quantities, from 1 share to the total holding. For each candidate quantity, the tool computes:
- Which lots are consumed (FIFO order)
- The forced LTCG from any long-term lots consumed
- The STCL from any short-term lots consumed
- The net tax impact: STCL tax saving minus forced LTCG tax cost
The algorithm searches for the quantity that maximizes net tax benefit while meeting the target STCL.
In our ITC example, the binary search would evaluate quantities like:
- Sell 200 shares: All from Lot 1 (LT). LTCG = Rs 10,000. No STCL harvested. Not useful.
- Sell 300 shares: All from Lot 1. LTCG = Rs 15,000. No STCL. Still not useful.
- Sell 350 shares: 300 from Lot 1 (LTCG Rs 15,000) + 50 from Lot 2 (STCL Rs 5,000). Net tax impact: Rs 5,000 x 20% - max(0, Rs 15,000 - remaining exemption) x 12.5%.
- Sell 400 shares: 300 from Lot 1 (LTCG Rs 15,000) + 100 from Lot 2 (STCL Rs 10,000). Net tax impact: Rs 10,000 x 20% - max(0, Rs 15,000 - remaining exemption) x 12.5%.
If the Rs 15,000 LTCG is within the exemption (cost = Rs 0), then selling 350 shares gives a net benefit of Rs 1,000, and selling 400 gives Rs 2,000. The algorithm picks the quantity that meets the target while keeping the LTCG within the exemption.
When the LTCG Exemption Makes Partial Harvesting Free
The best case for partial harvesting is when the forced LTCG from sell-through fits entirely within your remaining Rs 1.25 lakh exemption. In this case, the sell-through is free, and you can harvest exactly the amount of short-term loss you need.
Continuing the ITC example: suppose you have used Rs 1,00,000 of your Rs 1.25 lakh exemption so far this year. Remaining exemption: Rs 25,000. The forced LTCG from selling through Lot 1 is Rs 15,000, which is within the Rs 25,000 remaining exemption.
In this case, the sell-through costs nothing. You can sell 350 shares (300 LT + 50 ST), trigger Rs 15,000 in tax-free LTCG, and harvest Rs 5,000 in STCL. The tax saving is Rs 5,000 x 20% = Rs 1,000, with zero sell-through cost.
Even better, the sell-through effectively harvests Rs 15,000 in LTCG tax-free. When you repurchase the shares, your new cost basis for those shares resets to Rs 400 (current price), locking in the gain tax-free. This is a combined gain-and-loss harvest.
TaxHarvestLab recognizes these combined harvesting opportunities and recommends them with clear dollar-for-dollar tax impact analysis. It is one of the tool's most valuable features for year-end tax planning.
The key insight is that partial harvesting, combined with the LTCG exemption, can turn a seemingly costly sell-through into a net positive transaction.
When Partial Harvesting Reduces But Does Not Eliminate the Cost
Sometimes the forced LTCG exceeds the exemption even with partial harvesting. In these cases, the question is not whether there is a cost, but how much cost you are willing to accept.
Scenario: You hold a stock with 500 LT shares (gain Rs 600/share) and 100 ST shares (loss Rs 100/share). Forced LTCG for full sell-through = Rs 3,00,000. Well above the Rs 1.25 lakh exemption.
Full harvest: Sell 600 shares. LTCG = Rs 3,00,000. Taxable LTCG (above Rs 1.25 lakh) = Rs 1,75,000. Tax = Rs 21,875. STCL = Rs 10,000. Tax saved = Rs 2,000. Net loss = Rs 19,875. Clearly unprofitable.
But what if you do not need to harvest all the ST loss? What if you only need Rs 3,000 in STCL?
Partial harvest: Sell 530 shares. First 500 from LT (LTCG = Rs 3,00,000), next 30 from ST (STCL = Rs 3,000). The sell-through LTCG is still Rs 3,00,000 regardless of how many ST shares you sell. Selling 530 or 600 shares produces the same forced LTCG.
This reveals an important limitation: partial harvesting reduces the STCL captured but does not reduce the forced LTCG from sell-through. The LT lots must be fully sold through regardless. The only way to reduce forced LTCG is to not sell at all.
In cases where the forced LTCG far exceeds the exemption, partial harvesting does not save you. TaxHarvestLab would flag this entire opportunity as unprofitable and recommend against any harvesting.
The Algorithm in Detail: How TaxHarvestLab Optimizes
TaxHarvestLab's binary search for minimum ST quantity works as follows:
Input: Target STCL amount, stock lot structure, remaining LTCG exemption.
Step 1: Determine the total LT shares that must be sold through. This is fixed and equals the total LT holding for the stock.
Step 2: Calculate the forced LTCG from all LT shares. Check against the remaining exemption. If forced LTCG above exemption creates a cost that exceeds the maximum possible STCL benefit, flag as unprofitable and stop.
Step 3: If potentially profitable, binary search for the minimum number of ST shares to sell. The lower bound is 1 share and the upper bound is the total ST holding.
Step 4: For each candidate ST quantity, compute the STCL and the net tax impact. The net impact is STCL x 0.20 - max(0, forced LTCG - remaining exemption) x 0.125.
Step 5: Find the smallest ST quantity where the captured STCL meets or exceeds the target. This is the minimum recommended sale quantity.
Step 6: Report the total shares to sell (all LT shares + minimum ST shares), the forced LTCG, the captured STCL, and the net tax impact.
This algorithm runs in logarithmic time relative to the number of ST shares, making it efficient even for large positions. The result is the smallest possible trade that achieves the investor's tax offset goal while minimizing sell-through costs.
Practical Example: Finding the Minimum
Let us work through a complete example of the binary search.
You need to offset Rs 5,000 in STCG. You hold a stock with: - 150 LT shares at Rs 300, current price Rs 400 (LT gain = Rs 100/share) - 80 ST shares at Rs 500, current price Rs 400 (ST loss = Rs 100/share)
Forced LTCG from selling all 150 LT shares = 150 x Rs 100 = Rs 15,000. Assume remaining exemption = Rs 50,000. So forced LTCG is within exemption; cost = Rs 0.
Now find minimum ST shares to sell: - Target STCL = Rs 5,000 - Loss per ST share = Rs 100 - Minimum ST shares = Rs 5,000 / Rs 100 = 50 shares
Total sale: 150 LT shares + 50 ST shares = 200 shares.
Result: - Forced LTCG: Rs 15,000 (within exemption, tax = Rs 0) - Captured STCL: Rs 5,000 (tax saving = Rs 1,000) - Net benefit: Rs 1,000
You sell exactly 200 shares, not the full 230. You harvest exactly the STCL you need. The remaining 30 ST shares stay in your portfolio for future harvesting if needed.
After the sale, you can repurchase all 200 shares at Rs 400. Your new lot structure starts fresh with 200 shares at Rs 400 (plus the 30 remaining ST shares at Rs 500).
Key Takeaways: Precision Over Brute Force
Partial harvesting is about precision. Instead of selling your entire position and dealing with whatever FIFO consequences arise, you calculate exactly how much to sell to achieve your tax goal.
Here are the key principles:
- You do not need to harvest all available losses. Determine your target STCL based on the STCG you need to offset, then sell the minimum required.
- The forced LTCG from sell-through is fixed once you decide to reach the ST lot. Whether you sell 1 ST share or all ST shares, the LT sell-through is the same. Partial harvesting reduces the STCL captured but does not reduce the sell-through cost.
- Partial harvesting is most beneficial when the forced LTCG is within the exemption (zero cost) and you only need a portion of the available STCL.
- When forced LTCG exceeds the exemption, partial harvesting cannot fix the problem. The sell-through cost is incurred regardless. In such cases, do not harvest at all.
- TaxHarvestLab uses binary search to find the optimal ST quantity, balancing the target STCL against the sell-through cost and your remaining LTCG exemption.
- After partial harvesting, repurchase the sold shares to maintain your market exposure. India has no wash sale rule for equity, so immediate repurchase is allowed.
Precision harvesting is a hallmark of sophisticated tax planning. It requires understanding FIFO at the lot level, which is exactly what TaxHarvestLab provides.
See how this applies to your portfolio
Upload your Zerodha or Groww reports and get personalized recommendations in under 2 minutes.
Analyze My Portfolio FreeFrequently Asked Questions
Can I sell only my short-term shares without selling the long-term shares?
No. Under FIFO, the oldest shares are sold first. To reach short-term lots, you must sell through all long-term lots first. Partial harvesting refers to selling fewer short-term shares (not skipping long-term ones), but the long-term sell-through is unavoidable.
Does selling fewer short-term shares reduce the forced LTCG?
No. The forced LTCG is determined by the total long-term holding, which must be fully sold through regardless of how many short-term shares you sell afterward. Partial harvesting controls the STCL captured but not the sell-through cost.
How does TaxHarvestLab determine the optimal number of shares to sell?
TaxHarvestLab uses a binary search algorithm. It calculates the forced LTCG from sell-through, checks it against your remaining LTCG exemption, then searches for the minimum number of short-term shares that produces the target STCL. The result is the smallest trade that achieves your tax offset goal.
Is there a minimum loss worth harvesting with FIFO sell-through?
There is no fixed minimum, but as a practical guide, if the forced LTCG exceeds the exemption, the STCL must be at least 62.5% of the excess LTCG to break even. For very small losses (under Rs 5,000) with significant sell-through, the effort and transaction costs are usually not justified.