MultiATSM package - General Guidelines

Rubens Moura

2024-10-15

This document aims at providing general guidance on the use of the MultiATSM package available at the CRAN repository.

library(MultiATSM)

The MultiATSM package offers estimation routines and various outputs for single and multi-country affine term structure models (ATSMs). All the frameworks of this package are based on the unspanned economic risk framework from (JPS, 2014). In essence, these models assume the absence of arbitrage opportunities, consider a linear state space representation of the yield curve dynamics and offer a tractable approach to simultaneously combine the traditional yield curve factors (spanned factors) along with macroeconomic and financial variables (unspanned factors).

The MultiATSM package currently supports the generation of outputs for eight distinct classes of ATSMs. Specifically, the package accommodates models estimated either on a country-by-country basis, following the approach of JPS (2014), or jointly across all countries within the economic system, as developed in JLL (2015) by Jotikasthira, Le, and Lundblad (2015) and CM (2024) by Candelon and Moura (Forthcoming).

Due to peculiar features of JPS-based specifications, an efficient estimation of the parameters governing the risk-neutral (\(Q\)-measure) and the physical (\(P\)-measure) probability measures can be carried out rather independently. The only exception is the variance-covariance matrix (sigma) term which is a common element to both the \(P\) and the \(Q\) density functions. In all cases, the risk factor dynamics under the \(P\)-measure follow a VAR(1) model of some sort. The table below summarizes the general features of each one of the models available at this package.

Table 0.1: Model Features
P-dynamics
Q-dynamics
Sigma matrix estimation
Dominant Country
Individual
Joint
Individual
Joint
P only
P and Q
Unrestricted
Restricted
Unrestricted
Restricted
JLL GVAR
Unrestricted VAR
JPS original x x x
JPS global x x x
JPS multi x x x
Restricted VAR (GVAR)
GVAR single x x x
GVAR multi x x x
Restricted VAR (JLL)
JLL original x x x x
JLL No DomUnit x x x
JLL joint Sigma x x x x

Some aspects of the multi-country frameworks are worth highlighting. As for the models based on the setup of JLL (2015), the version “JLL original” follows closely the seminal work of JLL (2015), i.e., it is assumed an economic cohort containing a worldwide dominant economy and a set of smaller countries, in addition to the estimation of the sigma matrix be performed exclusively under the \(P\)-measure. The two other alternative versions assume the absence of a dominant country (“JLL No DomUnit”) and the estimation of sigma under both the \(P\) and \(Q\) measures (”JLL joint Sigma”), as in the standard single-country JPS (2014) model. As for the remaining multi-country ATSMs, it is considered that the dynamics of the risk factors under the \(P\)-measure evolves according to a GVAR model. The version labeled “GVAR multi” is the one presented in CM (2024).

In what follows, the focus will be devoted to describe the various pieces that are necessary to implement ATSMs. Specifically, Section 1 describes the data-set available at this package and the set of functions that are useful to retrieve data from Excel files. Section 2 exposes the necessary inputs that have to be specified by the user. In Section 3 the estimation procedure is detailed. Section 4 shows how to use the MultiATSM package to estimate ATSMs from scratch.

1 Data

1.1 Package data-set

The MultiATSM package includes modified datasets compared to those originally used in Candelon and Moura (2023) (CM, 2023) and Candelon and Moura (Forthcoming) (CM, 2024) due to limited availability of certain data sources. In some cases, simulated data replicating the original methodology is employed. To simplify the exposition, the database of CM (2024) is used throughout the following sections to demonstrate the package’s functions. These datasets can be accessed using the LoadData() function with the argument CM_2024, and similarly, the CM (2023) data with CM_2023.

LoadData("CM_2024")

The previous function loads four types of datasets. The first dataset consists of time series for zero-coupon bond yields from four emerging markets: China, Brazil, Mexico, and Uruguay. For the purpose of the ATSM estimation, it is important to note two requirements: (i) the bond yield maturities must be consistent across all countries (although the DataForEstimation() function can take different maturities as inputs, it outputs bond yields with uniform maturities for all economies); and (ii) the bond yields should be expressed in percentage terms per annum, not in basis points. The MultiATSM package does not include routines for bootstrapping zero-coupon yields from coupon bonds, so users must handle this data manipulation themselves if needed.

