cfs = [5, 5, 105]
times = [1, 2, 3]
discount_rate = 0.03
present_value(discount_rate, cfs, times) # 105.65
duration(Macaulay(), discount_rate, cfs, times) # 2.86
duration(discount_rate, cfs, times) # 2.78
convexity(discount_rate, cfs, times) # 10.62A collection of common functions/manipulations used in Actuarial Calculations.
duration:- Calculate the
Macaulay,Modified, orDV01durations for a set of cashflows
- Calculate the
convexityfor price sensitivity- Flexible interest rate options via the
Yields.jlpackage. internal_rate_of_returnorirrto calculate the IRR given cashflows (including at timepoints like Excel'sXIRR)breakevento calculate the breakeven time for a set of cashflowsaccum_offsetto calculate accumulations like survivorship from a mortality vector
eurocallandeuroputfor Black-Scholes option prices
- Calculate risk measures for a given vector of risks:
CTEfor the Conditiona Tail Expectation, orVaRfor the percentile/Value at Risk.
duration:- Calculate the duration given an issue date and date (a.k.a. policy duration)
- functions which return a rate/yield will return a
Yields.Rateobject. E.g.irr(cashflows)will return aRate(0.05,Periodic(1))instead of just a0.05(float64) to convey the compounding frequency. This uses (and is fully compatible with) Yields.jl and can be used anywhere you would otherwise use a simple floating point rate.
A couple of other notes:
rate(...)will return the untyped rate from aYields.Ratestruct:
julia> r = Yields.Rate(0.05,Yields.Periodic(1));
julia> rate(r)
0.05- You can still pass a simple floating point rate to various methods. E.g. these two are the same (the default compounding convention is periodic once per period):
discount(0.05,cashflows)
r = Yields.Rate(0.05,Yields.Periodic(1));
discount(r,cashflows)- convert between rates with:
using Yields
r = Yields.Rate(0.05,Yields.Periodic(1));
convert(Yields.Periodic(2), r) # convert to compounded twice per timestep
convert(Yields.Continuous(2),r) # convert to compounded twice per timestepFor more, see the Yields.jl which provides a rich and flexible API for rates and curves to use.
Full documentation is available here.
See JuliaActuary.org for instructions on running this example.
Functions often use a mix of interest_rates, cashflows, and timepoints. When calling functions, the general order of the arguments is 1) interest rates, 2) cashflows, and 3) timepoints.
