Skip to content

Instantly share code, notes, and snippets.


Insurance Data Science Conference 2018


Modelling longevity risk for retirement and pension planning

Gareth Peters, Heriot-Watt University, Edinburgh

In this talk we build on a sequence of papers recently developed to enhance the modelling of life expectancy based on mortality data. Forecasting life expectancy and mortality are two important aspects for the study of demography that influence pension planning, retirement decisions and government policy.

We demonstrate how to develop regression models incorporating stochastic factors such as graduation temporal effects, period effects, cohort effects, stochastic volatility and long memory to enhance the forecasting and estimation of life tables. In addition, we show the mispricing that occurs in standard annuities, pure endowments and Gauranteed Annuity Oprtions (GAOs)


Stan in Insurance Workshop 17 July 2018

[8:30-9:00] Registration

[9:00 - 10:30] Eric Novik

  • Intro to Stan, including:
    • Coding linear regression to assess wine quality
    • Demonstrating important parts of the Stan program
  • Doing some basic posterior predicting checking
View plotBananas.R
checkModelPlot <- function(x, data, delta, company_code, col=c(1,2),
main="Reported incurred loss development by accident year",
ylab="Loss ratio (%)", xlab="Development year",...){
my.settings <- list(
par.main.text = list(font = 2, # make it bold
just = "left",
x = grid::unit(5, "mm")),
par.sub.text = list(font = 1,
mages / snip.R
Created January 11, 2018 21:41
Mac: Copy R data frame to clipboard
View snip.R
snip <- function(input) {
pb <- pipe("pbcopy", "w")
write.table(input, sep="\t", file=pb, row.names = FALSE)

R in Insurance, Paris, 8 June 2017


  • 9:00 am - 9:10 am Welcome - Julien Pouget (Directeur de l'ENSAE)

9:10 am - 10:00 am Opening Keynote Session

  • Textual analysis of expert reports to increase knowledge of technological risks - Julie SEGUELA, Covea

10:00 am - 11:00 am Session 1 - big data

View NormalDistribution.stan
functions {
// Define log probability density function
real myNormal_lpdf(real y, real mu, real sigma) {
return -log(2 * pi()) / 2 - log(sigma)
- square(mu - y) / (2 * sigma^2);
data {
int N;
real y[N];
View NormalDistribution.R
y <- rnorm(100, 4, 2)
truehist(y, col="#B2001D")
lines(density(y), col="skyblue", lwd=2)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -0.4294 3.0120 4.2280 4.2180 5.3830 8.8030
View WorldBankMotionChart.R
# Download World Bank data and turn into data.table
myDT <- data.table(
wb(indicator = c("SP.POP.TOTL",
"SP.DYN.TFRT.IN"), mrv = 60)
# Download country mappings