项目作者: kasaai

项目描述 :
Individual claims history simulation machine
高级语言: R
项目地址: git://github.com/kasaai/simulationmachine.git
创建时间: 2019-08-19T19:41:59Z
项目社区:https://github.com/kasaai/simulationmachine

开源协议:Other

下载


simulationmachine

Lifecycle:
experimental
Travis build
status

This package implements the claims history simulation algorithm detailed
in An Individual Claims History Simulation
Machine
by Andrea Gabrielli and
Mario V. Wüthrich. The goal is to provide an easy-to-use interface for
generating claims data that can be used for loss reserving research.

Installation

You can install the development version from
GitHub with:

  1. # install.packages("remotes")
  2. remotes::install_github("kasaai/simulationmachine")

Example

First, we can specify the parameters of a simulation using
simulation_machine():

  1. library(simulationmachine)
  2. charm <- simulation_machine(
  3. num_claims = 50000,
  4. lob_distribution = c(0.25, 0.25, 0.30, 0.20),
  5. inflation = c(0.01, 0.01, 0.01, 0.01),
  6. sd_claim = 0.85,
  7. sd_recovery = 0.85
  8. )
  9. charm
  10. #> A simulation charm for `simulation_machine`
  11. #>
  12. #> Each record is:
  13. #> - A snapshot of a claim's incremental paid loss and claim status
  14. #> at a development year.
  15. #>
  16. #> Specs:
  17. #> - Expected number of claims: 50,000
  18. #> - LOB distribution: 0.25, 0.25, 0.3, 0.2
  19. #> - Inflation: 0.01, 0.01, 0.01, 0.01
  20. #> - SD of claim sizes: 0.85,
  21. #> - SD of recovery sizes: 0.85

Once we have the charm object, we can use conjure() to perform the
simulation.

  1. library(dplyr)
  2. records <- conjure(charm, seed = 100)
  3. glimpse(records)
  4. #> Observations: 603,324
  5. #> Variables: 11
  6. #> $ claim_id <chr> "1", "1", "1", "1", "1", "1", "1", "1", "1", "…
  7. #> $ accident_year <int> 1994, 1994, 1994, 1994, 1994, 1994, 1994, 1994…
  8. #> $ development_year <int> 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2,…
  9. #> $ accident_quarter <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 4, 4, 4…
  10. #> $ report_delay <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
  11. #> $ lob <chr> "3", "3", "3", "3", "3", "3", "3", "3", "3", "…
  12. #> $ cc <chr> "42", "42", "42", "42", "42", "42", "42", "42"…
  13. #> $ age <int> 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65…
  14. #> $ injured_part <chr> "51", "51", "51", "51", "51", "51", "51", "51"…
  15. #> $ paid_loss <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4913, 0, 0…
  16. #> $ claim_status_open <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0…

Let’s see how many claims we drew:

  1. records %>%
  2. distinct(claim_id) %>%
  3. count()
  4. #> # A tibble: 1 x 1
  5. #> n
  6. #> <int>
  7. #> 1 50277

If you prefer to have each row of the dataset to correspond to a claim,
you can simply pivot the data with tidyr:

  1. records_wide <- records %>%
  2. tidyr::pivot_wider(
  3. names_from = development_year,
  4. values_from = c(paid_loss, claim_status_open),
  5. values_fill = list(paid_loss = 0)
  6. )
  7. glimpse(records_wide)
  8. #> Observations: 50,277
  9. #> Variables: 32
  10. #> $ claim_id <chr> "1", "2", "3", "4", "5", "6", "7", "8", "9"…
  11. #> $ accident_year <int> 1994, 1994, 1994, 1994, 1994, 1994, 1994, 1…
  12. #> $ accident_quarter <dbl> 1, 4, 4, 2, 1, 1, 1, 3, 4, 4, 2, 2, 4, 3, 1…
  13. #> $ report_delay <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0…
  14. #> $ lob <chr> "3", "3", "3", "4", "2", "1", "3", "1", "3"…
  15. #> $ cc <chr> "42", "39", "26", "8", "50", "22", "43", "1…
  16. #> $ age <int> 65, 52, 23, 54, 24, 53, 39, 40, 27, 43, 55,…
  17. #> $ injured_part <chr> "51", "53", "70", "36", "36", "53", "51", "…
  18. #> $ paid_loss_0 <dbl> 0, 4913, 0, 458, 1158, 376, 0, 285, 0, 0, 0…
  19. #> $ paid_loss_1 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 3389, 0, 0, 0, 0…
  20. #> $ paid_loss_2 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
  21. #> $ paid_loss_3 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
  22. #> $ paid_loss_4 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
  23. #> $ paid_loss_5 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
  24. #> $ paid_loss_6 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
  25. #> $ paid_loss_7 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
  26. #> $ paid_loss_8 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
  27. #> $ paid_loss_9 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
  28. #> $ paid_loss_10 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
  29. #> $ paid_loss_11 <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
  30. #> $ claim_status_open_0 <int> 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0…
  31. #> $ claim_status_open_1 <int> 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0…
  32. #> $ claim_status_open_2 <int> 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
  33. #> $ claim_status_open_3 <int> 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
  34. #> $ claim_status_open_4 <int> 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
  35. #> $ claim_status_open_5 <int> 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
  36. #> $ claim_status_open_6 <int> 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
  37. #> $ claim_status_open_7 <int> 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
  38. #> $ claim_status_open_8 <int> 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
  39. #> $ claim_status_open_9 <int> 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
  40. #> $ claim_status_open_10 <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…
  41. #> $ claim_status_open_11 <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0…

Please note that this project is released with a Contributor Code of
Conduct
.
By participating in this project you agree to abide by its terms.