data('CM_Yields')

The second dataset focuses on the time series of risk factors. Using the terminology of JPS (2014), this dataset includes (i) country-specific spanned factors (commonly represented by level, slope, and curvature – see Section 3.1 for an intuitive explanation of these factors) and (ii) a set of country-specific and global unspanned factors, such as economic growth and inflation. Similar to the bond yield data, these economic indicators must be constructed by the user.

data('CM_Factors')

The final two datasets are essential for estimating GVAR-based models. The trade flows data, sourced from the International Monetary Fund (IMF), presents the sum of the value of all goods imports and exports between any two countries of the sample on a yearly basis since 1948. All the values are free on board and are expressed in U.S. dollars. These data are used to construct the transition matrix of the GVARs models.

data('CM_Trade')

The GVAR factors database casts country-specific lists of all the factors that are used in the estimation of each country’s VARX(1,1,1). The function titled DatabasePrep() provides assistance to structure the data in a similar fashion to this form. Moreover, a specific function for computing the star risk factors is detailed in the Section 3.2.2.

data('CM_Factors_GVAR')

1.2 Import data from Excel files

This package also offers an automatized procedure to extract data from Excel files and to, subsequentially, prepare the risk factor databases that are directly used in the model estimation. The use of the package functions requires that the databases (i) are constructed in separate Excel files for the unspanned factors, the term structure data, and the measures of interdependence (for the GVAR-based models); (ii) contain, in each Excel file, one separate tab per country (in addition to the global variables, in the case of the unspanned factors’ database); and (iii) have identical variable labels across all the tabs within each file. For illustration, see the Excel file available at the package. One example of list of inputs to be provided is, for instance,

Initial_Date <- "2006-09-01" # Format "yyyy-mm-dd"
Final_Date <- "2019-01-01" # Format "yyyy-mm-dd"
DataFrequency <- "Monthly"
GlobalVar <- c("GBC", "VIX") # Global Variables
DomVar <- c("Eco_Act", "Inflation", "Com_Prices", "Exc_Rates") #  Domestic variables
N <-  3 # Number of spanned factors per country
Economies <- c("China", "Mexico", "Uruguay", "Brazil", "Russia")
ModelType <- "JPS original"

Using these inputs, the variable RiskFac_TS can be constructed, containing the full time series of risk factors required for the model.

FactorLabels <- LabFac(N, DomVar, GlobalVar, Economies, ModelType)
RiskFac_TS <- DataForEstimation(Initial_Date, Final_Date, Economies, N, FactorLabels, ModelType,
                                DataFrequency)

2 Required user inputs

2.1 Fundamental inputs required for estimation

In order to estimate any ATSM of this package, the user needs to specify several general model inputs, namely:

1. Desired ATSM class

2. Risk factor set

3. Sample span

4. Frequency of the data:

5. Stationary constraint under the \(Q\)-dynamics:

6. Output label

One possible example of the basic model inputs is

# 1) Model type
ModelType <- "JPS original"

# 2) Risk factor set
Economies <- c("China", "Brazil", "Mexico", "Uruguay")
GlobalVar <- c("GBC", "CPI_OECD") # Global variables
DomVar <- c("Eco_Act", "Inflation") # Domestic variables 
N <- 3 # number of spanned factors per country

# 3) Sample span
Initial_Date <- "01-05-2005" # Format: "dd-mm-yyyy"
Final_Date <- "01-12-2019" # Format: "dd-mm-yyyy"

# 4) Frequency of the data
DataFrequency <- "Monthly"

# 5) Risk-neutral stationary constraint
StationarityUnderQ <- 0 # 1 = set stationary condition under the Q; 0 = no stationary condition

# 6) Output label
OutputLabel <- "Model_demo"

2.2 Model-specific inputs required for estimation

2.2.1 GVARlist and JLLlist

Additional inputs are required for estimating GVAR-ATSM or JLL-ATSM models. These inputs should be organized into separate lists, named GVARlist and JLLlist for clarity. This section outlines the general structure of both lists, while Sections 3.2.2 and 3.2.3 provide detailed explanations and available options.

