make_rtn {fcl}R Documentation

Create a Return Object

Description

By providing a "group" (ids) of dates, mvs and pls, calucating the Time-weighted Rate of Return (TWRR) or Modified Dietz Rate of Return (DIETZ).

Usage

make_rtn(date, mv, pl, id = 1L)

Arguments

date

a Date vector, the reference date of each row

mv, pl

a double vector, the market value and the 'PnL' (Profit and Loss) of each day

id

an integer vector, the ID of each row belongs to

Value

A list of functions, with signature of from, to and id, all of which are only allowed to accept a scalar. They all return an xts object with one column.

Cash flow handling

Note

All the input vector must be 1 or the same length.

References

Modified Dietz Method: https://en.wikipedia.org/wiki/Modified_Dietz_method

Time weighed Return: https://en.wikipedia.org/wiki/Time-weighted_return

Examples

rtn <- make_rtn(date = c(210101, 210105, 210110), mv = c(100, 123, 140), pl = c(0, 3, 7))
rtn$twrr_cr(210102, 210110)
rtn$twrr_dr(210102, 210110)
rtn$dietz(210102, 210110)
rtn$dietz_avc(210102, 210110)

[Package fcl version 0.1.0 Index]