This is a tutorial on how to manage personal finance using ledger. The reader is assumed to have a good knowledge about how to use the command line. The basic idea is that you write down all the transactions in a file named personal.ledger and then use the command line program ledger to generate various kinds of reports.

Double-entry accounting

Ledger follows the double-entry accounting system. In simple terms, it is a journal which tracks the movement of money from debit account to credit account. Let’s assume you are a salaried employee and make 100,000 INR every month. In ledger, a transaction is represented as

2018/01/01 Salary
    Income:Salary                              -100,000 INR
    Account:Savings                             100,000 INR

Here Income:Salary is the debit account and Account:Savings is the credit account. The date at which the transaction took place and a description of the transaction is written in the first line followed by the list of credit or debit entry. Account name could be anything. The : in the account name represents hierarchy. Its use will become more clear when we look at the reports generated by ledger. The sum of the balance of all the accounts must be zero.

~/finance $ ledger -f personal.ledger balance
         100,000 INR  Account:Savings
        -100,000 INR  Income:Salary
--------------------
                   0

We now know enough basics to get started. For simplicity, I am going to just show entries for 3 months.

2018/01/01 Salary
    Income:Salary                              -100,000 INR
    Account:Savings                             100,000 INR

2018/02/01 Salary
    Income:Salary                              -100,000 INR
    Account:Savings                             100,000 INR

2018/03/01 Salary
    Income:Salary                              -100,000 INR
    Account:Savings                             100,000 INR

The total balance in the savings account can be reported by

~/finance $ ledger -f personal.ledger balance Account:Savings
         300,000 INR  Account:Savings

Asset

A person’s net worth is calculated by the formula

Net worth = Assets - Liablities

In a ledger file, each of these assets should be represented by a separate account. Let say 12,000 INR of your salary goes to EPF, we could represent it as follows.

2018/01/01 Salary
    Income:Salary                              -100,000 INR
    Account:Savings                              88,000 INR
    Asset:Debt:EPF                               12,000 INR

2018/02/01 Salary
    Income:Salary                              -100,000 INR
    Account:Savings                              88,000 INR
    Asset:Debt:EPF                               12,000 INR

2018/03/01 Salary
    Income:Salary                              -100,000 INR
    Account:Savings                              88,000 INR
    Asset:Debt:EPF                               12,000 INR

There can be multiple credit entries in a transaction as long as the credit and debit sum up to zero. Let’s say you invest 5,000 INR every month in the PPF account, it could be represented as follows.

2018/01/01 Salary
    Income:Salary                              -100,000 INR
    Account:Savings                              88,000 INR
    Asset:Debt:EPF                               12,000 INR

2018/01/01 Investment
    Account:Savings                              -5,000 INR
    Asset:Debt:PPF                                5,000 INR

2018/02/01 Salary
    Income:Salary                              -100,000 INR
    Account:Savings                              88,000 INR
    Asset:Debt:EPF                               12,000 INR

2018/02/01 Investment
    Account:Savings                              -5,000 INR
    Asset:Debt:PPF                                5,000 INR

2018/03/01 Salary
    Income:Salary                              -100,000 INR
    Account:Savings                              88,000 INR
    Asset:Debt:EPF                               12,000 INR

2018/03/01 Investment
    Account:Savings                              -5,000 INR
    Asset:Debt:PPF                                5,000 INR

The money moves from your savings account to ppf account. Your current net worth could be reported by

~/finance $ ledger -f personal.ledger balance Asset
          51,000 INR  Asset:Debt
          36,000 INR    EPF
          15,000 INR    PPF
--------------------
          51,000 INR

Interest

The interest credited by the bank could be represented as another transaction. If the bank credits the interest at the end of the financial year, it could be represented as

2018/03/31 Interest
    Income:Interest                              -15,000 INR
    Asset:Debt:PPF                                 5,000 INR
    Asset:Debt:EPF                                10,000 INR
~/finance $ ledger -f personal.ledger balance Asset
          66,000 INR  Asset:Debt
          46,000 INR    EPF
          20,000 INR    PPF
--------------------
          66,000 INR

Commodity

