capturing stock trades

1,328 views
Skip to first unread message

Tim Docker

unread,
Apr 24, 2009, 7:35:47 AM4/24/09
to Ledger
a stock purchase/sale. Is there a convention for this?

The ledger sample file shows 50 AAPL @ $30, but in that case it's
credited against "Equity", and the manual suggests that the Equity
account should be reserved for initial balances.

Should I have a new top level account for the market(ie different
to Equity,Assets,Income, and Expenses)? ie something like:


2004/05/01 * Investment balance
Assets:Brokerage 50 AAPL @ $30.00
Market:Stock

This doesn't feel quite right. What do others do? I guess the
approach would be the same for the purchase of any asset which
has ongoing value.

Also, is it possible to get the dollars paid and shared received
to go to separate sub accounts? I could do something like:

2004/05/01 * Investment balance
Assets:Stocks 50 AAPL @ $30.00
Assets:Stocks $1500
Assets:Trading Account $-1500
Market:Stock

but it seems messy to have to manually calculate the transfer
amount.

Any tips or pointers would be appreciated.

Tim

Tim Docker

unread,
Apr 24, 2009, 7:58:49 AM4/24/09
to Ledger
Oops - I missed the fact that writing "50 AAPL @ $30" is an
entry only for AAPl - it doesn't affect the $. So it appears
you need to book the cashflow separately, and can hence refer
to a different account ie:

2004/05/01 * AAPL Purchase.
Assets:Stocks 50 AAPL @ $30.00
Assets:Trading Account $-1500
Market:Stocks

But I'm still interested in how others do this, and whether I need
to be manually calculating the total cash.

Tim

Vinod Kurup

unread,
Apr 24, 2009, 9:11:49 AM4/24/09
to Ledger
Here's how I do it. I got this from this mailing list a while ago.
Putting the commission into the 'AAPL' account allows for the realized
gain to be calculated properly.

The SELL transaction is more complicated, in order to make sure that
the gain or loss on the transaction gets captured into a 'Capital
Gains' account. It's easy enough for single buys and sells, but gets
hairy when you've had multiple buys (e.g. dollar cost averaging)

;; Transfer money to my brokerage

1998/05/01
Assets:Investments:Scottrade $1,000.00
Assets:Banking:Suntrust

;; Buy AAPL

1998/05/05 BUY AAPL
Assets:Investments:Scottrade:AAPL 10 AAPL @ $29.25
Assets:Investments:Scottrade:AAPL $14.95 ; commission
Assets:Investments:Scottrade

;; Sell AAPL

1999/08/16 SELL AAPL
Assets:Investments:Scottrade:AAPL -10 AAPL @ $29.25 ; buy price
Assets:Investments:Scottrade:AAPL 10 AAPL @ $60.375 ; sell price
Assets:Investments:Scottrade:AAPL -10 AAPL @ $60.375
Assets:Investments:Scottrade:AAPL $-14.95 ; buy commission
Income:Capital Gains:LT $14.98 ; sell
commission
Assets:Investments:Scottrade $588.77
Income:Capital Gains:LT

Hope that helps get you started...

Vinod

John Wiegley

unread,
Apr 24, 2009, 1:55:56 PM4/24/09
to ledge...@googlegroups.com
On Apr 24, 2009, at 7:35 AM, Tim Docker wrote:

> a stock purchase/sale. Is there a convention for this?

Yes, the typical convention is as follows:

2004/05/01 Stock purchase
Assets:Broker 50 AAPL @ $30.00
Expenses:Broker:Commissions $19.95
Assets:Broker $-1,500.00

This assumes you have a brokerage account that is capable of managed
both liquid and commodity assets. Now, on the day of the sale:

2005/08/01 Stock sale
Assets:Broker -50 APPL {$30.00} @ $50.00
Expenses:Broker:Commissions $19.95
Income:Capital Gains $-1,000.00
Assets:Broker $2,500.00

You can, of course, elide the amount of the last posting. I just put
it there for clarity's sake.

The {$30.00} is a lot price. You can also use a lot date,
[2004/05/01], or both, in case you have several lots of the same price/
date and your taxation model is based on longest-held-first.

John

Derek Mahar

unread,
Apr 25, 2009, 10:02:03 AM4/25/09
to Ledger
On Apr 24, 1:55 pm, John Wiegley <jwieg...@gmail.com> wrote:
>    2005/08/01 Stock sale
>        Assets:Broker                   -50 APPL {$30.00} @ $50.00
>        Expenses:Broker:Commissions       $19.95
>        Income:Capital Gains          $-1,000.00
>        Assets:Broker                  $2,500.00
>...
> The {$30.00} is a lot price.  You can also use a lot date,  
> [2004/05/01], or both, in case you have several lots of the same price/
> date and your taxation model is based on longest-held-first.

