atoti.experimental.finance package¶
Module contents¶
Warning
Experimental features are subject to breaking changes (even removals) in minor and/or patch releases.
Financial functions.
- atoti.experimental.finance.irr(*, cash_flows, market_value, date, precision=0.001)¶
Return the Internal Rate of Return based on the underlying cash flows and market values.
The IRR is the rate
r
that nullifies the Net Present Value:\[\begin{split}NPV = \\sum_{i=0}^{T} CF_i (1 + r)^{\\frac{T - t_i}{T}} = 0\end{split}\]With:
\(T\) the total number of days since the beginning
\(t_i\) the number of days since the beginning for date i
\(CF_i\) the enhanced cashflow for date i:
CF of the first day is the opposite of the market value for this day: \(CF_0 = - MV_0\).
CF of the last day is increased by the market value for this day: \(CF_T = cash\\_flow_T + MV_T\).
Otherwise CF is the input cash flow: \(CF_i = cash\\_flow_i\).
This equation is solved using the Newton’s method.
- Parameters
cash_flows (
MeasureDescription
) – The measure representing the cash flows.market_value (
MeasureDescription
) – The measure representing the market value, used to enhanced the cashflows first and last value. If the cash flows don’t need to be enhanced then0
can be used.date (
Hierarchy
) – The date hierarchy. It must have a single date level.precision (
float
) – The precision of the IRR value.
See also
The IRR Wikipedia page.
Example
With the following data:
Date
MarketValue
CashFlows
2020-01-01
1042749.90
2020-01-02
1099720.01
2020-01-03
1131220.24
2020-01-04
1130904.32
2020-01-05
1748358.77
-582786.257893061
2020-01-06
1791552.54
The IRR can be defined like this:
m["irr"] = irr(cash_flows=m["CashFlow.SUM"], market_value=m["MarketValue.SUM"], date=h["Date"]) cube.query(m["irr"]) >>> 0.14397
- Return type