Skip to content

Commit

Permalink
allow fractional issue age if mortality is a parametric model
Browse files Browse the repository at this point in the history
  • Loading branch information
alecloudenback committed Feb 3, 2024
1 parent 0fd6134 commit 671e244
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/LifeContingencies.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,19 @@ Keyword arguments:
issue_age = 30
)
"""
struct SingleLife{M,D} <: Life
struct SingleLife{I,M,D} <: Life
mortality::M
issue_age::Int
issue_age::I
alive::Bool
fractional_assump::D
function SingleLife(mortality::M, issue_age::I, alive::Bool=true, fractional_assump::D=mt.Uniform()) where {M<:MortalityTables.ParametricMortality,I<:Real,D<:DeathDistribution}

return new{I,M,D}(mortality, issue_age, alive, fractional_assump)
end
function SingleLife(mortality::M, issue_age::I, alive::Bool=true, fractional_assump::D=mt.Uniform()) where {M,I<:Integer,D<:DeathDistribution}

return new{I,M,D}(mortality, issue_age, alive, fractional_assump)
end
end

function SingleLife(; mortality, issue_age=nothing, alive=true, fractional_assump=mt.Uniform())
Expand All @@ -77,9 +85,9 @@ function SingleLife(mortality; issue_age=nothing, alive=true, fractional_assump=
issue_age = firstindex(mortality)
end

if !(eltype(mortality) <: Real)
if (eltype(mortality) <: AbstractArray)
# most likely case is that mortality is an array of vectors
# use issue age to select the right one (assuming indexed with issue age
# use issue age to select the right one (assuming indexed with issue age)
return SingleLife(mortality[issue_age], issue_age, alive, fractional_assump)
else
return SingleLife(mortality, issue_age, alive, fractional_assump)
Expand Down
12 changes: 12 additions & 0 deletions test/single_life.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,16 @@
@test premium_net(ins, 26) LifeContingencies.A(ins, 26) / LifeContingencies.(ins, 26)

end

@testset "issue https://github.com/JuliaActuary/LifeContingencies.jl/issues/78" begin
t = MortalityTables.table("2001 VBT Residual Standard Select and Ultimate - Male Nonsmoker, ANB")
i = 0.05
@test_throws MethodError LifeContingency(SingleLife(mortality=t.ultimate, issue_age=53.75), i)

m = MortalityTables.MakehamBeard()
lc1 = LifeContingency(SingleLife(mortality=m, issue_age=53.75), i)
lc2 = LifeContingency(SingleLife(mortality=m, issue_age=54.00), i)
@test l(lc1, 1) > l(lc2, 1)

end
end

0 comments on commit 671e244

Please sign in to comment.