simulate_scenario {R4GoodPersonalFinances}R Documentation

Simulate a scenario of household lifetime finances

Description

The function simulates a scenario of household lifetime finances and returns a tibble with nested columns. By default no Monte Carlo samples are generated, and only single sample based on portfolio expected returns are returned with column sample=0. If the additional Monte Carlo samples are generated, they have consecutive IDs starting from 1 in the sample column.

Usage

simulate_scenario(
  household,
  portfolio,
  scenario_id = "default",
  current_date = get_current_date(),
  monte_carlo_samples = NULL,
  seeds = NULL,
  use_cache = FALSE,
  debug = FALSE,
  ...
)

Arguments

household

An R6 object of class Household.

portfolio

A nested tibble of class Portfolio.

scenario_id

A character. ID of the scenario.

current_date

A character. Current date in the format YYYY-MM-DD. By default, it is the output of get_current_date().

monte_carlo_samples

An integer. Number of Monte Carlo samples. If NULL (default), no Monte Carlo samples are generated.

seeds

An integer vector. Seeds for the random number generator used to generate random portfolio returns for each Monte Carlo sample. If NULL (default), random seed is generated automatically.

use_cache

A logical. If TRUE, the function uses memoised functions to speed up the simulation. The results are cached in the folder set by set_cache().

debug

A logical. If TRUE, additional information is printed during the simulation.

...

Additional arguments passed simulation functions.

Value

A tibble with nested columns including:

Examples


older_member <- HouseholdMember$new(
  name       = "older",  
  birth_date = "1980-02-15",
  mode       = 80,
  dispersion = 10
)  
household <- Household$new()
household$add_member(older_member)  

household$expected_income <- list(
  "income" = c(
    "members$older$age <= 65 ~ 7000 * 12"
  )
)
household$expected_spending <- list(
  "spending" = c(
    "TRUE ~ 5000 * 12"
  )
)

portfolio <- create_portfolio_template() 
portfolio$accounts$taxable <- c(10000, 30000)
portfolio <- 
  portfolio |> 
  calc_effective_tax_rate(
    tax_rate_ltcg = 0.20, 
    tax_rate_ordinary_income = 0.40
  )

scenario <- 
  simulate_scenario(
   household = household,
   portfolio = portfolio,
   current_date = "2020-07-15"
  )
names(scenario)


[Package R4GoodPersonalFinances version 1.0.0 Index]