
Simulate multiple scenarios of household lifetime finances
Source:R/simulate_scenarios.R
simulate_scenarios.Rd
Simulate multiple scenarios of household lifetime finances
Usage
simulate_scenarios(
scenarios_parameters,
household,
portfolio,
current_date = get_current_date(),
monte_carlo_samples = NULL,
auto_parallel = FALSE,
use_cache = FALSE,
debug = FALSE,
...
)
Arguments
- scenarios_parameters
A
tibble
with columnscenario_id
and nested columnevents
. Each scenario has defined one or more events in the tibbles that are stored in as a list in theevents
column.- household
An R6 object of class
Household
.- portfolio
A nested
tibble
of classPortfolio
.- current_date
A character. Current date in the format
YYYY-MM-DD
. By default, it is the output ofget_current_date()
.- monte_carlo_samples
An integer. Number of Monte Carlo samples. If
NULL
(default), no Monte Carlo samples are generated.- auto_parallel
A logical. If
TRUE
, the function automatically detects the number of cores and uses parallel processing to speed up the Monte Carlo simulations. The results are cached in the folder set byset_cache()
.- use_cache
A logical. If
TRUE
, the function uses memoised functions to speed up the simulation. The results are cached in the folder set byset_cache()
.- debug
A logical. If
TRUE
, additional information is printed during the simulation.- ...
Additional arguments passed simulation functions.
Examples
if (FALSE) { # interactive()
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
)
start_ages <- c(60, 65, 70)
scenarios_parameters <-
tibble::tibble(
member = "older",
event = "retirement",
start_age = start_ages,
years = Inf,
end_age = Inf
) |>
dplyr::mutate(scenario_id = start_age) |>
tidyr::nest(events = -scenario_id)
scenarios_parameters
scenarios <-
simulate_scenarios(
scenarios_parameters = scenarios_parameters,
household = household,
portfolio = portfolio,
current_date = "2020-07-15"
)
scenarios$scenario_id |> unique()
}