Let’s say you are also investing 10,000 INR on UTI Nifty Index Fund and 10,000 INR on ICICI Nifty Next 50 Index Fund every month. Mutual Fund can be considered as a commodity which could be converted to currency.

2018/01/01 Investment
    Account:Savings                              -25,000 INR
    Asset:Debt:PPF                                 5,000 INR
    Asset:Equity:NIFTY          148.0865 NIFTY @ 67.5281 INR
    Asset:Equity:NIFTY_JR    358.6659 NIFTY_JR @ 27.8811 INR

2018/02/01 Investment
    Account:Savings                              -25,000 INR
    Asset:Debt:PPF                                 5,000 INR
    Asset:Equity:NIFTY          140.2870 NIFTY @ 71.2824 INR
    Asset:Equity:NIFTY_JR    363.2242 NIFTY_JR @ 27.5312 INR

2018/03/01 Investment
    Account:Savings                              -25,000 INR
    Asset:Debt:PPF                                 5,000 INR
    Asset:Equity:NIFTY          147.5908 NIFTY @ 67.7549 INR
    Asset:Equity:NIFTY_JR    378.4323 NIFTY_JR @ 26.4248 INR

Let’s consider 148.0865 NIFTY @ 67.5281 INR. Here NIFTY is the name of the commodity and we have bought 148.0865 units at 67.5281 INR per unit.

ledger by default reports the commodity without conversion.

~/finance $ ledger -f personal.ledger balance Asset
          66,000 INR
      435.9643 NIFTY
  1100.3224 NIFTY_JR  Asset
          66,000 INR    Debt
          46,000 INR      EPF
          20,000 INR      PPF
      435.9643 NIFTY
  1100.3224 NIFTY_JR    Equity
      435.9643 NIFTY      NIFTY
  1100.3224 NIFTY_JR      NIFTY_JR
--------------------
          66,000 INR
      435.9643 NIFTY
  1100.3224 NIFTY_JR

To convert the commodity to current market value, we have to supply the current price of the commodity. AMFI publishes the latest NAV values. Save the following text in a file named price.db

P 2018/10/26 00:00:00 NIFTY 65.6193 INR
P 2018/10/26 00:00:00 NIFTY_JR 23.0733 INR
~/finance $ ledger -f personal.ledger --price-db price.db balance --market Asset
         119,996 INR  Asset
          66,000 INR    Debt
          46,000 INR      EPF
          20,000 INR      PPF
          53,996 INR    Equity
          28,608 INR      NIFTY
          25,388 INR      NIFTY_JR
--------------------
         119,996 INR

The same approach could be used for other commodities like gold, stocks etc.

Gain

Gain or loss based on the commodity value in the price.db can be calculated as follows.

~/finance $ ledger -f personal.ledger --price-db price.db balance --gain Asset
          -6,004 INR  Asset:Equity
          -1,392 INR    NIFTY
          -4,612 INR    NIFTY_JR
--------------------
          -6,004 INR

Register

The list of all the transactions related to an account and it’s running total could be reported by the register command.

~/finance $ ledger -f personal.ledger --price-db price.db register --market Asset:Equity
18-Jan-01 Investment   Asset:Equity:NIFTY       10,000 INR  10,000 INR
                       Asset:Equity:NIFTY_JR    10,000 INR  20,000 INR
18-Feb-01              <Revalued>                  430 INR  20,430 INR
18-Feb-01 Investment   Asset:Equity:NIFTY       10,000 INR  30,430 INR
                       Asset:Equity:NIFTY_JR    10,000 INR  40,430 INR
18-Mar-01              <Revalued>               -1,816 INR  38,615 INR
18-Mar-01 Investment   Asset:Equity:NIFTY       10,000 INR  48,615 INR
                       Asset:Equity:NIFTY_JR    10,000 INR  58,615 INR
18-Oct-26              <Revalued>               -4,619 INR  53,996 INR

Allocation

The allocation of money across different assets could be reported as follows.

~/finance $ ledger -f personal.ledger --price-db price.db balance --market --percent Asset
             100.00%  Asset
              55.00%    Debt
              69.70%      EPF
              30.30%      PPF
              45.00%    Equity
              52.98%      NIFTY
              47.02%      NIFTY_JR

This is just the tip of the iceberg. Checkout out the ledger manual for further details.