On Fri 27 Mar 2020 at 15:16, Sam Tetruashvili <[email protected]> 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

-- 

--- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ledger-cli/87369szegk.fsf%40gmail.com.

Reply via email to