mwrr.ijs

Script: ~addons/finance/finexec/ipm/mwrr.ijs
Contributor: William Szuch
Updated: 2022 6-26
Depend: nil
Definitions: loaded to locale base
Status: done
Script source: mwrr.ijs

Definitions to calculate the money weighted rate of return for a time unit.
Also referred to as the internal rate of return.
External cash flow:
  cash inflow positive (eg: 100 10)
  cash outflow negative (eg: _10 _12)
If a solution exits it is in the range as [ _ 1,_ ] where _ is infinity.
Equations:
NF

Definitions

M mwr, mwrDates, mwrPeriodic

mwr (verb)

Form: explicit
Calculate the money weighted rate of return for a non-periodic
cash flow.
The money weighted rate of return is the effective interest rate for
the time unit of the cash flow.
The money weighted rate of return is calculated for the solution to
the equation that the present value of the cach flow is zero.
(1) constant time units
(2) money weighted rate of return calculated by Newton-Raphson method.
(3) tolerance 1e_6
(4) non periodic cash flow
(5) Maximum iterations 15

Syntax

([I])mwr(C;T)
[I] = optional initial trial value (decimal interest rate)
      default = 0
C  = non-periofic cash flow
     must have at least one change of sign
T = time of the cash flow in time units

Example

 mwr(_1 1;0 1)
0
  mwr(_1 1.5;0 1)
0.5
  mwr(_10 10 5;0 1 1.5)
0.419643
  mwr(_10 10 5 5;0 1 1.5)
┌───────────────────────────────────────┐
│*** cash flow and time do not match ***│
└───────────────────────────────────────┘
  mwr(_10 10 5 5 _5 _5 5);(0 1 1.5 3.5 6 7 8)
0.507807

mwrDates (verb)

Form: explicit
Calculate the money weighted rate of return for a non-periodic
cash flow with dates.
The money weighted rate of return is the effective interest rate for
the time unit of the cash flow.
The money weighted rate of return is calculated for the solution to
the equation that the present value of the cach flow is zero.
(1) constant time unit of one year : assume 365 days
    if the period is less than a year the rate is not annualised
(2) money weighted rate of return calculated by Newton-Raphson method.
(3) tolerance 1e_6
(4) non periodic cash flow
(5) Maximum iterations 15

Syntax

[I]mwrDates(C;D)
[I] = optional initial trial value (decimal interest rate)
      default = 0
C   = cash flow
      must have at least one change of sign
D = dates of the cash flow : yyyymmdd as 8 digit numbers

Example

   mwrDates(1000 20 30 _1100;20140101 20150101 20160101 20170101)

mwrPeriodic (verb)

Form: explicit
Calculate the money weighted rate of return for a time unit
for a periodic cash flow.
The money weighted rate of return is the effective interest rate for
the time unit of the cash flow.
The money weighted rate of return is calculated for the solution to
the equation that the present value of the cach flow is zero.
(1) constant time units
(2) money weighted rate of return calculated by Newton-Raphson method.
(3) tolerance 1e_6
(4) periodical cash flow
(5) Maximum iterations 15

Syntax

([I])mwrPeriodic(C)
[I] = optional initial trial value (decimal rate)
      default = 0
C   = periodic cash flow starting at time unit= 0
      and increasing by uniform steps of one time unit for each cash flow
      must have at least one change of sign

Example

   mwrPeriodic(_1 1.1)
0.1
   mwrPeriodic(_1 2)
1
   mwrPeriodic(_1 0.9)
_0.1
   mwrPeriodic(1 1 _2)
0
   mwrPeriodic(10 10 10 _30)
0
   mwrPeriodic(10 10 10 _40)
0.150911
   mwrPeriodic(_100 10 10 12 12 23 23 23 23 25 30 120)
0.164739
   mwrPeriodic(20 20 10 10 12 12 23 23 23 23 25 30 _250 12)
_2.25588