/reproducible-reserving

An example workflow for actuarial reserving using R/Rmarkdown

Primary LanguageRApache License 2.0Apache-2.0

reproducible-reserving

Experiments that (hopefully) lead to an example workflow for actuarial reserving using R/Rmarkdown.

Why a workflow in R/Rmarkdown?

Spreadsheets currently dominate the workflows of actuaries and the following pain points associated with them:

  • Single files make it difficult for the distributed teams of the modern workplace to work in parallel.
  • Spreadsheets are prone to reproducibility problems, as steps in analysis might be encoded several different ways (e.g., formula, macro, separate documentation, memory of analyst).
  • Logic and orchestration embedded in macros is often opaque and difficult to maintain.
  • Changes/errors may be difficult to spot because the model and view are on top of each other.
  • Once created, spreadsheet based workflows are often brittle to changes in methodology or implementation.

These are problems that can be addressed by moving to an R/RMarkdown based workflow supported by distributed version control (git).

Example

Since my primary goal is investigate workflow alternatives, my initial example will be pretty simple, and consist of the following pieces:

  • Simulate incremental paid data using {simulationmachine} package.
  • Clean, transform, filter, and aggregate claim data into form needed for analysis
  • Data Diagnostics (examples)
    • Large Claim movements
    • Actual vs Expected
  • Traditional reserve review including at least the following
    • Chainladder
    • BF
    • Cape Cod
    • Selection based on a rule (e.g. default method weights)
  • Report
    • Reserve Report (rmarkdown rendered to pdf)
    • Summary Tables (spreadsheet)
    • Deck for Board Presentation (rmarkdown rendered to slides)

Although this analysis is quite straightforward, one of the benefits of an R/Rmarkdown workflow is the easy at which new methodologies can be incorporated. I intend to demostrate this as this project evolves.

Try it yourself

Note on gt package

This project makes use of two amazing amazing packages that currently have a small conflict with each other. The renv package is used to control dependencies to lock down the execution environment for this project, and the gt package which is used to create presentation ready tables in Rmarkdown reports. As of this writing (2019-12-29), gt is not on CRAN and so has to be installed from github, but there is currently an issue doing this directly into environments managed by renv (link)

  1. clone github repo to local machine
git clone https://github.com/rstudio/gt.git
  1. Run check and build gt package
# install devtools if not already installed
# install.packages("devtools")

# run R build check to confirm that all dependencies are present
devtools::check()

# build gt package locally
pkg_path <- devtools::build()
  1. Install the package localally
devtools::install_local(pkg_path)

Once you have the gt package installed on your system you can setup this project

  1. clone repo to you computer
git clone https://github.com/actuarialvoodoo/reproducible-reserving.git
  1. Open up Rstudio project and restore dependencies
renv::restore()
  1. Run drake plan
drake::r_make()