Feature request: show balance sheets over date range
Introduction
I'm using ledger-cli to model what happens to treasury, federal reserve, and bank balance sheets given certain economic actions.
Here's a small 4 transaction example:
2020-01-01 bank borrows 1000 from fed
bank:assets:reserves:fed 1000
bank:liabilities:loan:fed -1000
;
fed:assets:loans:bank 1000
fed:liabilities:deposits:odhbdi -1000
2020-02-01 bank buys bonds from treasury
bank:assets:bonds 1000
bank:assets:reserves -1000
;
treasury:liabilities:treasury_debt -1000
treasury:assets:reserves 1000
;
fed:liabilities:deposits:odhbdi 1000 ; other deposits held by depository institutions
fed:liabilities:deposits:tga -1000 ; treasury general account
2020-03-01 treasury pays person for road using bank
treasury:assets:reserves -1000
treasury:expenses:road 1000
;
bank:assets:reserves:fed 1000
bank:liabilities:deposits:person -1000
;
person:equity:earnings:road -1000
person:assets:deposits:bank 1000
2020-04-01 bank repays fed loan
bank:liabilities:loan:fed 1000
bank:assets:reserves:fed -1000
;
fed:assets:loans:bank -1000
fed:liabilities:deposits:odhbdi 1000
Displaying the balance sheets over time
I then display the balance sheet after each transaction, with a description of what led to that state.
This requires that I run something like the following (in PowerShell):
Write-Output 'bank borrows 1000 from fed'
ledger -f tmp.ledger balance --end 2020-01-02
Write-Output 'bank buys bonds from treasury'
ledger -f tmp.ledger balance --end 2020-02-02
Write-Output 'treasury pays person for road using bank'
ledger -f tmp.ledger balance --end 2020-03-02
The output looks like this:
Feature request
Instead of doing the above, it would be nice to be able to specify that I want to see the balance sheets at various points in time:
ledger -f tmp.ledger balance-sheets 2020-01-02, 2020-02-02, 2020-03-02
Then ledger could take care of showing a description taken from the transaction as well as the resulting balance sheet.
Maybe also support date ranges:
ledger -f tmp.ledger balance-sheets --start 2020-01-02 --end 2020-03-02
And if no dates are specified, the state after each transaction is shown:
ledger -f tmp.ledger balance-sheets
Potential other uses
Even if folks aren't using ledger-cli in the above (admittedly probably unusual) way, it might be helpful for when folks are debugging transactions.
Here's my workaround using the ledger Python API.
api-balance.py:
import ledger
from core import *
from history_of_balances import *
ls = [xact for xact in ledger.read_journal('tmp.ledger').xacts()]
ledger_ = Ledger()
for transaction in ls:
ledger_.transactions.append(
Transaction(
transaction.date,
transaction.payee,
[Entry(str(post.account), float(post.amount)) for post in transaction.posts()]))
history_of_balances(ledger_)
If I run:
python3 -m api-balance
I get the following (screenshot truncated due to length):
The core and history_of_balances modules are from this library:
https://github.com/dharmatech/minimal_ledger.py