Far - marketable securities - realized gain/loss question

Hi all, I was doing homework questions, and it seems to me that : for trading securities, the realized G/L when you are selling the trading securities dosen't equal to the difference between the sales price and the original cost of the securities. It is the difference between Yr 1 and Yr2 FV. What about for available for sale or held to maturity securities? For these two, realized G/L = sale price - cost(amortized for HTM)? Anyone can help? thanks!