Skip to content

Commit

Permalink
Merge pull request #100 from JuliaActuary/life_exp_fix2
Browse files Browse the repository at this point in the history
Life exp fix2
  • Loading branch information
alecloudenback authored Apr 27, 2021
2 parents ab4544b + 6843a57 commit 663e8fe
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MortalityTables"
uuid = "4780e19d-04b9-53dc-86c2-9e9aa59b5a12"
authors = ["Alec Loudenback <alecloudenback@gmail.com>"]
version = "2.1.1"
version = "2.1.2"

[deps]
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
Expand Down
15 changes: 13 additions & 2 deletions src/life_expectancy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,24 @@
life_expectancy(table,age,DeathDistribution)
Calcuate the remaining life expectancy. Assumes curtate life expectancy for tables if not Parametric or DeathDistribution given.
The life_expectancy of the last age defined in the table is set to be `0.0`, even if the table does not end with a rate of `1.0`.
"""
function life_expectancy(table,age)
sum(survival(table,age,age + dur) for dur in 1:lastindex(table) -age)
if age == lastindex(table)
return 0.
else
sum(survival(table,age,age + dur) for dur in 1:lastindex(table) -age)
end
end

function life_expectancy(table,age,dist)
QuadGK.quadgk(to -> survival(table,age,to+age,dist),0,lastindex(table)-age)[1]
if age == lastindex(table)
return 0.
else
QuadGK.quadgk(to -> survival(table,age,to+age,dist),0,lastindex(table)-age)[1]
end

end

function life_expectancy(table::ParametricMortality,age)
Expand Down
1 change: 1 addition & 0 deletions test/life_expectancy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

# calculate sum of tpx in Excel
@test life_expectancy(t.ultimate,55) 22.16469212 atol=1e-6
@test life_expectancy(t.ultimate,100) 0.0 atol=1e-6

# relation of curtate to complete, ALMC 2.6.1
@test life_expectancy(t.ultimate,55,MortalityTables.Uniform()) 22.16469212 + 0.5 atol=1e-3
Expand Down

2 comments on commit 663e8fe

@alecloudenback
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/35415

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v2.1.2 -m "<description of version>" 663e8fe7addf779448f7fff8e27d62a9a1b518cd
git push origin v2.1.2

Please sign in to comment.