For GVAR models, the nature of the inputs is twofold. First, the dynamic structure of each country’s VARX model must be specified. For example:

VARXtype <- "unconstrained"

Second, the estimation of the GVAR requires specifying the necessary inputs to build the transition matrix() . An example of this list of inputs is

W_type <- 'Sample Mean' # Method to compute the transition matrix
t_First_Wgvar <- "2000" # First year of the sample
t_Last_Wgvar <-  "2015" # Last year of the sample

Therefore, a complete GVARlist is

GVARlist <- list( VARXtype = "unconstrained", W_type = "Sample Mean",
                  t_First_Wgvar = "2000", t_Last_Wgvar = "2015") 

Regarding the JLL-ATSM frameworks, it is sufficient to specify the name of the dominant economy (if applicable) within the economic system:

JLLlist <- list(DomUnit =  "China")

2.2.2 BRWlist

In an influential paper, Bauer, Rudebusch, and Wu (2012) (BRW, 2012) have shown that the estimates from traditional ATSMs can be severely biased due to the typical small-sample size used in these studies. As result, such models may produce unreasonably stable expected future short-term interest, therefore distorting the term premia estimates for long-maturity bonds. To circumvent this problem, they propose a bootstrap-based method that relies on indirect inference estimation that corrects for the bias present in previous works.

From its version \(0.3.1\), the MultiATSM package accommodates the framework proposed by BRW (2012) to each one of its ATSM types. Some additional inputs must be specified, if the user intends to perform the model estimation along the lines of BRW (2012). They are:

  • Mean or median of OLS estimates (flag_mean): the user must decide whether to compute the mean or median of the OLS estimates after each bootstrap iteration. To compute the mean (median), the user must set TRUE (FALSE);

  • Adjustment parameter (gamma): this parameter controls the degree of shrinkage between the difference in the OLS estimates and the BRW (2012)’s bootstrap-based one after each iteration. The value of this parameter is fixed and must lie in the interval \(]0;1[\);

  • Number of iteration (N_iter) : total amount of iterations used in the stochastic approximation algorithm after burn-in;

  • Number of bootstrap samples (B): quantity of simulated samples used in each burn-in or actual iteration;

  • Perform closeness check (checkBRW): flag whether the user wishes to check the root mean square distance between the model estimates produced by the bias-correction method and those generated by OLS. Default is set to TRUE;

  • Number of bootstrap samples used in the closeness check (B_check): default is set to 100,000;

  • Number of burn-in iteration (N_burn): quantity of the iterations to be discarded in the first stage of the bias-correction estimation process. The recommended number is \(15\%\) of the total number of iterations.

BRWlist <- within(list(flag_mean = TRUE, gamma = 0.2, N_iter = 500, B = 50, 
                       checkBRW = TRUE, B_check = 1000), N_burn <- round(N_iter * 0.15))

2.3 The InputsForOpt() function

The InputsForOpt() function plays a crucial role in the functioning of the MultiATSM package. Specifically, it gathers, transforms, and generates the necessary inputs for building the likelihood function based on the user-provided inputs described in the previous sections, which are then directly utilized in the model optimization process. One possible use of InputsForOpt() is:

data(CM_GlobalMacroFactors)
data(CM_DomMacroFactors)
data(CM_Yields)

ModelType <- "JPS original"
Economies <- "Mexico"
t0 <- "01-05-2007" # Initial Sample Date (Format: "dd-mm-yyyy")
tF <- "01-12-2018" # Final Sample Date (Format: "dd-mm-yyyy")
N <- 3
GlobalVar <- c("Gl_Eco_Act") # Global Variables
DomVar <- c("Eco_Act") # Domestic Variables
FactorLabels <- LabFac(N, DomVar, GlobalVar, Economies, ModelType)

DataFreq <- "Monthly"

ATSMInputs <- InputsForOpt(t0, tF, ModelType, Yields, GlobalMacroVar, DomesticMacroVar,
                         FactorLabels, Economies, DataFreq,CheckInputs = FALSE)

2.4 Additional inputs for numerical and graphical outputs

Once the model parameters from the ATSM have been estimated, the NumOutputs() function enables the compilation of numerical and graphical of the following additional outputs:

