# The MBMCL R package for multi-line stochastic reserving

After working on a bootstrapping framework for the Mack model, with a one-year point of view and with several triangles to bootstrap jointly, i decided to put some of my code into a litle package, *mbmcl*.

You can install it with :

```
devtools::install_github("lrnv/mbmcl")
library(mbmcl)
```

We’ll also load some conveniance packages, namely magrittr/dplyr/purrr/tibble/tidyr.

```
library(magrittr)
library(dplyr)
library(purrr)
library(tibble)
library(tidyr)
```

Then load some triangle data, for exemple the `ABC`

triangle from the `ChainLadder`

package. For the purpose of this exposition, we need several triangles of same size, lets create dummy triangles, and look at mack’s results on them :

```
library(ChainLadder)
data("ABC")
random_triangle <- function(source_triangle){
source_triangle %>%
cum2incr %>%
multiply_by(matrix(data=abs(rnorm(length(ABC),1,0.5)),nrow=dim(ABC)[1])) %>%
incr2cum %>%
return
}
triangles <- list(A = random_triangle(ABC),B = random_triangle(ABC),C = random_triangle(ABC))
triangles %>%
map(MackChainLadder) %>%
map(summary) %>%
map("Totals") %>%
enframe %>%
mutate(
value = value %>%
map(~mutate(.x,Output = row.names(.x)))
) %>%
unnest() %>%
spread(name,Totals)
```

Ok theese 3 triangles are different enough for our purpose.

Now, let’s compute a Bootstrap of the Mack model on the first triangle. For that, we’ll use the `BootMackChainLadder`

function from the package :

```
Model <-
BootMackChainLadder(
Triangle = triangles[[1]],
B = 100, # Number of bootstrap replicates
distNy = "normal", # distribution of next-year residuals.
)
```

Only the first argument (the input triangle) is required, but specifying the number of bootstrap replicates is better, and specifying the distribution for residuals can be usefull. Indeed, if we choose to resample residuals with a normal distribution, we can consider that we are in the *normal*, *true-glm* version of the classical *quasi-glm* model that is the mack model. On the other hand, specifying `distNy = "residuals"`

will give you a bootstrap corresponding to the *quasi-glm* mack model.

```
Model
```

Note that it gives the same This-year results as the classical mack model. Indeed, only the One-year part of this model is bootstraped.

If you want the comparaison with the MW formula, you could do something like this :

```
Num_replicates <- 10^seq(1,4,by=0.1)
Models <- map(Num_replicates,~BootMackChainLadder(Triangle = triangles[[1]],B=.x,distNy = "normal"))
Models %>%
map(CDR) %>%
map_dbl(~.x %>% pull() %>% rev %>% .[[1]]) %>%
{plot(Num_replicates, .,type="b",main = "Bootstraped standard error of the total CDR function of the number \n of boostrap replicates (red = MW formula)")}
abline(col="red",h = triangles[[1]] %>% MackChainLadder %>% CDR %>% .[[2]] %>% rev %>% .[[1]])
```

This works for one triangle, but what if my claims are divided into several triangles, that i need to develop in a joint manner to understand the variability of the **total** reserves over a one-year period ?

Well, in this case, you could apply the formula proposed my Merz-Wüthrich in 2008 for the variability of the CDR in the **Braun Model**.

If you want a bootstrap, you could apply the proposition of **Boumezoued et al** in 2011, wich is exactly what does the default parameters of the `MutliBootMackChainLadder`

function from the eponym package.

```
MBMCL <- MultiBootMackChainLadder(triangles,
B=100,
distNy = "normal")
```

From this object, you can extract several informations, for exemple mean bootstrapped results :

`mean(MBMCL)`

Or information about the One-year risk, for each triangle AND on the agregated portefolio

```
CDR(MBMCL)
```

Finaly, the model gives you a *bootstrapped* joint distribution for the 3 *Claim developement results*, allowing, for exemple, to compute corelation between them :

```
Corel(MBMCL)
```

You can also get a lot of information from `str`

: every class exported by the package(mainly, the `BootMackChainLadder`

and `MultiBootMackChainLadder`

objects) are standard S3 classes containing all simulations and all informations about simulations that were done. Exploiting thoose objects is straightforward, it is just a matter of “where is the information i need ?”.

Other options are availiable in the functions to parametrise the bootstraps a little more : stabilisation of coefficients, Bornhuetter-fergusson, etc.. But thoose extension are *not* based on peer-reviewed academic work, so use them with caution and… read the code !