“ I have only $1600 (100 sh * $20 = $2000 - $400 tax) to buy stock B. “ In this calculation you are also paying tax on the the original investment.