For the numerical computation of the IRFs, GIRFs, FEVDs or GFEVDs, a horizon of analysis has to be specified, e.g.:

Horiz <- 100

For the graphical outputs, the user must indicate the desired types of graphs in a string-based vector:

DesiredGraphs <- c("Fit", "GIRF", "GFEVD") # Available options are: "Fit", "IRF", "FEVD", "GIRF", 
                                          # "GFEVD", "TermPremia".

Moreover, the user must select the types of variables of interest (yields, risk factors or both) and, for the JLL type of models, whether the orthogonalized version should be additionally included

WishGraphRiskFac <- 0 #   YES: 1; No = 0.
WishGraphYields <- 1 #    YES: 1; No = 0.
WishOrthoJLLgraphs <- 0 # YES: 1; No = 0.

The function InputsForOutputs() can provide some guidance for customizing the features of the wished outputs. Conditional to these settings, individual folders are created at the user’s temporary directory (which can be accessed using tempdir() ) to store the different types of the desired graphical outputs.

2.4.1 Bond yield decomposition

In its current form, the MultiATSM package allows for the calculation of two risk compensation measures: term premia and forward premia. In particular, a \(n\)-maturity bond yield can be decomposed as the sum of its expected (\(Exp_t^{(n)}\)) and term premia (\(TP_t^{(n)}\)) components. Technically: \[ y_t^{(n)} = Exp_t^{(n)} + TP_t^{(n)} \] In the package’s standard form, the expected short rate term is computed from time \(t\) to \(t+n\), which represents the bond’s maturity: \(Exp_t^{(n)} = \sum_{h=0}^{n} E_t[y_{t+h}^{(1)}]\). Alternatively, one could perfom such a decomposition at the forward rate level (\(f_t^{(n)}\)), specifically \(f_t^{(n)} = \sum_{h=m}^{n} E_t[y_{t+h}^{(1)}] + FP_t^{(n)}\) where \(FP_t^{(n)}\) corresponds to the forward premia. In this case, the user must specify a binary variable set to \(1\) if the computation of forward premia is desired, or \(0\) otherwise. If set to \(1\), the user must also provide a two-element numerical vector containing the maturities corresponding to the starting and ending dates of the bond maturity. Example:

    WishFPremia <- 1 # Wish to estimate the forward premia: YES: 1, NO:0 
    FPmatLim <- c(60,120)

2.4.2 Bootstrap settings

If the user intends to generate confidence bands around the point estimates of the numerical outputs previously described using a bootstrap procedure, an additional list of inputs is required. Specifically:

  • The desired bootstrap procedure (methodBS): Available options are (i) standard residual bootstrap (bs); (ii) wild bootstrap (wild), and block bootstrap (block). If the latest is selected, then the block length (BlockLength) must be indicated;
  • The number of bootstrap draws (ndraws);
  • The confidence level expressed in percentage points (pctg).
Bootlist <- list(methodBS = 'block', BlockLength = 4, ndraws =  50, pctg   =  95)

2.4.3 Out-of-sample forecast settings

To perform out-of-sample forecasts of bond yields, the following list-based features have to be detailed:

  • Number of periods-ahead that the forecasts are to be generated (ForHoriz);
  • Time-dimension index of the first observations belonging to the information set (t0Sample);
  • Time-dimension index of the last observation of the information set used to perform the first forecast set (t0Forecast);
  • Method used in the forecast computation (ForType): forecasts can be generated using rolling or expanding windows. Rolling window forecasting to be done by setting this parameter as Rolling. In such a case, the forecast length used in the forecasts is the one specified as in t0Sample. Should the user wishes the forecasts to be performed on a expanding window basis, then this input should be set as Expanding.
ForecastList <- list(ForHoriz = 12, t0Sample = 1, t0Forecast = 70, ForType = "Rolling")

3 Model Estimation

Once bond yields and economic time series data are gathered and model features are selected, ATSM estimation proceeds in three steps. First, estimate the country-specific spanned factors for inclusion in the global ATSM. Next, estimate the parameters governing risk factor dynamics under the \(P-\)measure. Finally, optimize the entire selected ATSM, including the \(Q-\)measure parameters.

3.1 Spanned Factors

