################################################################################
# LOAD PACKAGES AND SCRIPTS IN SEQUENCE TO PRODUCE AHV EXPENDITURE PROJECTIONS #
################################################################################

# Preamble. ------------------------------------------------------------------------------

# Clear workspace and load necessary packages.
rm(list = ls())
sapply(c("tidyverse", "simputation", "readxl", "rsample", "broom", "strucchange"), 
       library, char = TRUE)

# Suppress variable type guessing messages from 'readr' functions.
options(readr.show_col_types = FALSE)

# Calculations. --------------------------------------------------------------------------

# Define helper functions.
source("scripts/other/aux_fun.R")

# Load baseline parameters.
source("scripts/model/1_initialize_parameters.R")

# Read and process input data.
source("scripts/model/2_prepare_inputs.R")

# Translate demographic scenarios into Swiss pension stock projections and consolidate
# input data into analysis table.
source("scripts/model/3_adjust_scenarios.R")

# Conduct cross-validation for linear trend extrapolations and save optimal 'Trendpunkte'. 
# Must be run at least once (results are stored as 'data/output/RANGE.RData').
if (PAR$cv)
  source("scripts/model/4_cross-validation.R")

# Produce and return the reference projection of the AHV total expenditures.
source("scripts/model/5_reference_projection.R", echo = TRUE)

# Simulate 'high' and 'low' expenditure paths in line with the BSV 'Umlage-Szenario'
# concept, and report them in combination with the reference projection.
if (PAR$bands)
  source("scripts/model/6_uncertainty_bands.R", echo = TRUE)

