simulation | R Documentation |
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.
simulation(
df,
n_sim = NULL,
split = NULL,
seed = NULL,
sync_seed = TRUE,
output_format = "csv",
output_path = NULL
)
df |
A data.frame returned by |
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 |
No return value. Files are saved to output_path
.
# 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()
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.