hledger
Safe HaskellNone
LanguageGHC2021

Hledger.Cli.Xirr

Description

Calculation of the internal rate of return of some dated cash flows, shared by the roi and holdings commands.

Synopsis

Documentation

data IrrError Source #

Why an internal rate of return could not be computed.

Constructors

IrrNothingPutIn

money only came out (or is still in at the end), and none was put in: the rate is infinite

IrrAllOnOneDay Day

all the cash flows fall on this day, so no time passes, but they don't add up to zero

IrrNotBracketed

no solution between -100% and the largest rate searched (1000000%)

IrrSearchFailed

the search for a solution did not converge

Instances

Instances details
Eq IrrError Source # 
Instance details

Defined in Hledger.Cli.Xirr

Methods

(==) :: IrrError -> IrrError -> Bool

(/=) :: IrrError -> IrrError -> Bool

Show IrrError Source # 
Instance details

Defined in Hledger.Cli.Xirr

Methods

showsPrec :: Int -> IrrError -> ShowS

show :: IrrError -> String

showList :: [IrrError] -> ShowS

xirr :: Day -> [(Day, Quantity)] -> Either IrrError Double Source #

The annualised internal rate of return of some dated cash flows, as a percentage, like Excel's XIRR. What is put in is negative; what is taken out, or is still held at the end, is positive. Each flow is compounded from its date to the reference day (usually the date of the last one).

Some cases have no solution, or one the search can't find:

  • no cash flows: 0%
  • money is put in, but nothing comes out or is left: -100% (all of it was lost)
  • money comes out or is left, but nothing is put in: an infinite rate, so an error
  • all on one day: 0% if they add up to zero (nothing was gained or lost), otherwise an error, as no time passes for the gain or loss to happen in.

So on one day, a total loss is -100% but a partial loss is an error. That's because a total loss solves (1+r)^t = 0, which gives -100% however long the money was in. A partial loss (eg (1+r)^t = 0.5) depends on t, and has no solution when no time passes. (Also, cash flows which net to zero are not passed in, so a total loss's date is not known here.)