Professional Documents
Culture Documents
(Oct 02) Consider a portfolio of 1-year term life insurance independent policies from the file LIFEin-
surance.csv that specifies age and insured amount for each policy, with the additional#benefit of
twice the insured amount in case of accidental death, assuming that 1 out of 10 deaths is accidental
(no matter the age). Use the mortality table in the file mortality.csv and do the following: a)
Calculate the theoretical mean and variance for total claims. b) Through 60000 claims simulations
of the portfolio, estimate mean and variance of total claims, and compare to the theoretical values
obtained in the previous item. c) Also from b) estimate Value at Risk (VaR) of level 99.5% for
total claims. d) Using item a) results, calculate normal approximation of VaR of level 99.5% for
total claims, and compare to the VaR obtained in item c). e) Graph a histogram of the simulations
of total claims from item b) and add to the same graph the approximated normal density.
[4]: mortality=pd.read_csv('/home/carlos-vazquez/Descargas/mortality.csv')
mortality=pd.DataFrame(mortality)
#mortality
[5]: life=pd.read_csv('/home/carlos-vazquez/Descargas/LIFEinsurance.csv')
life=pd.DataFrame(life)
#life
for j in range(len(life['AGE'])):
qj = q[life.AGE[j]]
cj = life.INSAMOUNT[j]
1
ES += (1+k)*qj*cj
VS += cj**2*(1.3)*qj-(cj*qj*1.1)**2
print("E(S)= %F " % ES)
print("VAR(S)= %F" %VS)
#print("E(S)= %F",%)
E(S)= 345.349800
VAR(S)= 4202.942122
2. Through 60000 claims simulations of the portfolio, estimate mean and variance of total claims,
and compare to the theoretical values obtained in the previous item.
[12]: #Numero de simulaciones, no pongas las 60,000
m= 2000
fin=default_timer()
print(fin-inicio)
6.350041851001151
[14]: '''
Fijo semilla
'''
np.random.seed(1)
'''
Creo una matriz donde simulo si la persona muere de un accidente o no,
las filas son simulaciones de cada persona,
las colmnas es la simulacion de toda la tabla, hay 10,000 filas y m columnas
'''
inicio=default_timer()
accident=[list(np.random.binomial(size=m,n=1,p=k)) for i in range(len(life.
,→AGE)) ]
fin=default_timer()
print(fin-inicio)
#accident
8.599715409996861
2
[15]: '''
Creo otra matriz donde si la persona murio le multiplico su suma asegurada, si␣
,→murio por accidente le sumo 2 veces
la suma asegurada
'''
inicio=default_timer()
todo =[[life.INSAMOUNT[i]*cmuera[i][j]*(1+accident[i][j]) for j in range(m) ]␣
,→for i in range(len(life.AGE))]
fin=default_timer()
print(fin-inicio)
#todo
426.1776272920033
[16]: '''
Creo una lista donde guardo la suma de cada columna , es decir una simulacion␣
,→de S,
[17]: simVaR=pd.DataFrame(S).quantile(0.995)
print("VaR(S)_0.995 = %f " %simVaR)
VaR(S)_0.995 = 523.408500
d) Using item a) results, calculate normal approximation of VaR of level 99.5% for total claims,
and compare to the VaR obtained in item c).
[18]: norm.ppf(0.995,ES,(VS)**0.5)
[18]: 512.3410762579526
[ ]:
e) Graph a histogram of the simulations of total claims from item b) and add to the same graph
the approximated normal density.
[19]: plt.title('SImulations of S')
x=range(100,700)
3
plt.hist(S,label='Simulation of S',edgecolor = 'black',bins=50, alpha=1,density␣
,→=True,color='yellow')
plt.plot(x,norm.pdf(x,loc=ES,scale= (VS**0.5)),color='blue',label='Normal␣
,→aprox')
plt.ylabel('density')
plt.xlabel('S')
plt.legend()
plt.show()
[ ]:
[ ]:
[ ]: