Stock/Commodities fee posting positions and cost basis

75 views
Skip to first unread message

Joel Swanson

unread,
May 7, 2020, 3:16:40 PM5/7/20
to Ledger
Hello ledger devs & users,

Does posting order affect stock or commodity cost basis in Ledger?

Looking at the first example in section 4.5.2 of the documentation[1], one finds this example:

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

Running  a balance command with the '--lots' flag yields the expected AAPL @ $30.00 as follows, whether or not we specify "@ $30.00" in the AAPL purchase posting:

$ ledger -f temp.ledger bal --lots
           $-1,519.95
50 AAPL {$30.00} [2004-05-01]  Assets:Broker
              $19.95  Expenses:Broker:Commissions
--------------------
           $-1,500.00
50 AAPL {$30.00} [2004-05-01]



If the ledger journal lists the broker's commission first, as follows, the output is still the same as above, but only if we specify the "@ $30.00".

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

Instead, if we run the following input

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

the output with the '--lots' flag will show $1500 in terms of AAPL shares:

$ ledger -f temp.ledger bal --lots
$-1,519.95 {0.0333333333333333 AAPL} [2004-05-01]
             50 AAPL  Assets:Broker
$19.95 {0.0333333333333333 AAPL} [2004-05-01]  Expenses:Broker:Commissions
--------------------
$-1,500.00 {0.0333333333333333 AAPL} [2004-05-01]
             50 AAPL


Is that really the desired behavior, where changing the order of postings changes the items for which ledger tracks lots? Does this have something to do with which postings are considered primary and secondary in a transaction with three or more postings?

Additionally, the lot information isn't including the brokerage fee. Is there a way to include this in ledger's cost basis? Wouldn't the cost basis for these 50 shares of AAPL be $30.399, which includes the brokerage fee? Or would that violate ledger's principle of simply being a calculator and not forcing any particular accounting strategy on anyone?

Thanks!

FYI, I'm running Ledger 3.1.2-20190205.


John Wiegley

unread,
May 8, 2020, 12:07:03 AM5/8/20
to Joel Swanson, Ledger
>>>>> "JS" == Joel Swanson <jke...@gmail.com> writes:

JS> Does posting order affect stock or commodity cost basis in Ledger?

JS> Is that really the desired behavior, where changing the order of postings
JS> changes the items for which ledger tracks lots? Does this have something
JS> to do with which postings are considered primary and secondary in a
JS> transaction with three or more postings?

Yes, that is actually the reasoning. The first posting establishes the
secondary commodity, while the second is the primary.

You can avoid this confusing by not using the auto-calculation logic, and
identifying your lots explicitly:

2004/05/01 Stock purchase
Expenses:Broker:Commissions $19.95
Assets:Broker 50 AAPL {$30.00} [2004/05/01] (<TransactionId>) @ $30.00
Assets:Broker $-1,519.95

If you use this fully elaborated lot specification everywhere, then you'll
always know what Ledger is based its numbers on. Generally when I sell a
commodity I just copy the details from the opening transaction.

John

o1bigtenor

unread,
May 8, 2020, 8:04:29 AM5/8/20
to Joel Swanson, Ledger
A semantical question - - - - AIUI what you are referring to in the above is a
'stock' not a 'commodity' - - - yes?

Regards

John Wiegley

unread,
May 8, 2020, 8:18:17 PM5/8/20
to o1bigtenor, Joel Swanson, Ledger
>>>>> "o" == o1bigtenor <o1big...@gmail.com> writes:

o> A semantical question - - - - AIUI what you are referring to in the above
o> is a 'stock' not a 'commodity' - - - yes?

I guess I'm mixing Ledger terminology with market terminology. To Ledger,
everything is a commodity. But yes, in this particular case, the item we're
tracking is a stock.

John

o1bigtenor

unread,
May 9, 2020, 6:46:38 AM5/9/20
to o1bigtenor, Joel Swanson, Ledger
Interesting - - - thanks.

Joel

unread,
May 9, 2020, 10:19:27 AM5/9/20
to Ledger
Thanks, John. That helps my understanding.

o1bigtenor

unread,
May 9, 2020, 11:05:08 AM5/9/20
to Ledger, Joel Swanson
Mr John

Have been thinking about this <Transactionid> and where you have
placed it in the
layout of the transaction. To me this is not too dissimilar to
'different' currency
transactions (items are purchased in a different than 'home' currency)
when I want
to track the costs of and in the transaction. I usually put the
various 'rates' in the
'notes' files ( right after the payee line then the next line using
the ; rate 234.15).

The example here you are putting the <Transactionid> inside the
transaction information.
Would you also use this technique in a currency exchange transaction
(transaction done
in a different currency than the ledger's 'base currency)?

Regards

John Wiegley

unread,
May 9, 2020, 4:48:27 PM5/9/20
to o1bigtenor, Ledger, Joel Swanson
>>>>> "o" == o1bigtenor <o1big...@gmail.com> writes:

o> The example here you are putting the <Transactionid> inside the transaction
o> information. Would you also use this technique in a currency exchange
o> transaction (transaction done in a different currency than the ledger's
o> 'base currency)?

Sure. I also use the "lot note" to track wash sale adjustments to the cost
basis, and when I want to (personally) track a an option rollover, since to me
it's the continuation of an ongoing position but to my broker it's not. So I
might have:

(387437466,W$128.99/364736412)

I.e., this lot was opened in transaction 387437466, but its cost basis was
adjusted due to a wash sale in transaction 364736412.

Since the contents of the lot note are entirely free form, you can afterwards
process this to create your own "audit trail" of a particular instrument,
without having to use a specially named account or anything.

John

o1bigtenor

unread,
May 9, 2020, 6:39:03 PM5/9/20
to o1bigtenor, Ledger, Joel Swanson
Thanks - - - - the flexibility here is awesome.

Keep on keeping on!
Reply all
Reply to author
Forward
0 new messages