The spanned factors are yield-related variables that are used to fit the cross-section dimensions of the term structures. Typically, the spanned factors of country \(i\), \(P_{i,t}\), are computed as the N first principal components (PCs) of the set of observed bond yields. Formally, \(P_{i,t}\) is constructed as \(P_{i,t} = w_i Y_{i,t}\) where \(w_i\) is the PC weight matrix and \(Y_{i,t}\) is a country-specific column-vector of yields with increasing maturities.

For N=3, the spanned factors are traditionally interpreted as level, slope, and curvature. The nature of such interpretability results from the features of the PC weight matrix as illustrated below:

w <- pca_weights_one_country(Yields, Economy = "Uruguay") 

In matrix w, each row stores the weights used for constructing each spanned factor. The entries of the first row are linked to the composition of the level factor in that they load rather equally on all yields. Accordingly, high (low) values of the level factor indicate an overall high (low) value of yields across all maturities. In the second row, the weights monotonically increase with the maturities and, therefore, they capture the degree of steepness (slope) of the term structure. High slope factor values imply a steep yield curve, whereas low ones entail flat (or, possibly, downward) curves. In the third row, the weights of the curvature factor are presented. The name of this factor follows from the fact that the weights have a more pronounced effect on the middle range maturities of the curve. These concepts are graphically illustrated below.

Yield loadings on the spanned factors

Figure 3.1: Yield loadings on the spanned factors

To directly obtain the time series of the country-specific spanned factors, the user can simply use the Spanned_Factors() function as follows:

data('CM_Yields')
Economies <- c("China", "Brazil", "Mexico", "Uruguay")
N <- 3
SpaFact <- Spanned_Factors(Yields, Economies, N)

3.2 The P-dynamics estimation

As presented in Table 0.1, the dynamics of the risk factors under the \(P\)-measure evolve according to a VAR(1) model, which may be fully unrestricted (as in the case of the JPS-related models) or partially restricted (as in the GVAR and JLL frameworks). While the focus here is their integration into an ATSM setup, each specification can also be estimated independently to study dynamic systems. The usage of these models is illustrated below.

3.2.1 VAR

Using the VAR() function of this package requires simply selecting the set of risk factors for the desired estimated model. For instance, for the models JPS global and JPS multi, the estimation of the \(P\)-dynamics parameters is obtained as

data("CM_Factors")
PdynPara <- VAR(RiskFactors, VARtype= "unconstrained")

whereas the estimation of a JPS original model for China is

FactorsChina <- RiskFactors[1:7,]
PdynPara <- VAR(FactorsChina, VARtype= "unconstrained")

In both cases, the outputs generated are the vector of intercepts and both the feedback and variance-covariance matrices of an unconstrained VAR model.

3.2.2 GVAR

The GVAR() function is designed to estimate a first-order GVAR which is built from country-specific VARX(1,1,1) models. For a comprehensive discussion of GVAR models, see Chudik and Pesaran (2016).

The GVAR() function requires two key inputs: the number of country-specific spanned factors (N) and a set of supplementary inputs stored in the GVARinputs list. The former is composed by four elements:

  1. Economies: A character vector containing the names of the economies included in the system;

  2. GVAR list of risk factors: a list of risk factors sorted by country in addition to the global variables. See the outputs of the DatabasePrep() function;

  3. VARX type: a string-vector containing the desired estimated form of the VARX(1,1,1). Three possibilities are available. The “unconstrained” form estimates the model without any constrains, using standard OLS regressions for each model equation. The “constrained: Spanned Factors” form prevents foreign-spanned-factors to impact any domestic factor in the feedback matrix, whereas “constrained: ’ followed by the name of the risk factor restricts this same factor to be influenced only by its own lagged values and the lagged values of its own star variables. In the last two cases, the VARX(1,1,1) is estimated by restricted least squares.

GVARinputs <- list(Economies = Economies, GVARFactors = FactorsGVAR, VARXtype ="constrained: Inflation")
  1. Transition matrix: The estimation of a GVAR model requires defining a measure of interdependence among the countries of the economic system. This information is reported in the transition matrix, the entries of which reflect the degree of interconnection across two entities of this same economic system. The GVAR setups can be estimated using fixed or, starting from package’s version \(0.3.3\), time-varying interdependence weights.

