How to sell assets reducing gains? Backpack problem with FIFO
Suppose you have a portfolio with 3 funds (A, B, C) you have 30.000€ in each one but you have done 3 buys in each one (10.000€ each) and each one of the 9 positions (3×3) have diferent gains.
enter image description here
Knowing that if you sell from a fund it will sell first the first position you bought i.e. the oldest (FIFO). How can you determine which ones you should sell to generate 5.000 € while keeping the gains to the lowest to reduce taxes?