MyNixOS website logo
Description

computes the internal rate of return of an investment.

hledger-irr is a small command-line utility based on Simon Michael's hledger library. Its purpose is to compute the internal rate of return, also known as the effective interest rate, of a given investment. After specifying what account holds the investment, and what account stores the gains (or losses, or fees, or cost), it calculates the hypothetical annualy rate of fixed rate investment that would have provided the exact same cash flow.

As an example, consider the following irregular investment recorded in a file called speculation.ledger. The account “Speculation” holds the investment which could be, for example, a stock. Regularly, we make sure that the value of the account matches the value of the stock, by moving money from or to the account “Rate Gain”. It does not really matter when we adjust the price, as long as it is correct at the end of our reporting period.

2011-01-01 Some wild speculation – I wonder if it pays off
  Speculation   €100.00
  Cash

2011-02-01 More speculation (and adjustment of value)
  Cash         -€10.00
  Rate Gain     -€1.00
  Speculation

2011-03-01 Lets pull out some money (and adjustment of value)
  Cash          €30.00
  Rate Gain     -€3.00
  Speculation

2011-04-01 More speculation (and it lost some money!)
  Cash         -€50.00
  Rate Gain     € 5.00
  Speculation

2011-05-01 Getting some money out (and adjustment of value)
  Speculation  -€44.00
  Rate Gain    -€ 3.00
  Cash

2011-06-01 Emptying the account (after adjusting the value)
  Speculation   -€85.00
  Cash           €90.00
  Rate Gain     -€ 5.00

We can now calculate the rate of return for the whole time or just for parts of it (and be freaked out by the volatility of the investment):

$ hledger-irr -f speculation.ledger -t "Rate Gain" -i Speculation -c
2011/01/01: €-100.00
2011/02/01: €-10.00
2011/03/01: €30.00
2011/04/01: €-50.00
2011/05/01: €47.00
2011/06/01: €90.00
2011/01/01 - 2019/10/06: -100.00%
$ hledger-irr -f speculation.ledger -t "Rate Gain" -i Speculation -e 2011-03-01
2011/01/01 - 2011/03/01: 26.12%
$ hledger-irr -f speculation.ledger -t "Rate Gain" -i Speculation -b 2011-03-01
2011/03/01 - 2019/10/06: -100.00%
$ hledger-irr -f speculation.ledger -t "Rate Gain" -i Speculation --monthly
2011/01/01 - 2011/02/01: 12.49%
2011/02/01 - 2011/03/01: 41.55%
2011/03/01 - 2011/04/01: -51.44%
2011/04/01 - 2011/05/01: 32.24%
2011/05/01 - 2011/06/01: 95.92%

Running the utility with --help gives a brief overview over the available options:

$ hledger-irr --help
Usage: hledger-irr [OPTION...]
  -h          --help                        print this message and exit
  -V          --version                     show version number and exit
  -c          --cashflow                    also show all revant transactions
  -f FILE     --file=FILE                   input ledger file (pass '-' for stdin)
  -i ACCOUNT  --investment-account=ACCOUNT  investment account
  -t ACCOUNT  --interest-account=ACCOUNT    interest/gain/fees/losses account
  -b DATE     --begin=DATE                  calculate interest from this date
  -e DATE     --end=DATE                    calculate interest until this date
  -D          --daily                       calculate interest for each day
  -W          --weekly                      calculate interest for each week
  -M          --monthly                     calculate interest for each month
  -Y          --yearly                      calculate interest for each year

Known bugs and issues:

  • Currenlty, hledger-irr does not cope well with multiple commodities (e.g. Euro and Dollar, or shares).

  • Also, interest or fees that do not pass through the account selected by --investment-account are not taken into consideration.

Metadata

Version

0.1.1.16

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows