Computes Duration and Modified Duration for cash flows with different cash flow and compounding conventions. Cash flows need not be evenly spaced.
duration(
cf,
rate,
cf.freq = 1,
comp.freq = 1,
cf.t = seq(from = ifelse(immediate.start, 0, 1/cf.freq), by = 1/cf.freq, along.with =
cf),
immediate.start = FALSE,
modified = FALSE
)
Vector of cash flows
The interest rate in decimal (0.10 or 10e-2 for 10%)
Frequency of annuity payments: 1 for annual, 2 for semi-annual, 12 for monthly.
Frequency of compounding of interest rates: 1 for annual, 2 for semi-annual, 12 for monthly, Inf for continuous compounding.
Optional vector of timing (in years) of cash flows. If omitted regular sequence of years is assumed.
Logical variable which is TRUE
when the first cash
flows is at the beginning of the first period (for example, immediate
annuities) and FALSE
when the first cash flows is at the end of the first
period (for example, deferred annuities)
in function duration, TRUE
if modified
duration is desired. FALSE
otherwise.