Utilities submodule
Provides miscellaneous routines common in actuarial and financial work.
API
Exported API
ActuaryUtilities.Utilities.policy_duration — Function
policy_duration(d1::Date, d2::Date)Compute the policy duration given two dates, which is the number of years since the first date. The interval [0,1) is defined as having duration 1. Can return negative durations if second argument is before the first.
julia> issue_date = Date(2018,9,30);
julia> policy_duration(issue_date , Date(2019,9,30) )
2
julia> policy_duration(issue_date , issue_date)
1
julia> policy_duration(issue_date , Date(2018,10,1) )
1
julia> policy_duration(issue_date , Date(2019,10,1) )
2
julia> policy_duration(issue_date , Date(2018,6,30) )
0
julia> policy_duration(Date(2018,9,30),Date(2017,6,30))
-1ActuaryUtilities.Utilities.years_between — Function
years_between(d1::Date, d2::Date, overlap=true)Compute the number of integer years between two dates, with the first date typically before the second. Will return negative number if first date is after the second. The third argument overlap indicates whether the calendar anniversary should count as a full year (default true).
Examples
julia> d1 = Date(2018,09,30);
julia> d2 = Date(2019,09,30);
julia> d3 = Date(2019,10,01);
julia> years_between(d1,d3)
1
julia> years_between(d1,d2,false) # same month/day but `false` overlap
0
julia> years_between(d1,d2) # same month/day but `true` overlap
1
julia> years_between(d1,d2) # using default `true` overlap
1 ActuaryUtilities.Utilities.accum_offset — Function
accum_offset(x; op=*, init=1.0)A shortcut for the common operation wherein a vector is scanned with an operation, but has an initial value and the resulting array is offset from the traditional accumulate.
This is a common pattern when calculating things like survivorship given a mortality vector and you want the first value of the resulting vector to be 1.0, and the second value to be 1.0 * x[1], etc.
Two keyword arguments:
opis the binary (two argument) operator you want to use, such as*or+initis the initial value in the returned array
Examples
julia> accum_offset([0.9, 0.8, 0.7])
3-element Array{Float64,1}:
1.0
0.9
0.7200000000000001
julia> accum_offset(1:5) # the product of elements 1:n, with the default `1` as the first value
5-element Array{Int64,1}:
1
1
2
6
24
julia> accum_offset(1:5,op=+)
5-element Array{Int64,1}:
1
2
4
7
11