Chibisi Chima-Okereke —
written Jun 24, 2014 —
source
The Chain Ladder method is an actuarial technique used for
projecting incurred insurance claims to their ultimate loss
values. The data exists as claims triangles where the claims for
each accounting year increments down the rows and the claims for
each development period increments along the columns. This claims
triangle can be represented in a triangular upper matrix (along the
anti-diagonal) and the Chain Ladder technique works by filling in
the lower part of the matrix using ratios of claims in previous
accounting years and development periods.
In this example, we show how an implementation in R is sped up by
calling an equivaluent implementation in C++ from R using the Rcpp
interface.
We start with the C++ code for carrying out the Chain Ladder calculation.
The following function returns the fully projected triangle
The preceding C++ code is used by the following R code for simulating the claims triangles
We then use R code for projecting the traingle
We now run a timed test comparing chain ladder running in R natively
and being called from C++ functions using the Rcpp interface
Unit: microseconds
expr min lq median uq max neval
GetChainSquareR(x) 235.106 245.836 252.348 258.65 31378.5 10000
GetChainSquareCpp(x) 5.984 6.946 9.573 11.99 852.8 10000