-
Notifications
You must be signed in to change notification settings - Fork 0
/
PensionTariff.jl
135 lines (113 loc) · 4.7 KB
/
PensionTariff.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
module PensionTariff
using LifeInsuranceDataModel, JSON, Dates, LifeContingencies
using MortalityTables
using Yields
import LifeContingencies: V, ä # pull the shortform notation into scope
include("TariffUtilities.jl")
using .TariffUtilities
import LifeInsuranceDataModel.get_tariff_interface
"""
LifeInsuranceDataModel.get_tariff_interface(::Val{2})
Life Risk Insurance
"""
function LifeInsuranceDataModel.get_tariff_interface(::Val{2})
@info "get_tariff_interface in PensionTariff "
let
calls = JSON.parse("""
{"calculation_target":
{"selected": "none",
"label": "calculation target",
"options": ["net premium","pension rate"],
"net premium":
{"pension rate":{"type":"Int", "default":0, "value":null},
"n":{"type":"Int", "default":0, "value":null},
"m":{"type":"Int", "default":0, "value":null},
"frequency":{"type":"Int", "default":0, "value":null},
"begin":{"type":"Date", "default":"2020-01-01", "value":null}
},
"pension rate":
{"net premium":{"type":"Int", "default":0, "value":null},
"n":{"type":"Int", "default":0, "value":null},
"m":{"type":"Int", "default":0, "value":null},
"frequency":{"type":"Int", "default":0, "value":null},
"begin":{"type":"Date", "default":"2020-01-01", "value":null}
}
}, "result": {"value": 0}
}
""")
attributes = JSON.parse("""
{ "interest rate": 0.02,
"mortality_tables":
{ "f": {"nonsmoker": "1986-92 CIA – Female Nonsmoker, ANB",
"smoker": "1986-92 CIA – Female Smoker, ANB" },
"m":{"nonsmoker": "1986-92 CIA – Male Nonsmoker, ANB",
"smoker": "1986-92 CIA – Male Smoker, ANB"}
}
}
""")
tariffitem_attributes = JSON.parse("""
{"n":{"type":"Int", "default":0, "value":null},
"m":{"type":"Int", "default":0, "value":null},
"frequency":{"type":"Int", "default":0, "value":null},
"begin":{"type":"Date", "default":"2020-01-01", "value":null},
"pension rate":{"type":"Int", "default":0, "value":null},
"net premium":{"type":"Int", "default":0, "value":null}
}""")
partnerroles = [1]
TariffInterface("Life Risk Insurance",
calls, calculate!, validate, attributes, tariffitem_attributes, partnerroles)
end
end
function calculate!(tis::TariffItemSection, params::Dict{String,Any})
try
# accessiong partner data
pr = tis.partner_refs[1].ref.revision
dob = pr.date_of_birth
sex = pr.sex
smoker = pr.smoker
#accessing tariff data
tariffparameters = get_tariff_interface(Val(1)).parameters
mts = tariffparameters["mortality_tables"]
i = tariffparameters["interest rate"]
fn = params["calculation_target"]["selected"]
args = params["calculation_target"][fn]
if fn == "net premium"
begindate = Date(args["begin"]["value"])
pr = parse(Int, args["pension rate"]["value"])
m = parse(Int, args["m"]["value"])
n = parse(Int, args["n"]["value"])
frq = parse(Int, args["frequency"]["value"])
issue_age = insurance_age(dob, begindate)
life = SingleLife(
mortality=MortalityTables.table(mts[sex][smoker ? "smoker" : "nonsmoker"]).select[issue_age])
yield = Yields.Constant(i) # Using a flat 1,25% interest rate
lc = LifeContingency(life, yield) # LifeContingency joins the risk with interest
ins = Insurance(lc) # Whole Life insurance
ins = Insurance(life, yield) # alternate way to construct
premium_net(lc)
params["result"]["value"] = pr * ä(lc, n, start_time=m, frequency=frq)
elseif fn == "pension rate"
begindate = Date(args["begin"]["value"])
np = parse(Int, args["net premium"]["value"])
m = parse(Int, args["m"]["value"])
n = parse(Int, args["n"]["value"])
frq = parse(Int, args["frequency"]["value"])
issue_age = insurance_age(dob, begindate)
life = SingleLife(
mortality=MortalityTables.table(mts[sex][smoker ? "smoker" : "nonsmoker"]).select[issue_age])
yield = Yields.Constant(i) # Using a flat 1,25% interest rate
lc = LifeContingency(life, yield) # LifeContingency joins the risk with interest
ins = Insurance(lc) # Whole Life insurance
ins = Insurance(life, yield) # alternate way to construct
premium_net(lc)
params["result"]["value"] = np / ä(lc, n, start_time=m, frequency=frq)
end
catch err
println("wassis shief gegangen ")
@error "ERROR: " exception = (err, catch_backtrace())
end
end
function validate(tis::TariffItemSection)
@info "validating Pension Tariff"
end
end # module