################################################################################
# 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 crossvalidation for linear trend extrapolations and save optimal 'Trendpunkte'. 
# Must be run at least once (results are stored as 'data/out/range.RData'). Optional since 
# time consuming.
if (PAR$cv)
  source("scripts/model/4_cv_out.R")

# Produce and return total expenditure projections.
source("scripts/model/5_proj_out.R", echo = TRUE)
