2. 2 . 1
Self-Introduction
Tobias Pfeiffer, Software Engineer @ PFN
Joined PFI in April 2014, moved to PFN in October 2014
Recently worked on: Stream
processing engine, CES demo
Hobbies
Last year: Wedding planning →
Also: Cooking
3. 2 . 2
Today's Topic: Background & Motivation
Not related to work tasks
Not at all an expert or very knowledgeable in the field
(But: Everyone uses money, so needs to manage it.)
Motivation
Household CFO
Until now: LibreOffice & various spreadsheets
One Problem: LibreOffice
Another problem: Merging data sources
Recently discovered ledgerand gave it a try
5. 3 . 2
Why Accounting?
For companies: usually required by law
(to calculate taxes, inform shareholders etc.)
For private persons/households:
Locate and track: How much do you get (from
where), how much do you have (where), how much
do you spend (how)?
Manage: Pay your bills on time.
Optimize: What can you do to improve the
situation?
Plan: What can you afford and when?
6. 3 . 3
Double-Entry Accounting (複式簿記)
Published in 1494 (Luca Pacioli: Summa de arithmetica)
Concept: Maintain multiple books (”accounts”) and
record every transaction in two books
Cash in Wallet Food expenses
Amount Balance Amount Balance
-750 JPY 2,307 JPY 750 JPY 43,108 JPY
-120 JPY 2,187 JPY 120 JPY 43,228 JPY
Salary Bank account
Amount Balance Amount Balance
-12,345 JPY -246,789 JPY 12,345 JPY 14,679 JPY
7. 3 . 4
Double-Entry Accounting (2)
Notes
In the real world, this is more complex. (Why??)
Observations
The sum of amounts is zero in every transaction.
The sum of balances is zero across all accounts.
Advantages
Location of money is immediately observable.
A lot of “virtual accounts” can be added for fine-
grained reporting.
Invoice date and payment date can be different.
8. 3 . 5
Account Structure
Common structure
Income (収入): where money comes from
Expenses (費用): where money goes to
Assets (資産): where money is
Liabilities (負債): money you owe
Equity (資本?): “the real value of your property”
Examples:
Income»Salary (will get more and more negative)
Expenses»Food (will get more and more positive)
Assets»Cash, Assets»Bank Account
Liabilities»Credit Card
11. 4 . 3
Concept
Maintain a plain text file with your transactions.
(Such a list of transactions is a “ledger”/原簿.)
Plain text: Possible to have it in git, encrypt it, print
it, copy & paste, edit it with scripts, …
Execute ledgeron that file for reporting.
ledgerchecks that everything balances and
computes the numbers for the report.
In particular, ledgeris not a tool to enter
transactions!
12. 4 . 4
Input Format
General format: For example:
date payee
; note
account 1 amount
account 2 amount
2016-02-25 Lawson
; Ham Sandwich
Expenses:Food 325 JPY
Assets:Cash -325 JPY
ledgeralso allows:
One posting without
amount
More than two postings
(must add up to zero)
2016-02-25 Lawson
Expenses:Food 325 JPY
Assets:Cash
2016-02-25 Lawson
Expenses:Food 301 JPY
Expenses:Taxes 24 JPY
Assets:Cash -325 JPY
13. 4 . 5
Balance (残高) Report
ledgercan compute the balance on each account.
Input file: $ ledger balance
(The input file name is passed
with -for the LEDGER_FILE
environment variable.)
2016-02-20 Company
Assets:Bank 123,456 JPY
Income:Salary
2016-02-22 Bank
Assets:Cash 20,000 JPY
Assets:Bank
2016-02-26 Landlord
Expenses:Rent 70,000 JPY
Assets:Bank
2016-02-27 Supermarket
Expenses:Food 2,017 JPY
Assets:Cash
51,439 JPY Assets
33,456 JPY Bank
17,983 JPY Cash
72,017 JPY Expenses
2,017 JPY Food
70,000 JPY Rent
-123,456 JPY Income:Salary
--------------------
0
15. 4 . 7
Other Reports
Some other commands
equity: collapse all transactions into a single one
xml, csv: list transactions in other formats
xact: create a new transaction from a pattern
Some parameters
--period, --begin, --end: date limit
--strict: check that all used entities exist
all commands take a regular expression to filter
accounts
17. 4 . 9
Dealing With Cash
Problem: Tracking all the little cash expenses
One possible solution: Pay as much as possible using
credit card, and treat cash as “Expense”, not “Asset”.
To track an “important” expense, move money from
Expenses:Cash to the target account:
2016-03-02 ATM
Expenses:Cash 10,000 JPY
Assets:Bank
2016-03-05 Expensive Restaurant
Expenses:Eat Out 8,000 JPY
Expenses:Cash
18. 4 . 10
Dealing With Cash (2)
If you do track your cash expenses (collecting receipts
or using some app), at some point target/actual check
(reconciliation) needs to be done.
For checks, balance assertions can be used.
To correct the amount, balance resets can be used.
2016-03-05 Check balance
; ledger run will fail if we don't have 123 JPY
Assets:Cash = 123 JPY
2016-03-06 Correct balance
; take from Expenses:Loss what is required to get to 123 JPY
Assets:Cash = 123 JPY
Expenses:Loss
19. 4 . 11
Delayed Payments
$ ledger balance
$ ledger balance
When paying a purchase with a credit card, the
payment is done later. However, there is a liability
towards the credit card operator:
Later, the liabilities must be paid back:
2016-02-15 Amazon
Expenses:Books 780 JPY
Liabilities:Credit Card
780 JPY Expenses:Books
-780 JPY Liabilities:Credit Card
---------
0
2016-02-15 Amazon
Expenses:Books 780 JPY
Liabilities:Credit Card
2016-03-27 Pay Invoice
Liabilities:Credit Card 780 JPY
Assets:Bank
-780 JPY Assets:Bank
780 JPY Expenses:Books
---------
0
20. 4 . 12
Tracking Reimbursements
$ ledger balance
$ ledger balance
When paying something on behalf of the company, it is
the other way around, the company owes you money:
If you hand in the receipts properly, the money will be
reimbursed next month:
2016-02-17 Taxi
; no bus in inaka
Liabilities:PFN 3,020 JPY
Assets:Cash
-3,020 JPY Assets:Cash
3,020 JPY Liabilities:PFN
-------------
0
2016-02-17 Taxi
Liabilities:PFN 3,020 JPY
Assets:Cash
2016-03-20 PFN
Assets:Bank 126,476 JPY
Liabilities:PFN -3,020 JPY
Income:Salary -123,456 JPY
123,456 JPY Assets
126,476 JPY Bank
-3,020 JPY Cash
-123,456 JPY Income:Salary
-------------
0
22. 4 . 14
Currencies/Commodities
$ ledger balance fridge
$ ledger prices
$ ledger balance -X JPY Bank
A “currency” is just any string. You could also do
inventory tracking using ledger:
Currencies can also be exchanged into one another
with exchange rate computation…
… or manually given:
2016-02-29 Shopping day
Fridge
Supermarket -2 Apples
Konbini -3 Beers
2 Apples
3 Beers Fridge
2016-02-29 ATM @ Europe
Assets:Cash 50 EUR
Assets:Bank -6,258 JPY
2016/02/29 EUR 125.16 JPY
2016-02-29 ATM @ Europe
Assets:Cash 50 EUR @ 125 JPY
Assets:Bank
JPY-6250 Assets:Bank
23. 4 . 15
Stock
$ ledger balance brokerage
$ cat prices.db $ ledger --market --price-db
prices.db balance brokerage
$ ledger --gain --price-db
prices.db balance brokerage
Stocks can also be treated like currencies.
If you maintain a price history, you can find out current
value of your stock.
2015-05-04 Buy Stock
Assets:Brokerage 10 BMW
Assets:Bank -1,067.50 EUR
2015-09-24 Buy Stock
Assets:Brokerage 15 BMW
Assets:Bank -1,135.20 EUR
25 BMW Assets:Brokerage
P 2015/05/04 BMW 106.75 EUR
P 2015/09/24 BMW 75.68 EUR
P 2016/03/04 BMW 82.63 EUR
2,065.75 EUR Assets:Brokerage
-136.95 EUR Assets:Brokerage
24. 4 . 16
Metadata
ledgerallows to attach metadata to transactions,
such as effective dates, IDs, clearing state, and tags.
The meaning of metadata is completely up to the user.
Use the data when querying:
$ ledger --effective balance
$ ledger --pending|--cleared register
$ ledger register tag manga
$ ledger register tag ShipmentDate < [2016-02-20]
2016-02-15=2016-03-27 ! (123-7654) Rakuten
Expenses:Books 780 JPY ; payee: HappyBooks 123
Expenses:Household 2,350 JPY ; payee: MyHousehold
Liabilities:Credit Card
; :OnlineShopping:Manga:
; ShippingMethod: deliver to home address
; ShipmentDate:: [2016-02-16]
25. 4 . 17
Budgeting
Set up a budget and compare it against real expenses.
~ Monthly
Expenses:Eat Out 10,000 JPY
Assets:Cash
2016-02-14 Izakaya
Expenses:Eat Out 3,723 JPY
Assets:Cash
2016-02-28 Medium Restaurant
Expenses:Eat Out 5,182 JPY
Assets:Cash
2016-03-04 Expensive Restaurant
Expenses:Eat Out 12,300 JPY
Assets:Cash
$ ledger --monthly --budget register Expenses
16-Feb-01 - 16-Feb-29 Expenses:Eat Out -1,095 JPY -1,095 JPY
16-Mar-01 - 16-Mar-31 Expenses:Eat Out 2,300 JPY 1,205 JPY
28. 4 . 20
Related Tools
Forks
(Haskell)
(Python)
and more …
Tools to add transactions
native GnuCash import
(or roll your own using the Python API)
hledger
beancount
ledgerhelpers
tools to import CSV
tools to import OFX
30. 4 . 214 . 22
Features Not Presented Today
Automatic transactions
Python integration
Advanced stock valuation
Report formatting
31. 4 . 23
Summary
ledgerhelps you track your money, stock, and
(optionally) apples.
Powerful reporting commands allow to detect
spending patterns and plan for future expenses.
A number of tools help to get data in and out of your
ledgerfiles.