usually by FIFO method. If you hold a mutual fund over years and reinvest, there is no way you can keep track yourself.