Net worth over time

307 views
Skip to first unread message

Alex Branham

unread,
Mar 26, 2020, 5:04:39 PM3/26/20
to ledge...@googlegroups.com
Hi all -

I'd like to track my net worth (assets minus liabilities) over time. I
can get close to what I want with:

ledger -f finances.ledger reg assets liabilities --exchange $ -D

But that prints a line in each day for every account that had a
transaction (e.g. checking +100, credit card -100, etc). Is there a way
to tell ledger I don't care about the accounts, just print the total?

Thanks!
Alex

John Wiegley

unread,
Mar 26, 2020, 6:04:13 PM3/26/20
to Alex Branham, ledge...@googlegroups.com
>>>>> "AB" == Alex Branham <alex.b...@gmail.com> writes:

AB> ledger -f finances.ledger reg assets liabilities --exchange $ -D

AB> But that prints a line in each day for every account that had a
AB> transaction (e.g. checking +100, credit card -100, etc). Is there a way to
AB> tell ledger I don't care about the accounts, just print the total?

You could use:

ledger -f finances.ledger bal assets liabilities --exchange $ -D

Or

ledger -f finances.ledger reg assets liabilities --exchange $ -D --yearly

John

Sam Tetruashvili

unread,
Mar 26, 2020, 6:08:57 PM3/26/20
to ledge...@googlegroups.com, Alex Branham
Neither of these end up returning a table mapping calendar dates to net worth.

--

---
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/m2zhc2bwod.fsf%40newartisans.com.

Alex Branham

unread,
Mar 26, 2020, 6:38:38 PM3/26/20
to Sam Tetruashvili, ledge...@googlegroups.com
On Thu 26 Mar 2020 at 18:08, Sam Tetruashvili <sa...@alumni.cmu.edu> wrote:

> Neither of these end up returning a table mapping calendar dates to net
> worth.

Right, those aren't quite right. What I'm hoping for looks something
like:

2020-03-24 $-20.00 $ 40.00
2020-03-25 $ 20.00 $ 60.00
2020-03-26 $-10.00 $ 50.00
2020-03-27 $-40.00 $ 10.00

Thanks,
Alex

John Wiegley

unread,
Mar 26, 2020, 6:53:55 PM3/26/20
to Sam Tetruashvili, ledge...@googlegroups.com, Alex Branham
>>>>> "ST" == Sam Tetruashvili <sa...@alumni.cmu.edu> writes:

ST> Neither of these end up returning a table mapping calendar dates to net
ST> worth.

You never mentioned needing that. :)

Can you show me an example of what you wanted to see, using fake numbers and
account names?

John

Sam Tetruashvili

unread,
Mar 26, 2020, 7:03:20 PM3/26/20
to ledge...@googlegroups.com, Sam Tetruashvili, Alex Branham
No worries. I guess we interpreted Alex's initial question different.

Consider the following simple ledger file.

2020/03/01 Paycheck
    Assets:Bank      $ 100.00
    Income:Salary   -$ 100.00

2020/03/02 Lunch
    Expenses:Food    $ 20.00
    Assets:Bank     -$ 20.00

2020/03/03 Lunch
    Expenses:Food    $ 20.00
    Assets:Bank     -$ 20.00
   
I believe Alex wants to produce the following output:

Date         Net Worth
2020/03/01   $ 100.00
2020/03/02    $ 80.00
2020/03/03    $ 60.00

When I had to do something like this in the past I had to make a python script that runs the balance command once per calendar date. If there is an easier way to do this with a single ledger command it would be very useful to me (and probably to Alex).

--

---
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.

John Wiegley

unread,
Mar 27, 2020, 3:05:48 PM3/27/20
to Sam Tetruashvili, ledge...@googlegroups.com, Alex Branham
>>>>> "ST" == Sam Tetruashvili <sa...@alumni.cmu.edu> writes:

ST> I believe Alex wants to produce the following output:
ST> Date         Net Worth
ST> 2020/03/01   $ 100.00
ST> 2020/03/02    $ 80.00
ST> 2020/03/03    $ 60.00

This is produced by the following:

ledger -f foo.dat reg assets liabilities --daily -n -F '%(date) %12(total)\n'

John

Sam Tetruashvili

unread,
Mar 27, 2020, 3:17:15 PM3/27/20
to Sam Tetruashvili, ledge...@googlegroups.com, Alex Branham
Thank you so much John! For my larger ledger file with more than 1 commodity I found it useful to modify your suggestion as follows

ledger -f foo.dat reg assets liabilities --daily -V -n -F '%(date) %12(T)\n'

For posterity, the -n flag (aka --collapse) is the part of John answer that causes the total value of all account to be aggregated. The --daily flag set the period of aggregation to a single calendar day.

Alex Branham

unread,
Mar 28, 2020, 11:28:16 AM3/28/20
to Sam Tetruashvili, ledge...@googlegroups.com
On Fri 27 Mar 2020 at 15:16, Sam Tetruashvili <sa...@alumni.cmu.edu> wrote:

> Thank you so much John! For my larger ledger file with more than 1
> commodity I found it useful to modify your suggestion as follows
>
> ledger -f foo.dat reg assets liabilities --daily -V -n -F '%(date)
> %12(T)\n'

Thanks, this is very helpful. I still get multiple lines on some days
for reasons I don't quite understand. The account associated with it is
<Total>, which I don't think I've seen before.

Anyway, here's a small R program that takes the output and makes a graph
of net worth by day. Might need some tweaking if you run it on your own
machine (e.g. adding "-f /path/to/finances.ledger")

#+begin_src R
library(ggplot2)
library(data.table)

ledger_args <- list("-f finances.ledger", "register",
"--limit 'account=~/assets/' or 'account=~/liabilities/'",
"--exchange $", "-D", "--collapse")

lines <- system2("ledger", ledger_args, stdout = TRUE)

date <- as.Date(substr(lines, 1, 10))
net_worth <- unlist(lapply(strsplit(lines, "\\$"), function(x) x[3]))
net_worth <- as.numeric(gsub(",", "", net_worth))

dat <- data.table(
date = date,
net_worth = net_worth
)
dat[, date := date[1], .(cumsum(!is.na(date)))]
## Select last observation when there are multiple on the same day
dat[, .SD[unique(c(1, .N))], date]

ggplot(dat[date < Sys.Date()], aes(date, net_worth)) +
geom_line() +
xlab("Date") +
ylab("Net Worth") +
theme_minimal()
#+end_src
Reply all
Reply to author
Forward
0 new messages