simulation: Run Simulation of Death and Lapse Scenarios

View source: R/simulation.R

simulationR Documentation

Run Simulation of Death and Lapse Scenarios

Description

This function simulates death and lapse events over the insurance period using the portfolio created by make_portfolio(). The total number of simulations is n_sim * split, and results are saved in CSV or Parquet format in the specified path.

Usage

simulation(
  df,
  n_sim = NULL,
  split = NULL,
  seed = NULL,
  sync_seed = TRUE,
  output_format = "csv",
  output_path = NULL
)

Arguments

df

A data.frame returned by make_portfolio()

n_sim

Number of simulations per split

split

Number of splits (simulation repetitions)

seed

Random seed (optional)

sync_seed

Logical flag (default = TRUE). If TRUE, ensures that all policies belonging to the same insured person use synchronized random seeds for death simulation, thereby ensuring consistent timing of death events across policies. This is critical for accurately capturing volatility risk arising from common mortality shocks.

output_format

Output file format: "csv" or "parquet"

output_path

Path to save the simulation results and logs

Value

No return value. Files are saved to output_path.

Examples

# Prepare portfolio
port <- make_portfolio(example_portfolio, cols = list(
  unique_id = "POL_ID",
  client_id = "CLIENT_ID",
  duration = "DURATION",
  mortality = "MORTALITY",
  lapse = "LAPSE",
  nar = "NAR",
  rate = "RATE"
))

# Run simulation (output_path = tempdir() for demonstration)
simulation(port,
           n_sim = 10,
           split = 100,
           seed = 12345,
           output_format = "csv",
           output_path = tempdir()
           )

volrisk documentation built on June 14, 2025, 9:07 a.m.