Skip to content

Instantly share code, notes, and snippets.

Markus Gesmann mages

Block or report user

Report or block mages

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
mages /
Last active Oct 7, 2019
Reading temperature from Arduino
# Based on code by Paul McWhorter:
import serial
import re
import csv
import numpy as np
import matplotlib.pyplot as plt
from drawnow import *

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)

mages / gist:1544009
Created Dec 31, 2011
Search and replace string across files with R
View gist:1544009
## The following example demonstrates
## how a serach and replace string task
## can be peformed with R across several files
## Create two text files with content
filenames <- c( tempfile(), tempfile() )
for( f in filenames ){
cat("We wish you a Merry Christmas!\n\nBest regards\n", file=f)
View KalmanFilterExample.R
mycols <- topo.colors(100,0.5)
xhat <- c(0.2, -0.2)
Sigma <- matrix(c(0.4, 0.3,
0.3, 0.45), ncol=2)
x1 <- seq(-2, 4,length=151)
x2 <- seq(-4, 2,length=151)
f <- function(x1,x2, mean=xhat, varcov=Sigma)
dmnorm(cbind(x1,x2), mean,varcov)
z <- outer(x1,x2, f)
View Linear_models.R
# Markus Gesmann
library(arm) # for 'display' function only
icecream <- data.frame(
temp=c(11.9, 14.2, 15.2, 16.4, 17.2, 18.1,
18.5, 19.4, 22.1, 22.6, 23.4, 25.1),
units=c(185L, 215L, 332L, 325L, 408L, 421L,
406L, 412L, 522L, 445L, 544L, 614L)
basicPlot <- function(...){
mages / add.alpha.R
Last active Dec 20, 2018
How to change the alpha value of colours in R
View add.alpha.R
## Add an alpha value to a colour
add.alpha <- function(col, alpha=1){
stop("Please provide a vector of colours.")
apply(sapply(col, col2rgb)/255, 2,
rgb(x[1], x[2], x[3], alpha=alpha))
mages / ClusterAnalysis.R
Last active Jul 24, 2018
k-means cluster analysis in R
View ClusterAnalysis.R
url <-""
readImage <- readJPEG(getURLContent(url, binary=TRUE))
dm <- dim(readImage)
rgbImage <- data.frame(
x=rep(1:dm[2], each=dm[1]),
y=rep(dm[1]:1, dm[2]),

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
You can’t perform that action at this time.