Another quick little post in this series.

File setup

I have five files:

  1. .ledger - the main file which contains the transactions I download from my bank.
  2. .ledgerrc - which contains command line options/settings I always want applied.
  3. .ledger_pending - transactions I’ve made that haven’t reached the bank yet, like cheques; yes, those are still used in the countryside.
  4. .ledger_planned - my forecast transactions for the next month
  5. .ledger_accounts - so I can use the --strict option with ledger and (somewhat) avoid problems with typos in account/category names

The main .ledger file includes all the others; the position in the file where these includes occur is important as I’ll explain.

Transactions

I put all my transactions in a .ledger file. The good thing about this file is that Ledger will automatically pick it up which saves you a -f /path/to/ledgerfile on the command line. I use my own tool to download transactions from my bank that gets everything in the correct layout, etc so I can just copy and paste these at (just above) the bottom of my .ledger file and fill in the missing expense categories. I’m happy with manually assigning expense categories: In PocketSmith I automated some of these through filters I’d defined (the completely automatic/suggested transactions never worked out that well for me); I could look to build my own tool to categorise certain things, but, to be honest, generally it’s best to do this manually and get things right (Not all transaction/merchant names are always the same category anyway).

For the very last transaction I have my download tool format it to use a balance assertion with the current account balance. I used to just have my download tool include this at the bottom of the transactions as a comment and then I’d manually check the output of the register report matched the bank account balance for today. However, it makes sense to have Ledger do this for me.

Settings

In .ledgerrc I have just two options, so far, that I always want to be applied:

--date-format=%Y-%m-%d
--strict

The default date format was throwing me all the time, I thought every day was the 15th! Strict is used as said above to warn me of typos in categories just in case I decide to start using balance reports at some point in addition to forecasting. Since this file only relates to settings it is included at the top of the main .ledger file.

Pending transactions

I keep pending transactions in .ledger_pending. These are any transactions I’ve made, but aren’t yet showing up in the bank. In PocketSmith I had a manual account in addition to the main account that pulled in automatic transactions so this set-up isn’t really much different. I flag these transactions with !, but I’ve yet to really utilise this flag/state in any of the Ledger reports. I keep pending transaction dates in the future (manually adjusting them each time I run a report if necessary) so that I can have Ledger’s today’s balance match my bank’s.

I used to include this at the top of .ledger as well, but now include it at the bottom so I can get balance assertion to work.

Planned transactions

Planned transactions in .ledger_planned are how I get forecasting to work. I forecast until the end of the month only. I would, one day, love to get to the position where I don’t have to do this because I’m not living pay cheque to pay cheque, but that is just how life is at the moment and there is nothing I can do about it. These are just normal Ledger transactions (not Ledger periodic transactions) that I try to group by date for the next month. E.g I have these transactions grouped together on the 10th of the month as that is when I expect them to come out:

2015/07/10	!	Planned monthly - Heating, Car insurance, Netflix
	Expenses:Subscriptions:Netflix	£5.99
	;Expenses:Bills:Internet	£25
	Expenses:Heating:Oil	£50
	;Expenses:Heating:Coal	£90
	Expenses:Car:Insurance	£42.81
	Assets:Smile:Current

I have split this file up by yearly, monthly and weekly transactions. Although grouped by similar date, I can comment out individual ones, or comment out the whole lot when they’ve occurred. For my planned transactions it makes sense to group as many as possible by similar dates as there are less dates to change in the roll over to the next month (payday). Resetting this file each month will be a bit tedious and annoying (and probably error prone) compared to PocketSmith which makes this an absolute breeze.

Like .ledger_pending I used to include this at the top of .ledger as well, but now include it at the bottom so I can get balance assertion to work.

A note on the oil price: It is never normally anywhere near this cheap. All in all we pay an absolute fortune to stay moderately cold all year round. If you are ever in the position where you have a choice, don’t live in a property that requires coal and heating oil.

Idiosyncrasies of Ledger

In deciding to use balance assertions I found that you have to have the transactions in date order. As I said, previously I had all my includes (such as pending and planned transactions) at the top of the main file as that seemed tidier and also meant I pasted new transactions right at the bottom of the file instead of, now, a couple of lines above the includes at the bottom; Having transactions in any order didn’t matter before I used balance assertions because I used the --sort date option in the register report to get everything, including running balances, displayed correctly.

When I moved the includes to the bottom, I then suddenly found that the --strict option triggered loads of warnings for “Unknown commodity ‘£’”. I didn’t understand why I was suddenly seeing this now just because I’d moved the position of the include, but searched and found that you could pre-define commodities as per accounts. So I added commodity '£' to the top of my .ledger_accounts file. But still the warnings persisted; This seems like an actual bug to me. After more searching I found that --strict will (only) warn for transactions that aren’t pre-declared, but that flagging a transaction as cleared or pending automatically pre-declares things like commodities. So because I’d included my pending and planned transactions at the top of the file and marked these as pending this pre-declared the commodity. Moving these includes to the bottom meant that I was left with my normal transactions, which I had not bothered to mark as cleared (note to self: for completeness I should fix my transaction download tool to do this), hence all the warnings.

So, as a work-around I made sure the very first transaction, the opening balance, in .ledger is flagged as a cleared transaction with a *; I’ve since modified my download tool to set everything as a cleared transaction so I can use a balance report on cleared transactions only.

Commands I use

Just the one so far:

ledger --sort date reg ^assets ^liabilities

I still have --sort date to sort the planned and pending transactions correctly since, as I’ve said, the planned ones are grouped in the file by yearly, monthly, weekly. I’m using no date range as of yet, but at some point I’ll have to figure out not having to page through all the transactions to get to the bottom to see how my forecast is looking.


[EDIT: 2015-07-22] Updated quite a bit. Including notes on general settings and balance assertions. When I first published this post I was still keeping PocketSmith running as well, but I’m happy enough with my Ledger setup that I’ve now switched permanently from PocketSmith - being able to check finances easily on my old laptop is ace.

[EDIT: 2015-07-23] Hmm, the bit above where I say I should start doing all my transactions as cleared (asterisked): I’ve realised that if I do that I need to use the --explicit option with --strict to get Ledger to check the categories for these cleared transactions. Of course, this also means it will check the pending (exclamation marked) transactions in my pending and planned files, which I don’t really care about. So perhaps I should just go back to not flagging any of my actual bank transactions (apart from the first opening balance one because of the commodity issue) and then I can just use --strict?

[EDIT: 2015-10-16] I’ve refined my reports down to this register one for forecasting: ledger --sort date reg Current and this one for checking where the money has gone since a given date: ledger --invert --begin YYYY-MM-DD --cleared -S T bal ^income ^expenses. The register one is for my “Current” account only as that way any savings (which are transferred and remain assets) aren’t included in the forecast as otherwise they’d just get spent. The balance report I invert so it matches the register report and it’s for cleared transactions only so my forecasting doesn’t get mixed in. This balance report is a great way of seeing where everything has gone.