Welcome to the hotseat. We've prepared a guide if you'd like to read more about how it works.

R Code lecture example 1b

0 votes
52 views
asked Aug 15 in BUS 3024S - Contingencies by anonymous
Refer to today's R lecture example 1b, 
My code produce a different policy value  to the solution uploaded and I can't figure out where I went wrong (I used prospective method rather than retrospective.

Here's my code:
tV=c()
for (t in 0:20){
  A50t=SA*Axn(type="END",age=50+t,term =20-t, sp=T,i=int)
  a50t=prem*axn(type="Temp",age =50+t, term =20-t, sp=T, i=int)
  tV[t+1]=A50t-a50t
  t=t+1
}
polvaluematrix=data.frame(tm=0:20,policy_Value =tV)

Thank you!
commented Aug 16 by Njabulo.Dube (2,330 points)

Here's a hint: 

The life was selected at age 50. Think about how this affects the "sp=T" parameter in the annuity and assuarance functions.

commented Aug 22 by Junlin (200 points)
edited Aug 22 by Junlin
Is it because I input age as 50+t and sp=T, so R runs every age as selected, but in our case, the selection period is only 2 years?
commented Aug 22 by Njabulo.Dube (2,330 points)

Yes. That's the issue. Now, can you answer this question for everyone to follow what the issue is and how to go about fixing it when doing it via the prospective method? 

commented Aug 22 by Junlin (200 points)
My 1V is still different, but all the others give the same result. I tried to fix my code but it doesn't seems successful. I think the problem might be because: by code age as 50+t, R sees it as age [51] rather than [50]+1, but I'm struggling to fix it
##1b
tV2=c()
for (t in 0:1){
  A50t=SA*Axn(type="END",age=50+t,term =20-t, sp=T,i=int)
  a50t=prem*axn(type="Temp",age =50+t, term =20-t, sp=T, i=int)
  tV2[t+1]=A50t-a50t
  t=t+1
}
for (t in 2:20){
  A50t=SA*Axn(type="END",age=50+t,term =20-t, sp=F,i=int)
  a50t=prem*axn(type="Temp",age =50+t, term =20-t, sp=F, i=int)
  tV2[t+1]=A50t-a50t
  t=t+1
}
pol_val_2 = data.frame(tm = 0:20, policy_values = tV2)

commented Aug 23 by Njabulo.Dube (2,330 points)

Have a look at the solution on the R lecture notebook and see if you can now answer your own question

Please log in or register to answer this question.

...