Any way to get maximum balance and date for account?

44 views
Skip to first unread message

lipp f

unread,
Feb 3, 2024, 11:03:05 AMFeb 3
to Ledger
TIA.

Tavis Ormandy

unread,
Feb 3, 2024, 3:33:05 PMFeb 3
to ledge...@googlegroups.com
On 2024-02-03, lipp f wrote:
> TIA.
>

Are you only interested in cases that a /transaction/ causes the maximum
balance to be reached (e.g. you deposited some cash)?

Maybe something like this?

$ ledger reg -JVd 'd > [2023] & d < [2024]' ^Assets:Checking \
| sort -g -k2 \
| tail -1

I think you need the display filter, because --period would set the
starting balance to 0.

I guess you could do --sort 'account.value(d)' or something, but that
would be kinda slow.

If you also care about the case where the market value of a commodity
increases, then I guess the answer is similar, but you need something
like `--daily` or `--weekly`.

I dunno, maybe someone else has a cleaner solution :)

Tavis.

--
_o) $ lynx lock.cmpxchg8b.com
/\\ _o) _o) $ finger tav...@sdf.org
_\_V _( ) _( ) @taviso

lipp f

unread,
Feb 3, 2024, 4:51:40 PMFeb 3
to Ledger
For tax purposes, I need maximum balance of an investment account during the tax year. reg -J sorted doesn't actually give me that. When using reg, it needs to do a cumulative sum, on top of the initial balance.

Tavis Ormandy

unread,
Feb 3, 2024, 5:40:25 PMFeb 3
to ledge...@googlegroups.com
On 2024-02-03, lipp f wrote:
> For tax purposes, I need maximum balance of an investment account during
> the tax year. reg -J sorted doesn't actually give me that. When using reg,
> it needs to do a cumulative sum, on top of the initial balance.

Hmm, pretty sure the solution provided does literally that?

Breaking it down...

> -d 'd >= [2023] & d < [2024]'
This is a display filter, which means transactions are included in
totals even if they're not displayed.

You need this to calculate the correct initial balance.

> -V
This just means you want the market value, because you didn't specify if
this was a commodity account or a bank account.

> -J
This only outputs the date and the total, which is all you wanted and is
easier to process.

> sort -g -k2
Now sort that output by running total, so the highest balance you ever
had will be at the end.

> tail -1
Only print the highest balance, and throw the rest away.

If that's not what you're looking for, can you give an example?

Tavis.

lipp f

unread,
Feb 3, 2024, 7:15:50 PMFeb 3
to Ledger
$ ledger reg -J -X CAD -V assets and not external | sort -g -k2 |  tail -1
2021-12-31 1369417.9409144474843847
$ ledger  bal -X CAD -V -e "2022-1-1" assets and not external
1,249,676.858511046923949 CAD
and max balance is actually on Jan 3
$ ledger  bal -X CAD -V -e "2022-1-4" assets and not external
1,280,858.174837954476431 CAD

Tavis Ormandy

unread,
Feb 3, 2024, 9:26:39 PMFeb 3
to ledge...@googlegroups.com
On 2024-02-04, lipp f wrote:
> $ ledger reg -J -X CAD -V assets and not external | sort -g -k2 | tail -1
> 2021-12-31 1369417.9409144474843847
> $ ledger bal -X CAD -V -e "2022-1-1" assets and not external
> 1,249,676.858511046923949 CAD
> and max balance is actually on Jan 3
> $ ledger bal -X CAD -V -e "2022-1-4" assets and not external
> 1,280,858.174837954476431 CAD

Hmm, I think you're saying you think the high balance from -J is wrong?

What do these commands output?

$ ledger bal --depth 1 -X CAD --now "2021-12-31" -V assets and not external
$ ledger bal --depth 1 -X CAD --now "2022-01-03" -V assets and not external

lipp f

unread,
Feb 4, 2024, 8:09:54 AMFeb 4
to Ledger
those outputs won't help you. they are two pages long each, showing all individual securities. this is due to "--now".

Tavis Ormandy

unread,
Feb 4, 2024, 10:32:37 AMFeb 4
to ledge...@googlegroups.com
On 2024-02-04, lipp f wrote:
> those outputs won't help you. they are two pages long each, showing all
> individual securities. this is due to "--now".
>

beats me :)

I was expecting --depth 1 -X CAD to output a single number that matched
the -J output.

Maybe someone else knows what's going on :)

Tavis.

lipp f

unread,
Feb 4, 2024, 1:58:25 PMFeb 4
to Ledger
-e end_date with --depth 1  outputs couple of lines, with a summary number. I have no doubt that the balance for date is calculated correct this way. 
Wondering if reg -J is wrong  or might have a different meaning.

Reply all
Reply to author
Forward
0 new messages