-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathpolicy.py
More file actions
255 lines (182 loc) · 6.94 KB
/
policy.py
File metadata and controls
255 lines (182 loc) · 6.94 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
"""Source module to create ``Policy`` space from.
This module is a source module to create ``Policy`` space and its
sub spaces from.
The formulas of the cells in the ``Policy`` space are created from the
functions defined in this module.
The ``Policy`` space is the base space of the policy spaces
for individual policies, which are derived from and belong to
the ``Policy`` space as its dynamic child spaces.
The policy spaces for individual policies are parametrized by ``PolicyID``.
For example, to get the policy space of the policy whose ID is 171::
>> pol = model.Policy(171)
The cells in a policy space for each individual policy retrieve
input data, calculate and hold values of policy attributes specific to that policy,
so various spaces in :mod:`Input<simplelife.build_input>` must be accessible
from the ``Policy`` space.
.. rubric:: Project Templates
This module is included in the following project templates.
* :mod:`simplelife`
* :mod:`nestedlife`
.. rubric:: Space Parameters
Attributes:
PolicyID: Policy ID
.. rubric:: References in Base
Attributes:
PolicyData: Input.PolicyData
ProductSpec: Input.ProductSpec
LifeTable: LifeTable
Gen: Generation key
.. rubric:: References in Sub
Attributes:
Product: Product key
PolicyType: Policy type key
Gen: Generation key
Channel: Channel key
Sex: ``M`` for Male, ``F`` for Female
Duration: Number of years lapsed. 0 for new business
IssueAge: Issue age
PremFreq: Number of premium payments per year. 12 for monthly payments
PolicyTerm: Policy term in year
PolicyCount: Number of policies
SumAssured: Sum Assured per policy
"""
# Policy Attributes
policy_attrs = ['Product',
'PolicyType',
'Gen',
'Channel',
'Sex',
'Duration',
'IssueAge',
# 'WholeTermPaymentFlag',
# 'PremTerm',
# 'PremMode',
'PremFreq',
# 'WholeLifeFlag',
'PolicyTerm',
# 'MaxTerm',
'PolicyCount',
'SumAssured']
# 'GrossPremMult']
def IntRate(RateBasis):
"""Interest Rate"""
if RateBasis == 'PREM':
int_rate = ProductSpec.IntRatePrem
elif RateBasis == 'VAL':
int_rate = ProductSpec.IntRateVal
else:
raise ValueError('invalid RateBasis')
result = int_rate.match(Product, PolicyType, Gen).value
if result is not None:
return result
else:
raise ValueError('invalid RateBais')
def TableID(RateBasis):
"""Mortality Table ID"""
if RateBasis == 'PREM':
mort_table = ProductSpec.MortTablePrem
elif RateBasis == 'VAL':
mort_table = ProductSpec.MortTableVal
else:
raise ValueError('invalid RateBasis')
result = mort_table.match(Product, PolicyType, Gen).value
if result is not None:
return result
else:
raise ValueError('invalid RateBais')
def LoadAcqSA():
"""Acquisition Loading per Sum Assured"""
param1 = ProductSpec.LoadAcqSAParam1(Product)
param2 = ProductSpec.LoadAcqSAParam2(Product)
return param1 + param2 * min(PolicyTerm / 10, 1)
def LoadMaintPrem():
"""Maintenance Loading per Gross Premium"""
if ProductSpec.LoadMaintPremParam1(Product) is not None:
return ProductSpec.LoadMaintPremParam1(Product)
elif ProductSpec.LoadMaintPremParam2(Product) is not None:
param = ProductSpec.LoadMaintPremParam2(Product)
return (param + min(10, PolicyTerm)) / 100
else:
raise ValueError('LoadMaintPrem parameters not found')
def LoadMaintPremWaiverPrem():
"""Maintenance Loading per Gross Premium for Premium Waiver"""
if PremTerm < 5:
return 0.0005
elif PremTerm < 10:
return 0.001
else:
return 0.002
def LoadMaintSA():
"""Maintenance Loading per Sum Assured during Premium Payment"""
result = ProductSpec.LoadMaintSA.match(Product, PolicyType, Gen).value
if result is not None:
return result
else:
raise ValueError('lookup failed')
def LoadMaintSA2():
"""Maintenance Loading per Sum Assured after Premium Payment"""
result = ProductSpec.LoadMaintSA2.match(Product, PolicyType, Gen).value
if result is not None:
return result
else:
raise ValueError('lookup failed')
def InitSurrCharge():
"""Initial Surrender Charge Rate"""
param1 = ProductSpec.SurrChargeParam1.match(Product, PolicyType, Gen).value
param2 = ProductSpec.SurrChargeParam2.match(Product, PolicyType, Gen).value
if param1 is None or param2 is None:
raise ValueError('SurrChargeParam not found')
return param1 + param2 * min(PolicyTerm / 10, 1)
def NetPremRate(basis):
"""Net Premium Rate"""
gamma2 = LoadMaintSA2
comf = LifeTable[Sex, IntRate(basis), TableID(basis)]
if Product == 'TERM' or Product == 'WL':
return (comf.Axn(x, n) + gamma2 * comf.AnnDuenx(x, n-m, 1, m)) / comf.AnnDuenx(x, n)
elif Product == 'ENDW':
return (comf.Axn(x, n) + gamma2 * comf.AnnDuenx(x, n-m, 1, m)) / comf.AnnDuenx(x, n)
else:
raise ValueError('invalid product')
def GrossPremRate():
"""Gross Premium Rate per Sum Assured per payment"""
alpha = LoadAcqSA
beta = LoadMaintPrem
gamma = LoadMaintSA
gamma2 = LoadMaintSA2
delta = LoadMaintPremWaiverPrem
comf = LifeTable[Sex, IntRate('PREM'), TableID('PREM')]
if Product == 'TERM' or Product == 'WL':
return (comf.Axn(x, n) + alpha + gamma * comf.AnnDuenx(x, n, PremFreq)
+ gamma2 * comf.AnnDuenx(x, n-m, 1, m)) / (1-beta-delta) / PremFreq / comf.AnnDuenx(x, m, PremFreq)
elif Product == 'ENDW':
return (comf.Exn(x, n) + comf.Axn(x, n) + alpha + gamma * comf.AnnDuenx(x, n, PremFreq)
+ gamma2 * comf.AnnDuenx(x, n-m, 1, m)) / (1-beta-delta) / PremFreq / comf.AnnDuenx(x, m, PremFreq)
else:
raise ValueError('invalid product')
def AnnPremRate():
"""Annualized Premium Rate per Sum Assured"""
return GrossPremRate * (1/10 if PremFreq == 0 else PremFreq)
def GrossPremTable():
"""Gross premium table"""
return None
def ReserveNLP_Rate(basis, t):
"""Net level premium reserve rate"""
gamma2 = LoadMaintSA2
lt = LifeTable[Sex, IntRate(basis), TableID(basis)]
if t <= m:
return lt.Axn(x+t, n-t) + gamma2 * lt.AnnDuenx(x+t, n-m, 1, m-t) \
- NetPremRate(basis) * lt.AnnDuenx(x+t, m-t)
else:
return lt.Axn(x+t, n-t) + gamma2 * lt.AnnDuenx(x+t, n-m, 1, m-t)
def ReserveRate():
"""Valuation Reserve Rate per Sum Assured"""
return None
def SurrCharge(t):
"""Surrender Charge Rate per Sum Assured"""
return InitSurrCharge * max((min(m, 10) - t) / min(m, 10), 0)
def CashValueRate(t):
"""Cash Value Rate per Sum Assured"""
return max(ReserveNLP_Rate('PREM', t) - SurrCharge(t), 0)
def UernPremRate():
"""Unearned Premium Rate"""
return None