Project Home

Notes on Capital Gains

Old Notes

From "Filippo Tampieri" <filippo.tampieri@gmail.com> To "Martin Blais" <blais@furius.ca> Cc "John Wiegley" <johnw@newartisans.com> [Add] Subject Re: Here is one valid way to book capital gains Show full header Use #1. Also, you have to use the "average" purchased price for the asset. In other words, if you bought 100 AAPL at USD40/share, then bought another 100 AAPL at USD60/share, and finally sold 50 AAPL at USD70/share, you do not get to choose which lot you are selling from; instead, you have to think of having 200 AAPL at USD50/share; that's your cost basis; so when you sell the 50 AAPL at USD70/share, you are making USD20 a share (and are left with 150 AAPL at USD50/share). I actually prefer to think in terms of total costs. It is easier to understand, easier to program, and easier to account for commission costs. So, the example becomes: you bought 100 AAPL at USD4,000, then you bought another 100 AAPL at USD6,000, and finally sold 50 AAPL at USD3,500. Just before the sale, you had 200 AAPL at USD10,000; after the sale, you are left with 150 AAPL at USD6,500. Super-simple. Splits and stock exchanges are also very simple. Say, AAPL now splits 2:1, then I will have 300 AAPL at USD6,500; finally, something happens and they are exchanged for EEPL at 3:2 and I am left with 450 EEPL at USD6,500. See the cost basis never changes. For tax reporting in a different currency, say CAD, you simply have to replace all USD figures with CAD figures using the exchange rate at the date of the transaction where the USD currency is used (when you buy and when you sell), then you run all the transactions from scratch to update your holdings and realized gains (and you will have your report in the new currency). My software does all this, but it is extremely simple.

On Fri, Apr 25, 2008 at 1:36 PM, Martin Blais <blais@furius.ca> wrote:

Thanks for the clarification.

For calculating the gain, do you

1) convert the cost to CAD, convert the proceeds to CAD, then take the difference? (removing the commissions before converting each time)

or

2) calculate the capital gains in foreign currency (e.g. USD), minus the commission costs, and then convert at the rate when you closed your position?

