Need some help on lot date and lot price

71 views
Skip to first unread message

Lanrete Li

unread,
Jul 5, 2023, 2:52:57 AM7/5/23
to Ledger
Background
I don't have a finance/accouting background and therefore not very familiar with the concept of lot date and lot price.

I use ledger for personal finance so I don't need it to 100% follow accouting guidance, I don't use ledger to track my taxes neither.

Scenario
I'm using ledger to track my investment in ETF funds, let's say I bought 100 of certain ETF at 1.3 each at July-1st, I would have a (simplified) transaction as below:

2023/07/01 * Buy ETF
  Assets:Bank          -130 USD
  Assets:Fund:xxxx     100 "FD_xxxx" @@ 130 USD

In my understanding, this will create an internal commodity record that says
"FD_xxxx" = 1.3 USD at 07/01

I also manage a price db to track fund prices at each day, so that file contain info like below
P 2023/07/02 "FD_xxxx"  1.32 USD
P 2023/07/03 "FD_xxxx"  1.33 USD
P 2023/07/04 "FD_xxxx"  1.35 USD 

Let's say I sold all the fund using the price of Jul-4th, and the money will be in my account at July-5th, currently I'm recording it as below:

2023/07/04 * Sell FUND
  Assets:Bank       135 USD
  Assets:Fund:xxxx  -100 "FD_xxxx" @ 1.35 USD

I'm not exactly happy with this because
  1. My bank account actually get the money at 5th not 4th
  2. I still need to manually input the fund price even if I have a price db file
For (1) -> I assume we can use lot date to fix this? Basically I want to record a transaction that says I sold xx amount of YYY at date A, using the price of this commodity/currency at date B

For (2) -> I tried not entering the [@ 1.35 USD] at the end, ledger won't complain, but my balance report is mixed up with different commoditties.

Lastly, I sw some one will record the "incremental gain" as `Income:CapitalGain` when selling the fund, for example, in the official document there is:

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

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

It seems to me that the later transaction can be just written as 

2005/08/01 Stock sale 
  Assets:Broker                -50 AAPL @ $50.00 
  Expenses:Broker:Commissions  $19.95 
  Assets:Broker                $2,480.05

Both ledger will balance, which one SHOULD i follow? what if my 50 share of AAPL is purchased at different date and therefore different price?

Martin Michlmayr

unread,
Jul 5, 2023, 3:07:20 AM7/5/23
to ledge...@googlegroups.com
* Lanrete Li <jeo...@gmail.com> [2023-07-04 23:52]:
> 2023/07/01 * Buy ETF
> Assets:Bank -130 USD
> Assets:Fund:xxxx 100 "FD_xxxx" @@ 130 USD
>
> In my understanding, this will create an internal commodity record that says
> "FD_xxxx" = 1.3 USD at 07/01

You can run "ledger bal --lots" to see the lot information.

> I'm not exactly happy with this because

Unfortunately, afaik you have to do it manually at the moment because
ledger has no built-in mechanism to do it for you.

> Lastly, I sw some one will record the "incremental gain" as
> `Income:CapitalGain` when selling the fund, for example, in the official
> document there is:
>
> 2004/05/01 Stock purchase
> Assets:Broker 50 AAPL @ $30.00
> Expenses:Broker:Commissions $19.95
> Assets:Broker $-1,519.95
>
> 2005/08/01 Stock sale
> Assets:Broker -50 AAPL {$30.00} @ $50.00
> Expenses:Broker:Commissions $19.95
> Income:Capital Gains $-1,000.00
> Assets:Broker $2,480.05

Yes, this is correct. Actually, it's slightly incorrect because you
also have to give the date:

2005/08/01 Stock sale
Assets:Broker -50 AAPL {$30.00} [2004/05/01] @ $50.00
Expenses:Broker:Commissions $19.95
Income:Capital Gains $-1,000.00
Assets:Broker $2,480.05

> It seems to me that the later transaction can be just written as
>
> 2005/08/01 Stock sale
> Assets:Broker -50 AAPL @ $50.00
> Expenses:Broker:Commissions $19.95
> Assets:Broker $2,480.05

> Both ledger will balance, which one SHOULD i follow?

The correct one. You have to specify {} @ manually. Only
this way ledger knows what you're talking about exactly.

Run "bal --lots" - if the lots are red, you have a problem.

> what if my 50 share of AAPL is purchased at different date and
> therefore different price?

You can do something like this:

Assets:Broker -25 AAPL {$25.00} [2003/03/02] @ $50.00
Assets:Broker -25 AAPL {$30.00} [2004/05/01] @ $50.00

Unfortunately, all of this is quite a manual process.

Basically: run "ledger bal --lots assets:Broker", copy&paste the info,
afterwards run "bal --lots assets:broker" again and make sure nothing
is red.

If something is red, it means you removed a lot that doesn't exist.
This can be because you forgot to write the date (as in the example
above).

--
Martin Michlmayr
https://www.cyrius.com/

Lanrete Li

unread,
Jul 5, 2023, 5:08:38 AM7/5/23
to ledge...@googlegroups.com
Thanks Martin! This is very helpful, I will definitaley check out the --lots options.


--

---
You received this message because you are subscribed to the Google Groups "Ledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ledger-cli+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ledger-cli/20230705070712.GF470632%40jirafa.cyrius.com.
Reply all
Reply to author
Forward
0 new messages