# Convert conditional death probabilities into the survivor function. calculate.survivorfn <- function(age){ cooked <- rep(NA, 101) cooked[age+1] <- 100 for(i in (age+2):100) { cooked[i] <- cooked[i-1] - a$qxm[i]*cooked[i-1] } return(cooked) } # Work out two survivor functions, starting at age 60 and starting at age 35 -- a <- read.csv("http://www.mayin.org/ajayshah/lfs/india_male_mortality2015.csv", sep=",") a$cooked.60 <- calculate.survivorfn(60) a$cooked.35 <- calculate.survivorfn(35) # Draw a graph with the two survivor functions -- par(mai=c(.8,.8,.2,.2)) plot(35:100,a$cooked.35[36:101], type="l", lwd=2,col="blue", xlab="Age",ylab="Survivors") lines(60:100,a$cooked.60[61:101], type="l", lwd=2,col="red", xlab="Age", ylab="Survivors") legend(x="bottomleft",lwd=2,col=c("blue","red"), bty="n", cex=.75, legend=c("Starting at age 35","Starting at age 60")) # Make the NPV of an annuity p, where people die off based on the # survivor function S, when the interest rate is r, l is the number of # years the pension has to be paid. value.of.pension <- function(p, S, r, l=0) { (1/r)^(1:l) %*% (p * S) } # As an example: Price an annuity of Rs.1 per day at age 60: value.of.pension(rep(365,40), a$cooked.60[61:100]/100, 1.07,l=40) # Do scenarios based on inflation and wage growth -- inflation <- c(0.03, 0.04, 0.05) wagegrowth <- c(0.07, 0.08,0.09) # A function to make the stream of pension payments. l is the number # of years these have to be paid, and index is either the inflation or # wage index. make.pension.mat <- function(l, index){ p1 <- matrix(NA, l, 3) p1[1,] <- 365 for(i in 2:l){ p1[i,1] <- p1[i-1,1] + index[1]*p1[i-1,1] p1[i,2] <- p1[i-1,2] + index[2]*p1[i-1,2] p1[i,3] <- p1[i-1,3] + index[3]*p1[i-1,3] } return(p1) } # Now do lots of cases. # Price indexation p1 <- make.pension.mat(40, inflation) value.of.pension(p1, a$cooked.60[61:100]/100, 1.07,l=40) # Wage indexation p1 <- make.pension.mat(40, wagegrowth) value.of.pension(p1, a$cooked.60[61:100]/100, 1.07,l=40) # Retirement at 35 value.of.pension(rep(365,65), a$cooked.35[36:100]/100, 1.07,l=65) # Price indexation p1 <- make.pension.mat(65, inflation) value.of.pension(p1, a$cooked.35[36:100]/100, 1.07,l=65) # Wage indexation p1 <- make.pension.mat(65, wagegrowth) value.of.pension(p1, a$cooked.35[36:100]/100, 1.07,l=65)