TranslateProject/sources/tech/20180612 Using Ledger for YNAB-like envelope budgeting.md

5.9 KiB
Raw Blame History

Using Ledger for YNAB-like envelope budgeting

Bye bye Elbank

I have to start this post with this: I will not be actively maintaining Elbank anymore, simply because I switched back to Ledger. If someone wants to take over, please contact me!

The main reason for switching is budgeting. While Elbank was a cool experiment, it is not an accounting software, and inherently lacks support for powerful budgeting.

When I started working on Elbank as a replacement for Ledger, I was looking for a reporting tool within Emacs that would fetch bank transactions automatically, so I wouldnt have to enter transactions by hand (this is a seriously tedious task, and I grew tired of doing it after roughly two years, and finally gave up).

Since then, I learned about ledger-autosync and boobank, which I use to sync my bank statements with Ledger (more about that in another post).

YNABs way of budgeting

I only came across YNAB recently. While I wont use their software (being a non-free web application, and, you know… theres no M-x ynab), I think that the principles behind it are really appealing for personal budgeting. I encourage you to read more about it (or grab a copy of the book, its great), but heres the idea.

  1. Budget every euro : Quite simple once you get it. Every single Euro you have should be in a budget envelope. You should assign a job to every Euro you earn (thats called zero-based, envelope system).

  2. Embrace your true expenses : Plan for larger and less frequent expenses, so when a yearly bill arrives, or your car breaks down, youll be covered.

  3. Roll with the punches : Address overspending as it happens by taking money overspent from another envelope. As long as you keep budgeting, youre succeeding.

  4. Age your money : Spend less than you earn, so your money stays in the bank account longer. As you do that, the age of your money will grow, and once you reach the goal of spending money that is at least one month old, you wont worry about that next bill.

Implementation in Ledger

I assume that you are familiar with Ledger, but if not I recommend reading its great introduction and tutorial.

The implementation in Ledger uses plain double-entry accounting. I took most of it from Sacha, with some minor differences.

Budgeting new money

After each income transaction, I budget the new money:

2018-06-12 Employer
 Assets:Bank:Checking 1600.00 EUR
 Income:Salary -1600.00 EUR

2018-06-12 Budget
 [Assets:Budget:Food] 400.00 EUR
 [Assets:Budget:Rent] 600.00 EUR
 [Assets:Budget:Utilities] 600.00 EUR
 [Equity:Budget] -1600.00 EUR

Did you notice the square brackets around the accounts of the budget transaction? Its a feature Ledger calls virtual postings. These postings are not considered real, and wont be present in any report that uses the --real flag. This is exactly what we want, since its a budget allocation and not a “real” transaction. Therefore well use the --real flag for all reports except for our budget report.

Automatically crediting budget accounts when spending money

Next, we need to credit the budget accounts each time we spend money. Ledger has another neat feature called automated transactions for this:

= /Expenses/
 [Assets:Budget:Unbudgeted] -1.0
 [Equity:Budget] 1.0

= /Expenses:Food/
 [Assets:Budget:Food] -1.0
 [Assets:Budget:Unbudgeted] 1.0

= /Expenses:Rent/
 [Assets:Budget:Rent] -1.0
 [Assets:Budget:Unbudgeted] 1.0

= /Expenses:Utilities/
 [Assets:Budget:Utilities] -1.0
 [Assets:Budget:Unbudgeted] 1.0

Every expense is taken out of the Assets:Budget:Unbudgeted account by default.

This forces me to budget properly, as Assets:Budget:Unbudgeted should always be 0 (if it is not the case I immediately know that there is something wrong going on).

All other automatic transactions take money out of the Assets:Budget:Unbudgeted account instead of Equity:Budget account.

A Budget report

This is the final piece of the puzzle. Heres the budget report command:

ledger --empty -S -T -f ledger.dat bal ^assets:budget

If we have the following transactions:

2018/06/12 Groceries store
 Expenses:Food 123.00 EUR
 Assets:Bank:Checking

2018/06/12 Landlord
 Expenses:Rent 600.00 EUR
 Assets:Bank:Checking

2018/06/12 Internet provider
 Expenses:Utilities:Internet 40.00 EUR
 Assets:Bank:Checking

Heres what the report looks like:

 837.00 EUR Assets:Budget
 560.00 EUR Utilities
 277.00 EUR Food
 0 Rent
 0 Unbudgeted
--------------------
 837.00 EUR

Conclusion

Ledger is amazingly powerful, and provides a great framework for YNAB-like budgeting. In a future post Ill explain how I automatically import my bank transactions using a mix of ledger-autosync and weboob.


via: https://emacs.cafe/ledger/emacs/ynab/budgeting/2018/06/12/elbank-ynab.html

作者:Nicolas Petton 选题:lujun9972 译者:译者ID 校对:校对者ID

本文由 LCTT 原创编译,Linux中国 荣誉推出