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.
-
twrr_cr
: the cumulative Time-weighted Return -
twrr_dr
: the daily Time-weighted Return -
dietz
: the Modified Dietz Return -
dietz_avc
: the denominator used to calculate the 'Modifie Dietz Return -
cum_pl
: the cumulative PnL
Cash flow handling
The cash flow is not provided externally. Instead, it's deducted via market value and PnL, with the equation
\Delta MV = \Delta PnL + CF
.The cash inflow is treating as if it happens at the beginning of the day, while the cash outflow is at the end of the day. The reasons are two. The first is to reduce the possibility of having a close-to-zero denominator. The second is the cash is usually not usable for the whole day.
The calculation is based on calendar days. No business calendar or weekday considers. You can't change the calculation frequency, either. However, this is possible in the future version.
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)