ChainLadder Markus 20090724 PDF
ChainLadder Markus 20090724 PDF
ChainLadder Markus 20090724 PDF
One-Day Workshop
24 July, Staple Inn, London
Claims reserving in R
The ChainLadder package
Markus Gesmann
Contact: [email protected] 1
Content
Introduction
ChainLadder package
R and databases
R and MS Office interfaces
Double click the paperclip symbol in the bottom of this slide to access all the
R code of this presentation.
Markus Gesmann
The ChainLadder package R code from ChainLadder slides.R
2
Claims reserving in insurance
Markus Gesmann
The ChainLadder package
3
Reserving in insurance
Markus Gesmann
The ChainLadder package
4
Typical scenario
C
al
"homogeneous" classes of
en
da
rY
Origin Years
business, e.g. motor, marine,
ea
s r
property, etc.
Policies are aggregated by
class and looked at in a
triangle view of reported Reported claims
claims developments
Markus Gesmann
The ChainLadder package
5
Stochastic reserving
Markus Gesmann
The ChainLadder package
7
The ChainLadder package
Agenda:
Getting started
ChainLadder package
philosophy
Examples for
MackChainLadder
MunichChainLadder
BootChainLadder
Project web page: http://code.google.com/p/chainladder/
Current version: 0.1.2-11
Markus Gesmann
The ChainLadder package
8
Getting started
Markus Gesmann
The ChainLadder package
10
Triangle plot
Incurred claims development by origin year
4
5 5
4
4 3 3
5 3
4
20000
3 1 1 1
1
Incurred Claims
3 1 2 2
5
4 6 2 2
3 2
1
8 6
6 7
1
4
5000 10000
7
1 2
5
3
1
8
6
4
1 9 2
2
7
3
9
0
6
8
5
7
2
0
2 4 6 8 10
Development Year
Markus Gesmann
The ChainLadder package
11
Working with triangles
Markus Gesmann
The ChainLadder package
12
ChainLadder package philosophy
Markus Gesmann
The ChainLadder package
13
Chain-ladder as linear regression
Chain-ladder can be regarded as weighted linear
regression through the origin:
x <- RAA[,1] # dev. period 1 Force it through
the origin
y <- RAA[,2] # dev. period 2
model <- lm(y ~ x + 0, weights=1/x)
Volume weighted
Call:
lm(formula = y ~ x + 0, weights = 1/x)
Coefficients:
x
2.999 chain-ladder link-ratio
Markus Gesmann
The ChainLadder package
14
Full regression output
The output shows:
model formula
> summary(model)
Call:
chain-ladder link
ratio
lm(formula = y ~ x + 0, weights = 1/x)
std. error of the link
Residuals: ratio
Min 1Q Median 3Q Max P-value
-95.54 -71.50 49.03 99.55 385.32
Residual std. error
Coefficients:
Estimate Std. Error t value Pr(>|t|)
x 2.999 1.130 2.654 0.0291 *
---
Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1
Residual standard error: 167 on 8 degrees of freedom
Multiple R-squared: 0.4682,
Adjusted R-squared: 0.4017
F-statistic: 7.043 on 1 and 8 DF, p-value: 0.02908
Markus Gesmann
The ChainLadder package
15
Chain-ladder using the lm function
Markus Gesmann
The ChainLadder package
16
Accessing regression statistics
CL <- ChainLadder(RAA)
# Get chain-ladder link-ratios
sapply(CL, coef)
# 2.999 1.62 1.27 1.17 1.11 1.04 1.03 1.016 1.0
# Get residual standard errors
sapply(lapply(CL, summary), "[[", "sigma")
# 166.98 33.29 26.295 7.82 10.9 6.389 1.159 2.8 NaN
# Get R squared values
sapply(lapply(ChainLadder(RAA), summary), "[[",
"r.squared")
# 0.468 0.95 0.97 0.997 0.995 0.998 0.999 0.999 1.00
Markus Gesmann
The ChainLadder package
17
Mack-chain-ladder
Macks chain-ladder method calculates the
standard error for the reserves estimates.
The method works for a cumulative triangle Cik if
the following assumptions are hold:
Totals
Latest: 160,987.00
Ultimate: 213,122.23
IBNR: 52,135.23
Mack S.E.: 26,909.01
CV(IBNR): 0.52
Markus Gesmann
The ChainLadder package
20
plot.MackChainLadder
The residual plots show
Mack Chain Ladder Results Chain ladder developments by origin period
4
25000
IBNR 5 5
4
Latest
the standardised
4 3 3
30000
5
4 3
3 1 1 1 1
Amounts
Amounts
15000
5
4 3 6 1 2 2
5000
4
1 9 2
3 2
7
9
0
6
8
5
7
2
0
calendar period and
0
development period.
Origin period Development period
2
2
Standardised residuals
Standardised residuals
1
show no pattern or
-1
-1
0 5000 10000 15000 20000 25000 30000 1982 1984 1986 1988
direction for Mack's
Fitted Origin period method to be
applicable.
2
2
Standardised residuals
Standardised residuals
1
-1
1982 1984
Calendar period
1986 1988 1 2 3 4 5
Development period
6 7 8
trends and require
plot(M) further investigations.
Markus Gesmann
The ChainLadder package
21
Munich-chain-ladder
Markus Gesmann
The ChainLadder package
22
Munich-chain-ladder example
P/I triangle Full P/I triangle using chain ladder
1.0
3 1 1 6 6
5
4 3
4
1 1 2
1 6 6 5 5
6 2 3
0.9
3 6 4
1.0
4 2 5 5 3
4
3 2 5 3 3
4 1
2 1
2
1 4 4
1 1
6 1
3 2 2
0.8
4 2
Paid/Incurred
Paid/Incurred
5 3
1
2
0.8
5
0.7
2
5
4 7 7
7 7
5
4 7
0.6
0.6
1 7
6
6
0.5
3
2 3
2
7 7
0.4
0.4
1 2 3 4 5 6 7 1 2 3 4 5 6 7
Markus Gesmann
The ChainLadder package
23
MunichChainLadder
Usage:
MunichChainLadder(Paid, Incurred,
est.sigmaP = "log-linear",
est.sigmaI = "log-linear",
tailP=FALSE, tailI=FALSE)
Markus Gesmann
The ChainLadder package
24
MunichChainLadder example
Latest Paid Latest Incurred Latest P/I Ratio Ult. Paid Ult. Incurred Ult. P/I Ratio
1 2,131 2,174 0.980 2,131 2,174 0.980
2 2,348 2,454 0.957 2,383 2,444 0.975
3 4,494 4,644 0.968 4,597 4,629 0.993
4 5,850 6,142 0.952 6,119 6,176 0.991
5 4,648 4,852 0.958 4,937 4,950 0.997
6 4,010 4,406 0.910 4,656 4,665 0.998
7 2,044 5,022 0.407 7,549 7,650 0.987
Totals
Paid Incurred P/I Ratio
Latest: 25,525 29,694 0.86
Munich-chain-ladder
Ultimate: 32,371 32,688 0.99 forecasts based on paid and
incurred losses
Markus Gesmann
The ChainLadder package
25
plot.MunichChainLadder
1. 2.
Munich Chain Ladder Results Munich Chain Ladder vs. Standard Chain Ladder
1. MCL forecasts
on P and I
MCL Paid Mack P/I
2000 4000 6000
2. Comparison of
MCL Incurred MCL P/I
80
Amounts
60
Ultimate P/I
40
ratios of MCL
20
and Mack
0
0
1 2 3 4 5 6 7 1 2 3 4 5 6 7
2
Incurred/Paid residuals
Paid/Incurred residuals
residuals
1
1
0
4. P/I link-ratio
-1
-1
residuals against
-2
-2
-2 -1 0 1 2 -2 -1 0 1 2 I link-ratios
Paid residuals Incurred residuals
residuals
plot(MCL)
Markus Gesmann
The ChainLadder package
26
Bootstrap-chain-ladder
Markus Gesmann
The ChainLadder package
27
BootChainLadder
Usage:
BootChainLadder(Triangle, R = 999,
process.distr=c("gamma",
"od.pois"))
Markus Gesmann
The ChainLadder package
28
BootChainLadder example
set.seed(1)
BootChainLadder(Triangle = RAA, R = 999, process.distr = "od.pois")
Latest Mean Ultimate Mean IBNR SD IBNR IBNR 75% IBNR 95%
1981 18,834 18,834 0 0 0 0
1982 16,704 16,921 217 710 253 1,597
1983 23,466 24,108 642 1,340 1,074 3,205
1984 27,067 28,739 1,672 1,949 2,679 4,980
1985 26,180 29,077 2,897 2,467 4,149 7,298
1986 15,852 19,611 3,759 2,447 4,976 8,645
1987 12,314 17,724 5,410 3,157 7,214 11,232
1988 13,112 24,219 11,107 5,072 14,140 20,651
1989 5,395 16,119 10,724 6,052 14,094 21,817
1990 2,063 18,714 16,651 13,426 24,459 42,339
Totals
Latest: 160,987
Mean Ultimate: 214,066
Mean IBNR: 53,079
SD IBNR: 18,884
Total IBNR 75%: 64,788
Total IBNR 95%: 88,037
Markus Gesmann
The ChainLadder package
29
plot.BootChainLadder
1. 2.
1.Histogram of simulated
total IBNR
2.Empirical distribution of
total IBNR
3.Box-whisker plot of
simulated ultimate
claims cost by origin
period
3. 4.
4.Test if latest actual
incremental loss could
come from simulated
distribution of claims
cost
Markus Gesmann
The ChainLadder package
30
Generic Methods
Mack-, Munich-, BootChainLadder
names: gives the individual elements back
summary: summary by origin and totals
print: nice formatted output
plot: plot overview of the results
MackChainLadder
residuals: chain-ladder residuals
BootChainLadder
mean: mean IBNR by origin and totals
quantile: gives quantiles of the simulation back
Markus Gesmann
The ChainLadder package
31
R and databases
DB
ODBC
R
sqlQuery
Agenda: as.ArrayTriangle
sqlSave
Query database
Tables to triangles
Apply functions
Write to database R: ChainLadder
Markus Gesmann
The ChainLadder package
32
Working with databases
Markus Gesmann
The ChainLadder package
34
Write test data into database
library(RODBC)
# Create a test database in c:/Temp (here MS Access 2003)
channel <- odbcConnectAccess(
"C:/Temp/ChainLadderTestData.mdb")
sqlSave(channel, triangleTable, "tblTestTriangles",
rownames=FALSE)
odbcClose(channel)
Markus Gesmann
The ChainLadder package
35
Read tables from database
# From database
channel <- odbcConnectAccess(
"C:/Temp/ChainLadderTestData.mdb")
myData <- sqlQuery(channel,
"SELECT * FROM tblTestTriangles;")
odbcClose(channel)
Markus Gesmann
The ChainLadder package ChainLadderTestData.mdb
36
As an aside: Plot tables with lattice
GenIns ABC
1.2
Triangles stored in
1.0
long tables are much
0.8
easier to plot than
0.6
triangles in cross-tab
0.4
formats
0.2
value/1e+06
2 4 6 8 10 2 4 6 8 10
# Plot long triangles RAA Mortgage
6
xyplot(
value/1e6 ~ dev | LOB,
4
groups=origin, t="l",
2
data=myData,
scales="free"
0
) 2 4 6 8 10
dev
2 4 6 8
Markus Gesmann
The ChainLadder package
37
Transform tables into triangles
We use the array function rather than reshape,
as its output is ready to be used by ChainLadder
Markus Gesmann
The ChainLadder package
38
Use by to apply ChainLadder functions
Markus Gesmann
The ChainLadder package
39
Combine results in tables
Markus Gesmann
The ChainLadder package
40
Write results into database
Markus Gesmann
The ChainLadder package
41
Database summary
Use R to query DB
Transform table to
triangles
Apply ChainLadder
function across all
triangles
Summaries results
Save results in DB
Markus Gesmann
The ChainLadder package
42
R and MS Office interfaces
Agenda:
win.metafile
Clipboard
RExcel
COM-server
rcom
Markus Gesmann
The ChainLadder package
43
Windows meta-file
win.metafile(file="C:/Temp/Testplot.wmf")
plot(sin(seq(0,round(2*pi,2),0.01)))
dev.off()
Markus Gesmann
The ChainLadder package
44
Clipboard to exchange data
Excel -> R
read.table(file= "clipboard", sep="\t")
Markus Gesmann
The ChainLadder package
45
RExcel - Using R from within Excel
RExcel Add-in allows to use R functions from Excel, see:
http://sunsite.univie.ac.at/rcom/
There are at least three different ways of using R from within Excel
Scratchpad mode
Writing R Code directly in an Excel worksheet and
transferring scalar, vector, and matrix variables between R
and Excel
Macro mode
Writing macros using VBA and the macros supplied by
RExcel, attaching the macros to menu items or toolbar items
Worksheet functions
R can be called directly in functions in worksheet cells
Source: http://sunsite.univie.ac.at/rcom/server/doc/RExcel.html
Markus Gesmann
The ChainLadder package
46
ChainLadder_in_Excel.xls
RExcel allows to
use R functions
within Excel
Package comes
with example file
R function can be
embedded and
are interactive
Use R graphics
Markus Gesmann
The ChainLadder package
47
Using the COM server (VBA Example)
Sub FirstR()
Dim nrandom As Integer, x As Double
nrandom = 100
Set StaR = New StatConnector
StaR.Init ("R")
With StaR
.SetSymbol "n", nrandom
.EvaluateNoReturn ("x <- rnorm(n)")
.EvaluateNoReturn ("pdf(file='c:/Temp/Testplot.pdf')")
.EvaluateNoReturn ("hist(x)")
.EvaluateNoReturn ("dev.off()")
x = .Evaluate("mean(x)")
End With
Debug.Print x
End Sub
Markus Gesmann
The ChainLadder package
48
rcom: Control MS Office from R
Markus Gesmann
The ChainLadder package
49
More help ...
See examples on project web page
Read documentation on CRAN: http://cran.r-project.org/
web/packages/ChainLadder/ChainLadder.pdf
Read help pages in R:
?MackChainLadder
?MunichChainLadder
?BootChainLadder
Follow examples in R:
example(MackChainLadder)
example(MunichChainLadder)
example(BootChainLadder)
Markus Gesmann
The ChainLadder package
50
Conclusions
Markus Gesmann
The ChainLadder package
51
For a laugh - fancy 3d plot
Markus Gesmann
The ChainLadder package
52
References
Thomas Mack. Distribution-free calculation of the standard error of chain
ladder reserve estimates. Astin Bulletin. Vol. 23. No 2. 1993. pp 213-225.
Thomas Mack. The standard error of chain ladder reserve estimates:
Recursive calculation and inclusion of a tail factor. Astin Bulletin. Vol. 29. No
2. 1999. pp 361-366.
Murphy, Daniel M. Unbiased Loss Development Factors. Proceedings of the
Casualty Actuarial Society Casualty Actuarial Society - Arlington, Virginia
1994: LXXXI 154-222.
Zehnwirth and Barnett. Best estimates for reserves. Proceedings of the CAS,
LXXXVI I(167), November 2000.
P.D.England and R.J.Verrall, Stochastic Claims Reserving in General
Insurance, British Actuarial Journal, Vol. 8, pp.443-544, 2002.
Gerhard Quarg and Thomas Mack. Munich Chain Ladder. Bltter DGVFM 26,
Munich, 2004.
Nigel De Silva. An Introduction to R: Examples for Actuaries. Actuarial Toolkit
Working Party, version 0.1 edition, 2006. http://toolkit.pbwiki.com/RToolkit.
Markus Gesmann
The ChainLadder package
53