Ledger-cli and reporting stock allocations

Posted: - Modified: | finance

Update 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%/"
You can comment with Disqus or you can e-mail me at sacha@sachachua.com.