Ledger-cli and reporting stock allocations
Posted: - Modified: | financeUpdate 2018-08-19: fixed report.
W- wanted to know how I get Ledger to report my stock allocations. I have a networth.ledger
that has the following:
N $ = /^Liabilities/ ; $account -1 (Net:0:Cash:$account) 1 (Allocation:Cash:Assets) 1 = /Assets:Checking|Assets:Savings/ and not /USD/ ; $account -1 (Net:0:Cash:$account) 1 (Allocation:Cash:$account) 1 = /Assets:GIC/ ; $account -1 (Allocation:Cash:GIC) 1 (Net:5:Other) 1 = /Assets/ and /RRSP/ ; $account -1 (Net:3:Retirement:$account) 1 = /Bonds/ and not /RRSP/ ; $account -1 (Net:2:Bonds:$account) 1 = /Bonds/ ; $account -1 (Allocation:Bonds) 1 = /Investments/ and /International|TSX|US|VCN/ and not /RRSP/ (Net:1:Stocks:$account) 1 = /Investments/ and /International/ (Allocation:International) 1 = /Investments/ and /TSX|VCN/ (Allocation:TSX) 1 = /Investments/ and /US/ (Allocation:US) 1 = /Business:Bank:Chequing|Business:Bank:Savings|Business:Bank:ING/ ; $account -1 (Net:4:Business:$account) 1 (Allocation:Cash:$account) 1 !include current.ledger apply account Business !include ~/cloud/ledger/business.ledger
It uses the amounts from my regular ledger to set up virtual accounts for easier allocation or net worth reporting. I excluded the USD account because I get Error: Cannot convert a balance with multiple commodities to an amount
even though everything gets correctly converted to $
if I use the command-line option -X $
.
Then I use the following reports, mostly based on the example in the Ledger manual. Allocation excluding cash:
ledger -X $ -V -f /home/sacha/cloud/ledger/networth.ledger --depth=3 bal ^Allocation and not Cash --current --format "\ %-17((depth_spacer)+(partial_account))\ %10(percent(market(display_total), market(parent.total)))\ %16(market(display_total))\n%/"
Allocation including cash:
ledger -X $ -V -f /home/sacha/cloud/ledger/networth.ledger --depth=3 bal ^Allocation --current --format "\ %-17((depth_spacer)+(partial_account))\ %10(percent(market(display_total), market(parent.total)))\ %16(market(display_total))\n%/"
3 comments
Riebenfeld
2018-08-18T23:54:55Zxuxa,
u copy-pasted, but didnt change: (both scripts are same)
"Allocation including cash:" should probabely contain the "-X $" thingie
im kinda thrilled i came across yer blog, you seem like a pretty cool dude!
keep in touch
sachac
2018-08-19T22:15:29ZWhoops, fixed. Thanks, and thanks for reading!
Adam Faryna
2020-09-13T15:18:58ZThanks for the article Sacha, and I love your work related to Emacs, and opensource. I use ledger-cli a lot but I struggle to find any information how to use rapport formatting features like "--format", "--total" etc. Sadly the manual is not verbose on these. Can you recommend any resource where I can find examples and info how to use them?