Time-varying interdependence implies that the star factors are constructed by applying trade flow weights from the specific year to adjust the risk factors of the corresponding year. To employ this feature, users need to specify the transition matrix type as Time-varying and select the same specific date (year) for both the initial and final years within the transition matrix. This implies that the trade weights of this year are used for solving (link matrices) the GVAR system.

Below the illustration of the transition matrix is computed as the average of the cross-border trade flow weights for the period spanning the years from 2006 to 2019. Therefore, the degree of dependence across countries is assumed to be fixed over the entire sample span. Note that each row sums up to \(1\).

data("CM_Trade")
t_First <- "2006"
t_Last <-  "2019"
Economies <- c("China", "Brazil", "Mexico", "Uruguay")
type <- "Sample Mean"
W_gvar <- Transition_Matrix(t_First, t_Last, Economies, type, DataPath = NULL, TradeFlows)
print(W_gvar)
##             China    Brazil     Mexico     Uruguay
## China   0.0000000 0.6549066 0.31550095 0.029592464
## Brazil  0.8268799 0.0000000 0.12340661 0.049713473
## Mexico  0.8596078 0.1326284 0.00000000 0.007763753
## Uruguay 0.3811195 0.5497525 0.06912795 0.000000000

Having defined the form of the transition matrix, one can complete the GVARinputs list to estimate a GVAR(1) model. Note that the CheckInputs parameter is set as TRUE to perform a prior consistency check on the inputs provided in GVARinputs.

data("CM_Factors_GVAR")

GVARinputs <- list(Economies = Economies, GVARFactors = FactorsGVAR, VARXtype = "unconstrained", 
                   Wgvar = W_gvar)
N <- 3

GVARpara <- GVAR(GVARinputs, N, CheckInputs = TRUE)

A separate routine is provided for computing the foreign-specific factors (also commonly referred to as the star variables) used in the estimation of the VARX models.

data('CM_Factors')
StaFac <- StarFactors(RiskFactors, Economies, W_gvar)

3.2.3 JLL

Calculating the \(P\)-dynamics parameters in the form proposed by JLL (2015) requires the following inputs: (i) the time series of the risk factors in non-orthogonalized form; (ii) the number of country-specific spanned factors and (iii) the specification of the JLLinputs list, which includes the following elements:

  1. Economies: A character vector containing the names of the economies included in the system;

  2. Dominant Country: a string-vector containing the name of the economy which is assigned as the dominant country (applicable for the JLL original and JLL joint Sigma models) or None (applicable for the JLL No DomUnit);

  3. Wish the estimation of the sigmas matrices: this is a binary variable which assumes value equal to \(1\) if the user wishes the estimation of all JLL sigma matrices (i.e. variance-covariance and the Cholesky factorization matrices) and, \(0\) otherwise. Since this estimation is done numerically, its estimation can take several minutes;

  4. Sigma of the non-orthogonalized variance-covariance matrix: to save time, the user may provide the variance-covariance matrix from the non-orthogonalized dynamics. Otherwise, this input should be set as NULL.

  5. JLL type: a string-vector containing the label of the JLL model to be estimated according to the features described in Table 0.1.

One possible list of JLLinputs is as follows:

ModelType <- "JLL original"   
JLLinputs <- list(Economies = Economies, DomUnit = "China", WishSigmas = 1,  SigmaNonOrtho = NULL,
                  JLLModelType = ModelType)

As such, the \(P-\)dynamics dimension of a JLL-based setup can be computed as:

data("CM_Factors")
N <- 3
JLLpara <- JLL(RiskFactors, N, JLLinputs, CheckInputs = TRUE)

3.3 ATSM estimation

ATSM estimation involves optimizing the log-likelihood function by optimally selecting the model parameters. The optimization structure in this package is based on routines from the term structure package by Le and Singleton (2018). The ATSM otimization is carried out using the Optimization() function.

Broadly, the unspanned risk framework from JPS (2014) (and, therefore, all its multi-country extensions) requires the estimation parameter set consisting of 6 elements, namely: the risk-neutral long-run mean of the short rate (r0), the risk-neutral feedback matrix (K1XQ), the variance-covariance matrix (SSZ) from the VAR processes, the standard deviation of the errors from the portfolios of yields observed with error (se), in addition to the intercept (K0Z) and the feedback (K1Z) matrices of the physical dynamics.

