An open API service indexing awesome lists of open source software.

https://github.com/problemofpoints/reservetestr

Provides a Framework for Testing Loss Reserve Methods
https://github.com/problemofpoints/reservetestr

Last synced: 4 months ago
JSON representation

Provides a Framework for Testing Loss Reserve Methods

Awesome Lists containing this project

README

        

---
output: github_document
---

[![Travis build status](https://travis-ci.org/problemofpoints/reservetestr.svg?branch=master)](https://travis-ci.org/problemofpoints/reservetestr)
[![AppVeyor build status](https://ci.appveyor.com/api/projects/status/github/problemofpoints/reservetestr?branch=master&svg=true)](https://ci.appveyor.com/project/problemofpoints/reservetestr)
[![lifecycle](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://www.tidyverse.org/lifecycle/#maturing)
[![Coverage status](https://codecov.io/gh/problemofpoints/reservetestr/branch/master/graph/badge.svg)](https://codecov.io/github/problemofpoints/reservetestr?branch=master)

```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)

```

# reservetestr

The goal of reservetestr is to provide a framework for testing loss reserve methods. Specifically, an interface to test methods against the [Casualty Actuarial Society (CAS) Loss Reserve Database](http://www.casact.org/research/index.cfm?fa=loss_reserves_data) is provided.

## Installation

You can install reservetestr from GitHub with:

```{r gh-installation, eval = FALSE}
# install.packages("devtools")
devtools::install_github("problemofpoints/reservetestr", upgrade_dependencies = FALSE)
```

## Example Usage

```{r import-libraries, warning=FALSE}
library(reservetestr)
suppressPackageStartupMessages(library(ChainLadder))
library(dplyr)
library(tidyr)
library(purrr)
library(ggplot2)

reservetestr::ggSetTheme()
```

## CAS Loss Reserve Database

From the [CAS website](http://www.casact.org/research/index.cfm?fa=loss_reserves_data):

> "Our goal is to prepare a clean and nice data set of loss triangles that could be used for claims reserving studies.
The data includes major personal and commercial lines of business from U.S. property casualty insurers.
The claims data comes from Schedule P - Analysis of Losses and Loss Expenses
in the National Association of Insurance Commissioners (NAIC) database."

Below is an example paid loss triangle from the database. The first triangle is the upper triangle used to fit the model. The second triangle is the actual lower right of the triangle used for model validation / testing.

```{r sample-data-train, fig.cap="Sampe Paid Loss Triangle - Training data"}
cas_loss_reserve_db %>%
get_meyers_subset(edition = 2) %>%
filter(line == "ppauto" & group_id == 388) %>%
pluck("train_tri_set", 1, "paid")
```

The back-testing results use a subset of the full database, resulting in 50 triangles across four lines of business - comauto, othliab, ppauto, wkcomp. For this example, we will only use "comauto".

```{r subset-data, fig.cap="Summary of Triangles by Line"}
cas_db_subset <- cas_loss_reserve_db %>%
get_meyers_subset(edition = 2)
```

The main function is `run_single_backtest` which, in this example, runs the `ChainLadder::MackChainLadder` method on each paid loss triangle.

```{r backtest-mack, warning=FALSE, message=FALSE, echo=TRUE}
mack_paid_results <- run_single_backtest(cas_db_subset,
testr_MackChainLadder,
lines_to_include = "comauto",
loss_type_to_backtest = "paid",
method_label = "mack_paid")
```

The output provided is the below.

```{r mack-glimpse}
glimpse(mack_paid_results)
```

We can create a p-p plot to visually access the accuracy of our estimates. If our method was perfect, we would expect to see the dots fall along the 45 degree line - indicating that our implied percentiles are perfectly uniform.

That is not the case in this example, so for "comauto" the Mack method applied to paid data does not back-test well.

```{r mack-exhibits-pp}
create_pp_plot(mack_paid_results, by_line = TRUE)
```

## Future Enhancements

- Add error metrics for deterministic methods
- Create an object structure using S3 class system
- Add more error handling
- Add `testr_` functions for the other methods in `ChainLadder`
- Add ability to test several methods at once