On Fri, 25 Apr 2008 13:21:50 -0400, "Filippo Tampieri" <filippo.tampieri@gmail.com> said: > I'll try to be more clear. > For us living in Canada, the tax reporting currency is CAD. > The currency of the stock account is the currency used to buy the stock. > You > probably have a USD investment account and a CAD investment account. > So, if you buy AAPL in USD in your USD investment account, you will have > to > report realized gains to Canada Revenue in CAD. > > > On Fri, Apr 25, 2008 at 11:50 AM, Martin Blais <blais@furius.ca> wrote: > > > Your description makes it sound like I'll have to take care of all this > > manually... > > > > Which is the reporting currency, and which is the account currency? I'm > > not sure which is which, the words aren't clear to me. If you buy a > > foreign stock, do you declare the gains in the stock's native currency, > > or in converted amount in CAD? > > > > > > > > > > On Fri, 25 Apr 2008 11:16:23 -0400, "Filippo Tampieri" > > <filippo.tampieri@gmail.com> said: > > > The compute capital gains from US investments that are taxed in Canada, > > > you > > > will need to keep track of the date of each purchase so that you can > > > correctly compute your releazed gains/losses in the reporting currency > > > rather than the currency of the account (or transaction). Also, you will > > > have to provide for the possibility of stock exchanges (i.e. you bought > > > XXX, > > > but later that was exchange for YYY - due to a merger, for example - and > > > finally you sold YYY); this has happened a few times to my investments > > > over > > > the last few years. Finally, how do you account for splits? You may have > > > the > > > split ratio, but many brokers report splits by simply showing some amount > > > of > > > shares going into your accout at no cost (e.g. you have 100 shares of > > > AAPL; > > > they split 3:2; your account statement may show 50 shares of AAPL @ $0.00 > > > going into your account). > > > > > > > > > On Fri, Apr 25, 2008 at 12:17 AM, Martin Blais <blais@furius.ca> wrote: > > > > > > > ... in the absence of "true" tracking of positions and trades. > > > > This is not tooo bad, all I have to do is find the amounts of the > > > > commissions at both ends of the trade. > > > > > > > > > > > > > > > > def test_with_commissions(self): > > > > > > > > # Booked capital gains. > > > > lgr = ledger_str(self.def_accounts + """ > > > > > > > > 2008-01-10 * Bought some shares. > > > > Assets:Broker 10 AAPL @ 120.00 USD > > > > Expenses:Commissions 9.95 USD > > > > Assets:Bank -1209.95 USD > > > > > > > > 2008-01-11 * Sold some shares. > > > > Assets:Broker -10 AAPL {120.00 USD} @ 125.00 USD > > > > Assets:Bank 1240.05 USD ;; actual amount deposited > > > > (easy to find on statement) > > > > Expenses:Commissions 9.95 USD ;; actual commission for > > > > closing the trade > > > > Income:CapitalGains ;; automatically computed gain > > > > (from share cost above) > > > > [Income:CapitalGains] 19.90 USD ;; offset for commissions to > > > > open and close this trade, manually entered > > > > [Expenses:Deductible-Costs] ;; an account that track costs > > > > for closed trades > > > > > > > > """, 'booked-gains') > > > > assert len(lgr.transactions) == 2 > > > > > > > > commisions = 2*Decimal('9.95') > > > > for accname, amount in ( > > > > ('Assets:Bank', Decimal('50')-commisions), > > > > ('Expenses:Commissions', commisions), > > > > ('Income:CapitalGains', -(Decimal('50')-commisions)), > > > > ): > > > > assert (lgr.get_account(accname).total == Wallet('USD', > > > > amount)) > > > >

First Implementation [Martin Blais <blais@furius.ca>]

Hi John

Just wanted to let you know that I've partially solved the trade booking problem within beancount. The way I'm doing it is like this:

2004-07-23 * Buy Apple Inc
  Assets:Investments:XTrade:AAPL     10 "AAPL" @ 116.238 USD
  Expenses:Financial:Commissions     9.95 USD
  Assets:Investments:XTrade

2004-07-23 * Sell Apple Inc
  Assets:Investments:XTrade:AAPL    -8.3 "AAPL" @ 127.232 USD
  Expenses:Financial:Commissions     9.95 USD
  Assets:Investments:XTrade
  (Income:Investments:Capital-Gains)    BOOK "AAPL"

The transaction with the posting with "BOOK <COMMODITY>" has its postings searched for a (unique) one that has the given commodity (in this case, the first posting of the second transaction). From this posting, the account name is extracted (Assets:Investments:XTrade:AAPL). This process is repeated for all entries with BOOK entries.

Then, for each of the accounts, for each of the commodities that need to be inventoried, the postings of the account are iterated and a FIFO inventory is calculated of the positions. Gains/losses are realized when a posting with a BOOK entry is present, which case the inventory has its accumulated gains/losses cancelled and the amount is transferred to the booking entry (the line with BOOK in the example).

Note that I'm making a few assumptions:

  • I'm assuming that there is a single posting with the booking commodity in a transaction that contains a booking posting.
  • I'm assuming that the commodity is priced throughout the system in a single currency. This is the currency that the inventory uses.
  • I'm doing all inventory trades before filling in the booking entries.

On the web server, I have a new page which lists all the transactions involved in each trade. This works with closing the books, and with date filtering as well.

This method works well but does not take into account commissions. I think my accountant removes the commissions globally after gains/losses are computed, but I'm not sure (I can't reach him for a few days).

Anyway, just thought you might find this interesting. Let me know if you have suggestions on how to improve this.

Note: the demo has not been updated in the beancount code, but I'll do that as soon as I return from yoga later.

cheers,