The parameters K0Z and K1Z are estimated as part of the model’s \(P-\)dynamics and are known in closed form. Likewise, r0 and se have analytical solutions and can be factored out of the log-likelihood function. However, the remaining parameters (K1XQ and SSZ) require numerical estimation. Le and Singleton (2018) provides standardized routines (integrated into this package) to set effective initial values, facilitating the optimization process.

The MultiATSM package offers two optimization algorithms: fminunc and fminsearch. By default, both algorithms are run sequentially twice to ensure the model reaches the global optimum. Specifically in the default bootstrap setup, only fminunc is used to save time.

4 Examples of full implementation of ATSMs

This section presents some examples on how to use the MultiATSM package to fully implement ATSMs. The console displays messages to help the user track the progress of the code execution at each step. Further on, the functions of this package are used to replicate some of the results presented in the original papers of JPS (2014), CM (2023) and CM (2024). See the Paper Replication Vignette of this package for a detailed reproduction.

4.1 General template

########################################################################################################
#################################### USER INPUTS #######################################################
########################################################################################################
# A) Load database data
LoadData("CM_2024")

# B) GENERAL model inputs
ModelType <- "JPS multi" # available options: "JPS original", "JPS global", "GVAR single", "JPS multi",
                          #"GVAR multi", "JLL original", "JLL No DomUnit", "JLL joint Sigma".

Economies <- c("China", "Brazil", "Mexico") # Names of the economies from the economic system
GlobalVar <- c("Gl_Eco_Act")# Global Variables
DomVar <- c("Eco_Act", "Inflation") # Country-specific variables
N <- 2  # Number of spanned factors per country

t0_sample <- "01-05-2005" # Format: "dd-mm-yyyy"
tF_sample <- "01-12-2019" # Format: "dd-mm-yyyy"

OutputLabel <- "Test" # label of the model for saving the file
DataFreq <-"Monthly" # Frequency of the data

StatQ <- 0 # Wish to impose stationary condition for the eigenvalues of each country: YES: 1,NO:0

# B.1) SPECIFIC model inputs
#################################### GVAR-based models ##################################################
GVARlist <- list( VARXtype = "unconstrained", W_type = "Sample Mean", t_First_Wgvar = "2005",
                  t_Last_Wgvar = "2019")
# VARXtype: Available options "unconstrained" or "constrained" (VARX)
# W_type: Method to compute the transition matrix. Options:"Time-varying" or "Sample Mean"
# t_First_Wgvar: First year of the sample (transition matrix)
# t_Last_Wgvar:  Last year of the sample (transition matrix)
#################################### JLL-based models ###################################################
JLLlist <- list(DomUnit =  "China")
# DomUnit: name of the economy of the economic system, or "None" for the model "JLL No DomUnit"
###################################### BRW inputs  ######################################################
WishBC <- 0 # Wish to estimate the model with the bias correction method of BRW (2012): #YES: 1, NO:0
BRWlist <- within(list(flag_mean = TRUE, gamma = 0.05, N_iter = 250, B = 50, checkBRW = TRUE,
                       B_check = 1000),  N_burn <- round(N_iter * 0.15))
# flag_mean: TRUE = compute the mean; FALSE = compute the median
# gamma: Adjustment parameter
# N_iter:  Number of iteration to be conserved
# N_burn:  Number of iteration to be discarded
# B: Number of bootstrap samples
# checkBRW: wishes to perform closeness check: TRUE or FALSE
# B_check: If checkBRW is chosen as TRUE, then choose number of bootstrap samples used in the check

# C) Decide on Settings for numerical outputs
WishFPremia <- 1 # Wish to estimate the forward premia: YES: 1, NO:0
FPmatLim <- c(60,120) #  If the forward premia is desired, then choose the Min and max maturities of the
                      # forward premia. Otherwise set NA
Horiz <- 30
DesiredGraphs <- c("Fit", "IRF", "TermPremia") # "Fit", "IRF", "FEVD", "GIRF", "GFEVD", "TermPremia"
WishGraphRiskFac <- 0
WishGraphYields <- 1
WishOrthoJLLgraphs <- 0

