lifetab <- function(t0,t1,t2,l_0,l_e,Shock=0)
{
# Input: l_0 is age of policy holders when the contracts are drawn up,
# l_e maximum age, whereas t0, t1, t2 are Gomperz-Makeham parameters.
#
# Output: kp is the lifetable and q the mortalities. Indexing: kp[l,k]
# is the probability of surviving k-1 years given the initial age l_0+l-1.
# Mortality q[l] is the probability of dying at age $l_0+l-1$.
#
ll <- l_0:(l_e+l_e)
q <- pmin(pmax((1-exp(-t0-(t1/t2)*(exp(t2)-1)*exp(t2*ll)))*(1+Shock),0),1)
kp <- matrix(0,l_e+1,l_e+1)
kp[,1] <- 1
for (l in 1:(l_e-1))
{
for (k in 2:(l_e+1-l))
{
kp[l,k] <- kp[l,k-1]*(1-q[l+k-2])
}
}
list(l_0=l_0,l_e=l_e,kp=kp,q=q)
}
ndist <- function(gamma,mu,K,J)
{
# The distribution of policies according to how long they have been in the
# company.
# Input: Parameters describing the distribution of the policies.
#
# Output: N number of policies at different age with indexing as
# described in function "lifetab".
#
p <- exp(-gamma*abs(0:K-mu))
N <- p*(J/sum(p))
N
}
riskfree <- function(a,b,theta,K=200,Shock=NULL)
{
# The risk-free rates of interest stored as rf.
#
rf <- a+b*(1-exp(-(1:K)*theta))
if(length(Shock) > 0)
{
rf <- rf*pmax(1-Shock,0)
}
rf
}