Do you know of any other ledger related tools for computing the gains
or losses using different methods for cost calculation (average cost,
first-in-first-out (same as longest-held-first), last-in-first-out)?

Derek

John Wiegley

unread,
Apr 25, 2009, 11:21:00 AM4/25/09
to ledge...@googlegroups.com
On Apr 25, 2009, at 10:02 AM, Derek Mahar wrote:

> Do you know of any other ledger related tools for computing the gains
> or losses using different methods for cost calculation (average cost,
> first-in-first-out (same as longest-held-first), last-in-first-out)?

Right now -- as with most things in the ledger world because it's about
reporting and not entering or modifying data -- you have to manually
specify exactly which past commodities you wish to sell. I think a GUI
on top of Ledger could do a good job of showing you which lots are
held, and allowing you to select an optimum set based on your desired
cost calculation. But the Ledger core does none of this.

John

Derek Mahar

unread,
Apr 26, 2009, 10:01:19 AM4/26/09
to Ledger
On Apr 25, 11:21 am, John Wiegley <jwieg...@gmail.com> wrote:
> Right now -- as with most things in the ledger world because it's about
> reporting and not entering or modifying data -- you have to manually
> specify exactly which past commodities you wish to sell.

So you need to specify the original cost of the commodities you wish
to sell or the date on which you bought those commodities or both?
What does ledger do if you specify neither? Must the cost be the
actual purchase price or can it be an average cost?

Since capital gains (or profit in general) is both an income entry and
a kind of report, might a ledger option compute these profit entries
on behalf of the user which the user could then use to replace the
original entries? Or, if the user leaves them out, might ledger
compute them automatically, similar to how it already automatically
balances a transaction by calculating the other side?

Derek

John Wiegley

unread,
Jun 3, 2009, 12:09:19 PM6/3/09
to ledge...@googlegroups.com
On Apr 26, 2009, at 3:01 PM, Derek Mahar wrote:

> So you need to specify the original cost of the commodities you wish
> to sell or the date on which you bought those commodities or both?

You can specify one, both or none.

> What does ledger do if you specify neither?

Ledger itself doesn't actually know anything about commodities as
opposed to anything else you might trade. Depending on the
information you provide, it can generate reports which reflect that
info. If you don't provide it, it just won't come through in any
reports.

> Must the cost be the actual purchase price or can it be an average
> cost?

Must be the actual purchase price.

> Since capital gains (or profit in general) is both an income entry and
> a kind of report, might a ledger option compute these profit entries
> on behalf of the user which the user could then use to replace the
> original entries? Or, if the user leaves them out, might ledger
> compute them automatically, similar to how it already automatically
> balances a transaction by calculating the other side?

Ledger doesn't really do any automatic computation of this kind. That
would be the job of an external tool, which might then generate Ledger-
compatible transactions.

John

vitoc

unread,
Jul 31, 2017, 1:46:05 PM7/31/17
to Ledger, tw...@dockerz.net
Hi,

Not trying to use ledger-cli for portfolio tracking, but as a reporting tool for accounting books, but I have a situation here that I am trying to resolve.

Here's the original state:

2016/09/10 
    Assets:Shares:SomeBroker   3000 "A68U"
    Assets:Savings:SomeBank  $899.53
    Equity:Opening Balances

Which is OK, and gives rise of course to this balance:

 $799.53
           3000 A68U  Assets
             $799.53    Savings:SomeBank
           3000 A68U    Shares:SomeBroker
            $-799.53
          -3000 A68U  Equity:Opening Balances
--------------------
                   0

If we make a stock purchase transaction:

2017/03/30 
  Assets:Shares:SomeBroker  870 "A68U" @ $0.919
  Assets:Savings:SomeBank  -$799.53

The balance report then gives:

           3870 A68U  Assets:Shares:SomeBroker
            $-799.53
          -3000 A68U  Equity:Opening Balances
--------------------
            $-799.53
            870 A68U

What can we usually do to get Asset = Equity (disregarding Liability for clarity's sake) without getting the difference here? Is that something that anyone will want? I do know that if I do -V it gives me this:

            $3556.53  Assets:Shares:SomeBroker
           $-3556.53  Equity:Opening Balances
--------------------
                   0

Just want to check if I am missing anything here. And if there's a better way to do this with multiple commodities.

Thanks,

Vito
Reply all
Reply to author
Forward
0 new messages