twrr.ijs

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

Definitions to calculate the time weighted rate
of return over for a time unit using several methods.
External cash flow:
  cash inflow positive (eg: 100 10)
  cash outflow negative (eg: _10 _12)
Date format: yyyymmdd (eg: 20161231;20160101)
Date is entered as an 8 digit number.
Equations:
NF

Definitions

T twr, twr_M, twrDietz, twrDietz_M, twrDietzDates, twrDietzDates_M, twrDietzProp, twrDietzProp_M

twr (dyad)

Form: tacit
Time weighted rate of return with
no external cash flow over a time unit.

Syntax

(Vb)twr(Ve)
Vb = portfolio value at the start of the time unit including accrued income
Ve = portfoliio value at the end of the time unit including accrued income

Example

   (100)twr(105)
0.05
   (100)twr(110 105 98 90)
0.1 0.05 _0.02 _0.1
   (100 105 110)twr(110)
0.1 0.047619 0
   (100 105 110)twr(110 100)
0.1  0.047619          0
  0 _0.047619 _0.0909091

twr_M (monad)

Form: tacit
Monadic form of twr.
Time weighted rate of return for a time unit with
no external cash flow.
Equation: twr_M(Vb;Ve)

Syntax

 twr_M(Vb;Ve)
 Vb = portfolio value at the start of the time unit including accrued income
 Ve = portfolio value at the end of the time unit including accrued income

Example

   twr_M(100;105)
0.05
   twr_M(100;110 105 98 90)
0.1 0.05 _0.02 _0.1
   twr_M(100 105 110 ;110)
0.1 0.047619 0
   twr_M(100 105 110;110 100)
0.1  0.047619          0
  0 _0.047619 _0.0909091

twrDietz (dyad)

Form: tacit
Time weighted rate of return for a time unit with
external cash flow using the Dietz methodology.
This method assumes that the external cash flow is in the
middle of the time unit.
Equation: (Vb;Ve)twrDietz(Ec)

Syntax

(Vb;Ve)twrDietz_d(Ec)
Vb = portfolio value at the start of the time unit including accrued income
Ve = portfolio value at the end of the time unit including accrued income
Ec = external cash flow over the time unit

Example

   (100;105)twrDietz(1)
0.039801
  (100;110)twrDietz(1 _2 3)
0.0792079

twrDietz_M (monad)

Form: tacit
Monadic form of twrDietz.
Time weighted rate of return for a time unit with
external cash flow using the Dietz methodology.
This method assumes that the external cash flow is in the
middle of the time unit.

Syntax

twrDietz_M(Vb;Ve;Ec)
Vb = portfolio value at the start of the time unit unit including accrued income
Ve = portfolio value at the end of the time unit including accrued income
Ec = external cash flow over the time unit

Example

   twrDietz_M(100;105;1)
0.039801
   twrDietz_M(100;110;1 _2 3)
0.0792079

twrDietzDates (dyad)

Form: explicit
Time weighted rate of return for a time unit with
external cash flow using the Dietz modified methodology with dates.
External cash flow:
   cash inflow positive (eg: 100);
   cash outflow negative (eg: _10).
Dates are in format: yyyymmdd eg: 20160101

Syntax

(Vb;VbD;Ve;VeD)twrDietzDates_de(Ec;D)
Vb = portfolio value at the start of the time unit including accrued income
VbD = date for Vb
Ve = portfolio value at the end of the time unit including accrued income
VeD = date of Ve
Ec = external cash flow over the period
D = dates of the Ec

Example

   (1000;20160101;1200;20160630)twrDietzDates(100 12 _50;20160301 20160215 20160201)
0.133407

twrDietzDates_M (monad)

Form: explicit
Monadic form of twrDietzDates
Time weighted rate of return for a period with
external cash flow using the Dietz modified methodology with dates.

External cash flow:cash inflow positive (eg: 100);cash outflow negative (eg: _10).
Dates are in format: yyyymmdd eg: 20160101;20160630;20160215

Syntax

twrDietzDates(Vb;VbD;Ve;VeD;Ec;D)
Vb = portfolio value at the start f the time unit including accrued income
VbD = date of Vb: yyyymmdd
Ve = portfolio value at the end of the time unit including accrued income
VeD = date of Ve: yyyymmdd
Ec = external cash flow over the time unit
D = dates of the external cash flow Ec: yyyymmdd as 8 digit numbers

Example

   twrDietzDatesm(1000;20160101;1200;20160630;100 12 _50;20160301 20160215 20160201)
0.133407

twrDietzProp (dyad)

Form: tacit
Time weighted rate of return for a time unit with
external cash flow using the Dietz modified methodology.
The modified methodology weights the external cash flow by the proportion
it is in the time unit.
External cash flow:
   cash inflow positive (eg: 100)
   cash outflow negative (eg: _10)

Syntax

(Vb;Ve)twrDietzProp(Ec;P)
Vb = portfolio value at the start of the time unit including accrued income
Ve = portfolio value at the end of the time unit including accrued income
Ec = external cash flow over the time unit
P  = proportion of the time unit of the Ecf to the end of the tikme unit
P in the range (0,1)

Example

   (1000;1020)twrDietzProp(0;0)
0.02
   (1000;980)twrDietzProp(1;0.5)
_0.0209895

twrDietzProp_M (monad)

Form: tacit
Monadic form of twrDietzProp.
Time weighted rate of return for a time unit with
external cash flow using the Dietz modified methodology.
The modified methodology weights the external cash flow by the proportion
it is in the time unit.
External cash flow:
   cash inflow positive (eg: 100)
   cash outflow negative (eg: _10)

Syntax

twrDietzProp((Vb;Ve;Ec;P)
Vb = portfolio value at the start of the time unit including accrued income
Ve = portfolio value at the end of the time unit including accrued income
Ec = external cash flow over the time unit
P  = proportion of the time unit of the Ecf to the end of the tikme unit
P in the range (0,1)

Example

   twrDietzProp_M(1000;1020;0;0)
0.02
   twrDietzProp_M(1000;980;1;0.5)
_0.0209895
   twrDietzProp_M(1000;1200;20 30 10 _20;0.8 0.7 0.5 0.3)
0.15444