# D) Bootstrap settings
WishBootstrap <- 1 #  YES: 1; No = 0.
BootList <- list(methodBS = 'bs', BlockLength = 4, ndraws = 5, pctg =  95)
# methodBS: bootstrap method. Available options: (i) 'bs' ; (ii) 'wild'; (iii) 'block'
# BlockLength: Block length, necessary input for the block bootstrap method
# ndraws: number of bootstrap draws
# pctg: confidence level

# E) Out-of-sample forecast
WishForecast <- 1 #  YES: 1; No = 0.
ForecastList <- list(ForHoriz = 12,  t0Sample = 1, t0Forecast = 162, ForType = "Rolling")
# ForHoriz: forecast horizon
# t0Sample:   initial sample date
# t0Forecast:  last sample date for the first forecast
# ForType: Available options are "Rolling" or "Expanding"

#########################################################################################################
############################### NO NEED TO MAKE CHANGES FROM HERE #######################################
#########################################################################################################

# 2) Minor preliminary work: get the sets of factor labels and  a vector of common maturities
FactorLabels <- LabFac(N, DomVar, GlobalVar, Economies, ModelType)
if(any(ModelType == c("GVAR single", "GVAR multi"))){ GVARlist$DataConnectedness <- TradeFlows}

# 3) Prepare the inputs of the likelihood function
ATSMInputs <- InputsForOpt(t0_sample, tF_sample, ModelType, Yields, GlobalMacroVar, DomesticMacroVar,
                           FactorLabels, Economies, DataFreq, GVARlist, JLLlist, WishBC, BRWlist)

# 4) Optimization of the ATSM (Point Estimates)
ModelParaList <- Optimization(ATSMInputs, StatQ, DataFreq, FactorLabels, Economies, ModelType)

# 5) Numerical and graphical outputs
# a) Prepare list of inputs for graphs and numerical outputs
InputsForOutputs <- InputsForOutputs(ModelType, Horiz, DesiredGraphs, OutputLabel, StatQ, DataFreq,
                                    WishGraphYields, WishGraphRiskFac, WishOrthoJLLgraphs, WishFPremia,
                                    FPmatLim, WishBootstrap, BootList, WishForecast, ForecastList)

# b) Fit, IRF, FEVD, GIRF, GFEVD, and Term Premia
NumericalOutputs <- NumOutputs(ModelType, ModelParaList, InputsForOutputs, FactorLabels, Economies)

# c) Confidence intervals (bootstrap analysis)
BootstrapAnalysis <- Bootstrap(ModelType, ModelParaList, NumericalOutputs, Economies, InputsForOutputs,
                               FactorLabels, JLLlist, GVARlist, WishBC, BRWlist)

# 6) Out-of-sample forecasting
Forecasts <- ForecastYields(ModelType, ModelParaList, InputsForOutputs, FactorLabels, Economies,
                            JLLlist, GVARlist, WishBC, BRWlist)

References

Bauer, Michael D, Glenn D Rudebusch, and Jing Cynthia Wu. 2012. “Correcting Estimation Bias in Dynamic Term Structure Models.” Journal of Business & Economic Statistics 30 (3): 454–67.
Candelon, Bertrand, and Rubens Moura. Forthcoming. “A Multicountry Model of the Term Structures of Interest Rates with a GVAR.” Journal of Financial Econometrics, Forthcoming.
———. 2023. “Sovereign Yield Curves and the COVID-19 in Emerging Markets.” Economic Modelling, 106453. https://doi.org/https://doi.org/10.1016/j.econmod.2023.106453.
Chudik, Alexander, and M Hashem Pesaran. 2016. “Theory and Practice of GVAR Modelling.” Journal of Economic Surveys 30 (1): 165–97.
Jotikasthira, Chotibhak, Anh Le, and Christian Lundblad. 2015. “Why Do Term Structures in Different Currencies Co-Move?” Journal of Financial Economics 115: 58–83.
Le, Anh, and Ken Singleton. 2018. “A Small Package of Matlab Routines for the Estimation of Some Term Structure Models.” Euro Area Business Cycle Network Training School - Term Structure Modelling.

mirror server hosted at Truenetwork, Russian Federation.