This document aims at providing general guidance on the use of the MultiATSM package available at the CRAN repository.
library(MultiATSM)
The MultiATSM package provides several model outputs from various single and multicountry affine term structure of interest models (ATSMs). All the frameworks of this package are based on the unspanned economic risk framework from Joslin, Priebsch, and Singleton (2014) (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 economic and financial variables (unspanned factors).
Due to the peculiar features of the JPS specification, an efficient estimation of the parameters governing the riskneutral (\(Q\)measure) and the physical (\(P\)measure) probability measures can be carried out rather independently. The only exception is the variancecovariance matrix (sigma) term which is a common element to both the \(P\) and the \(Q\) density functions.
In its current version, the MultiATSM package can generate the outputs of 8 different classes of ATSMs. More specifically, the MultiATSM includes models in which the estimation is done on a countrybycountry basis  as in JPS (2014)  or jointly for all the countries of the economic system  as in Jotikasthira, Le, and Lundblad (2015) (JLL, 2015) and Candelon and Moura (2021) (CM, 2021). 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.
Pdynamics

Qdynamics

Sigma matrix estimation

Dominant Country



Individual

Joint

Individual

Joint

P only

P and Q


Unrestricted

Restricted

Unrestricted

Restricted


JLL  GVAR  
Unrestricted VAR  
JPS  x  x  x  
JPS jointP  x  x  x  
VAR jointQ  x  x  x  
Restricted VAR (GVAR)  
GVAR sepQ  x  x  x  
GVAR jointQ  x  x  x  
Restricted VAR (JLL)  
JLL original  x  x  x  x  
JLL NoDomUnit  x  x  x  
JLL jointSigma  x  x  x  x 
Some aspects of the multicountry 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 NoDomUnit”) and the estimation of sigma under both the \(P\) and \(Q\) measures (“JLL jointSigma”), as in the standard JPS (2014) model. As for the remaining multicountry 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 jointQ” is the one presented in CM (2021).
In what follows, the focus will be devoted to describe the various pieces that are necessary to implement ATSMs. Specifically, Section 1 describes the dataset 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. To ease the exposition, throughout the next sections, the database used by CM (2021) is employed to illustrate the use of the various functions available in this package.
The MultiATSM package contains the four datasets used in CM (2021). The first set of data comprises several time series of zerocoupon bond yields from four emerging markets: China, Brazil, Mexico, and Uruguay. It is worth noting that this package requires (i) for estimation purposes, the maturities of the bond yields to be the same for all countries (although the function DataForEstimation handles different maturities across countries as inputs, the outputs generated by this same function are bond yields of the same maturities for all the economies); (ii) bond yields to be expressed in percentage terms (and not in basis points) per annum. The MultiATSM package does not support a routine to bootstrap zerocoupon yields from coupon bonds. This data manipulation procedure must be handled by the user herself, if necessary.
data('CM_Yields')
The second group of data concerns the time series of the risk factors. Specifically, along the terminology defined in JPS (2014), this dataset contains (i) countryspecific spanned factors (denoted by level, slope, and curvature  see Section 3.1 for a more detailed description) and (ii) an array of countryspecific and global unspanned factors (namely, some measure of economic growth and inflation). Similarly to the case of the bond yield data, the measures of economic and financial variables must be constructed by the user.
data('CM_Factors')
The two last blocks of data are necessary for the estimation of the GVARbased models. The trade flows database 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 countryspecific 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')
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 GVARbased 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,
< "20060901" # Format "yyyymmdd"
Initial_Date < "20190101" # Format "yyyymmdd"
Final_Date < "Monthly"
DataFrequency < c("GBC", "VIX") # Global Variables
GlobalVar < c("Eco_Act", "Inflation", "Com_Prices", "Exc_Rates") # Domestic variables
DomVar < 3 # Number of spanned factors per country
N < c("China", "Mexico", "Uruguay", "Brazil", "Russia")
Economies < "JPS" ModelType
Based on these inputs, one can construct the variable ZZfull which contains the complete set of the model risk factors.
< LabFac(N, DomVar, GlobalVar, Economies, ModelType)
FactorLabels <DataForEstimation(Initial_Date, Final_Date, Economies, N, FactorLabels, ModelType, DataFrequency) ZZfull
In order to estimate any ATSM of this package, the user needs to specify several general model inputs, namely:
One possible example of the basic model inputs is
< "JPS"
ModelType < 1 # 1 = estimate model with bias correction; 0 = estimate model without bias correction
BiasCorrection < "Monthly"
DataFrequency < "Month" # Available options are: "Month" or "Year".
UnitMatYields < c("China", "Brazil", "Mexico", "Uruguay")
Economies < 3 # number of spanned factors per country
N < c("GBC", "CPI_OECD") # Global variables
GlobalVar < c("Eco_Act", "Inflation") # Domestic variables
DomVar < c(0.25, 0.5, 1, 3, 5, 10) # vector of maturities
mat < 0 # 1 = set stationarity condition under the Q; 0 = no stationarity condition
StationarityUnderQ < 1 # Wish to estimate the forward premia: 1= Yes; 0= No
WishForwardPremia < c(60,120) # maturty of the loan starts in 60 months and ends in 120 months in the future
FPmatLim < "Model_demo" # output label OutputLabel
Some additional inputs are required if the user intends to estimate the GVARATSM or JLLATSM related setups. The extra inputs should be stored in separate lists for each model for convenience. To assist the user in executing this task, one can use the ListModelInputs function. Otherwise, the GVARinputs and JLLinputs constructs can be formed manually as specified below.
To GVAR models, the set of supplementary inputs include:
< list()
GVARinputs $Economies < Economies
GVARinputs$GVARFactors < FactorsGVAR
GVARinputs$VARXtype < "constrained: Inflation" GVARinputs
Furthermore, the estimation of the GVAR requires the specification of the necessary inputs to build the transition matrix (see Section 3.2.2 for more details). One example of this list of inputs is
< "2000" # First year of the sample
t_First < "2015" # Last year of the sample
t_Last < 'Sample Mean' W_type
Concerning the JLLATSM frameworks, the list of inputs includes:
One possible list of JLL inputs is as follows:
< list()
JLLinputs < "JLL original"
ModelType $Economies < Economies
JLLinputs$DomUnit < "China"
JLLinputs$WishSigmas < 1
JLLinputs$SigmaNonOrtho < NULL
JLLinputs$JLLModelType < ModelType JLLinputs
In an influential paper, BRW (2012) have shown that the estimates from traditional ATSMs can be severely biased due to the typical smallsample size used in these studies. As result, such models may produce unreasonably stable expected future shortterm interest, therefore distorting the term premia estimates for longmaturity bonds. To circumvent this problem, BRW (2012) propose a bootstrapbased 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 accomodates 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:
< TRUE # TRUE = compute the mean; FALSE = compute the median
flag_mean < 0.2 # Adjustment parameter
gamma < 500 # Number of iteration to be conserved
N_iter < N_iter*0.15 # Number of iteration to be discarded
N_burn < 50 # Number of bootstrap samples
B < 1 # Closeness check
checkBRW < 1000 # Number of bootstrap samples used in the closeness check B_check
Once the model parameters from the ATSM have been estimated, the MultiATSM package enables the numerical and graphical compilation of the following additional outputs:
For the IRFs, GIRFs, FEVDs or GFEVDs, a horizon of analysis has to be specified, e.g.:
< 100 Horiz
For the graphical outputs, the user must indicate the desired types of graphs in a stringbased vector:
< c("Fit", "GIRF", "GFEVD") # Available options are: "Fit", "IRF", "FEVD", "GIRF",
DesiredGraphs # "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
< 0 # YES: 1; No = 0.
WishGraphRiskFac < 1 # YES: 1; No = 0.
WishGraphYields < 0 # YES: 1; No = 0. WishOrthoJLLgraphs
The function InputsForOutputs can provide some guidance for customizing the features of the wished outputs. Conditional to these settings, individual folders are created at your temporary directory to store the different types of the desired graphical outputs.
If the user intends to generate confidence bands through some bootstrap procedure, an additional list of inputs is required. Specifically:
< list()
Bootlist $methodBS < 'block'
Bootlist$BlockLength < 4
Bootlist$ndraws < 3
Bootlist$pctg < 95 Bootlist
To perform outofsample forecasts of bond yields, the following listbased features have to be detailed:
< list()
ForecastList $ForHoriz < 12 # forecast horizon
ForecastList$t0Sample < 1 # initial sample date
ForecastList$t0Forecast < 70 # last sample date for the first forecast ForecastList
Having gathered bond yields and other economic time series data, the ATSM estimation is carried out in three steps. Firstly, one needs to provide the number of countryspecific spanned factors to be included in the global ATSM. Secondly, it is decided on the form of the risk factor dynamics under the \(P\)measure. Finally, the user needs to select the general features for the model optimization.
The spanned factors are yieldrelated variables that are used to fit the crosssection 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 countryspecific columnvector 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:
< pca_weights_one_country(Yields, Economy = "Uruguay") w
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.
To directly obtain the time series of the countryspecific spanned factors, the user can simply use the Spanned_Factors function as follows:
data('CM_Yields')
< c("China", "Brazil", "Mexico", "Uruguay")
Economies < 2
N < Spanned_Factors(Yields, Economies, N) SpaFact
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 JPSrelated models) or somewhat restricted (as in the GVAR and JLL frameworks). Below, the usage of each of these dimensions are illustrated.
Using the VAR function of this package requires simply selecting the appropriated set of risk factors for the desired estimated model. For instance, for the models JPS jointP and VAR jointQ, the estimation of the \(P\)dynamics parameters is obtained as
data("CM_Factors")
< VAR(RiskFactors, VARtype= "unconstrained") PdynPara
whereas the estimation of a JPS model for China is
< RiskFactors[1:7,]
FactorsChina < VAR(FactorsChina, VARtype= "unconstrained") PdynPara
In both cases, the outputs generated are the vector of intercepts and both the feedback and variancecovariance matrices.
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 of two entities of this same economic system. In this package, the illustration of the transition matrix is based on the average of the crossborder trade flow weights for the period spanning the years from 2006 to 2019. Note that each row sums up to 1.
data("CM_Trade")
< "2006"
t_First < "2019"
t_Last < c("China", "Brazil", "Mexico", "Uruguay")
Economies < "Sample Mean"
type < Transition_Matrix(t_First, t_Last, Economies, type, DataPath = NULL, TradeFlows)
W_gvar 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
Starting from package version \(0.3.3\), the GVAR setups can be estimated incorporating timevarying interdependence weights. This entails 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 Full Sample 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. Taking reference from the variable names in the previous example, an illustration could be set as follows:
< "2019"
t_First < "2019"
t_Last < "Full Sample" type
Having defined the form of the transition matrix, one can complete the GVARinputs variable along the lines discussed in Section 2.1.1.
data("CM_Factors_GVAR")
< list()
GVARinputs $Economies < Economies
GVARinputs$GVARFactors < FactorsGVAR
GVARinputs$VARXtype < "unconstrained"
GVARinputs$Wgvar < W_gvar
GVARinputs
< 3
N
< GVAR(GVARinputs, N) GVARpara
A separate routine is provided for computing the foreignspecific factors (also commonly referred to as the star variables) used in the estimation of the VARX models.
data('CM_Factors')
< StarFactors(RiskFactors, Economies, W_gvar) StaFac
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 nonorthogonalized form; (ii) the number of countryspecific spanned factors and (iii) the specification of the JLLinputs as presented in Section 2.1.1. See, for instance:
data("CM_Factors")
< 3
N < list()
JLLinputs < "JLL original"
ModelType $Economies < Economies
JLLinputs$DomUnit < "China"
JLLinputs$WishSigmas < 1
JLLinputs$SigmaNonOrtho < NULL
JLLinputs$JLLModelType < ModelType
JLLinputs< JLL(RiskFactors, N, JLLinputs) JLLpara
The estimation of ATSM involves defining the model inputs from the loglikelihood function and, subsequently, the parameters used in its optimization process. The structure proposed in this part of the code is in a great extent based on the term structure package by Le and Singleton (2018).
For the sake of simplicity, one illustrates the construction of a loglikelihood function based on a VAR jointQ model. For both the JLL and GVARbased models, one must further specify the JLLinputs or GVARinputs along the lines described in the Section 2.1.1.
# Inputs to be specified by the user
data("CM_Yields")
data("CM_Factors")
< "VAR jointQ"
ModelType < Yields
Yields < RiskFactors
ZZ < c("China", "Brazil", "Mexico", "Uruguay")
Economies < Maturities(Yields, Economies, UnitYields = "Month")
mat < "Monthly"
DataFrequency < c("GBC", "CPI_OECD") # Global variables
GlobalVar < c("Eco_Act", "Inflation") # Domestic variables
DomVar < 3 # Number of countryspecific spanned factors
N
# Generate the "Factor Labels" list (necessary preliminarily step)
< LabFac(N, DomVar, GlobalVar, Economies, ModelType)
FactorLabels
# Prepare the inputs for logLikelihood function
< InputsForMLEdensity(ModelType, Yields, ZZ, FactorLabels, mat, Economies, DataFrequency)
ATSMInputs
# LogLikelihood function
< Functionf(ATSMInputs, Economies, mat, DataFrequency, FactorLabels, ModelType) f
JPS (2014) requires the estimation of a set of parameters containing 6 elements, namely: the riskneutral longrun mean of the short rate (r0), the riskneutral feedback matrix (K1XQ), the variancecovariance 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. Each of these parameters must be cast in an individual list that should contain the (i) the starting value of the parameter (if any); (ii) the variable label followed by a ‘:’ and a type of constraint; (iii) a lower bound (if any), and (iv) an upper bound (if any). The variable labels of r0, se, K0Z and K1Z should be preceded by the symbol @ as a manner to account for the fact that the solution of these parameters are known in closedform. For the remaining ones (K1XQ and SSZ), Le and Singleton (2018) provide standardized routines (already incorporated in this package) to set good initial values so that the optimization process runs fast.
The type of constraint to be set for the parameters r0, se, K0Z and K1Z is typically bounded and are used for bounded matrices. For K1XQ and SSZ, the MultiATSM package currently provides the following options:
One example for the list of parameters specification is
< list(NULL, "K1XQ: Jordan" , NULL , NULL)
K1XQinputs < list(NULL, "SSZ: psd", NULL, NULL)
SSZinputs < list(NULL, "@r0: bounded", NULL, NULL)
r0inputs < list(NULL, "@se: bounded", 1e6, NULL)
seinputs < list(NULL, "@K0Z: bounded", NULL, NULL)
K0Zinputs< list(NULL, "@K1Z: bounded", NULL, NULL) K1Zinputs
To complete the optimization setting, the user needs to specify the level of convergence tolerance (usually, 1e4 is a reasonable value) and the vector OptRun. The first element of this vector must be filled by the word ‘iter off’, if the user wishes to switch off the printouts of the numerical optimization routines, or simply by ‘iter’ otherwise. The second element of the vector concerns the algorithm that is used in the optimization: the option ‘fminunc only’ only uses fminunc, whereas ‘fminsearch only’ only applies fminsearch. If OptRun is formed exclusively by ‘iter off’, then both fminunc and fminsearch are employed in the optimization.
This section presents some examples on how to use the MultiATSM package to fully implement ATSMs. Further on, the functions of this package are used to replicate some of the results presented in the original papers of JPS (2014) and CM (2021). See the Paper Replication Vignette of this package for a detailed reproduction.
########################################################################################################
#################################### USER INPUTS #######################################################
########################################################################################################
# A) Load database data
data("CM_Factors")
data('CM_Factors_GVAR')
data('CM_Trade')
data('CM_Yields')
# B) Decide on general model inputs
< "VAR jointQ" # available options are "JPS", "JPS jointP", "GVAR sepQ", "VAR jointQ",
ModelType #"GVAR jointQ", "JLL original", "JLL NoDomUnit", "JLL jointSigma".
< 0 # Wish to impose stationary condition for the eigenvalues of each country:
StationarityUnderQ #YES: 1,NO:0
< 1 # Wish to estimate the model with the bias correction method of BRW (2012):
BiasCorrection #YES: 1, NO:0
< 1 # Wish to estimate the forward premia: YES: 1, NO:0
WishForwardPremia < c(60,120) # If the forward premia is desired, then choose the Min and max maturities of the
FPmatLim # forward premia. Otherwise set NA
< c("China", "Brazil", "Mexico", "Uruguay") # Names of the economies from the economic system
Economies < c("GBC", "CPI_OECD") # Global Variables
GlobalVar < c("Eco_Act", "Inflation") # Countryspecific variables
DomVar
< 3 # Number of spanned factors per country
N
< "Test" # label of the model for saving the file
OutputLabel < "Monthly" # Frequency of the data
DataFrequency < "Month" # bond yields timeunit. Available options are "Month" or "Year"
UnitMatYields
# B.1) Decide on specific model inputs
#################################### GVARbased models ##################################################
< "2004" # First year of the sample (transition matrix)
t_First_Wgvar < "2019" # Last year of the sample (transition matrix)
t_Last_Wgvar < 'Sample Mean' # Method to compute the transition matrix
W_type < "unconstrained" # (i) "unconstrained" or (ii) ""constrained" (VARX)
VARXtype #################################### JLLbased models ###################################################
< "China"
DomUnit < 1 # Sigma matrix is estimated within the "InputsForMLEdensity" function
WishSigmas < NULL
SigmaNonOrtho < ModelType
JLLModelType ###################################### BRW inputs ######################################################
< TRUE # TRUE = compute the mean; FALSE = compute the median
flag_mean < 0.2 # Adjustment parameter
gamma < 500 # Number of iteration to be conserved
N_iter < N_iter*0.15 # Number of iteration to be discarded
N_burn < 50 # Number of bootstrap samples
B < 1
checkBRW < 1000 #
B_check #########################################################################################################
# C) Decide on Settings for numerical outputs
< 50
Horiz < c("Fit", "IRF", "FEVD") # "Fit", "IRF", "FEVD", "GIRF", "GFEVD", "TermPremia"
DesiredGraphs < 0
WishGraphRiskFac < 1
WishGraphYields < 0
WishOrthoJLLgraphs
# D) Bootstrao settings
< 1 # YES: 1; No = 0.
WishBootstrap < list()
Bootlist $methodBS < 'bs' # (i) 'bs' ; (ii) 'wild'; (iii) 'block'
Bootlist$BlockLength < 4 # necessary input if one chooses the block bootstrap
Bootlist$ndraws < 5
Bootlist$pctg < 95 # confidence level
Bootlist
# E) Outofsample forecast
< 1 # YES: 1; No = 0.
WishForecast < list()
ForecastList $ForHoriz < 12 # forecast horizon
ForecastList$t0Sample < 1 # initial sample date
ForecastList$t0Forecast < 145 # last sample date for the first forecast
ForecastList
#########################################################################################################
############################### NO NEED TO MAKE CHANGES FROM HERE #######################################
#########################################################################################################
# 2) Minor preliminary work
< length(Economies)
C < LabFac(N, DomVar,GlobalVar, Economies, ModelType) # Generate the set of labels
FactorLabels < RiskFactors
ZZ if(any(ModelType == c("GVAR sepQ", "GVAR jointQ"))){
< list()
Data $GVARFactors < FactorsGVAR}
Data< Maturities(Yields, Economies, UnitYields = UnitMatYields)
mat
# 2.1) Generate GVARinputs, JLLinputs and BRWinputs
< ListModelInputs(ModelType, Data, Economies, VARXtype, t_First_Wgvar, t_Last_Wgvar, W_type,
ModInputs
DomUnit, WishSigmas, SigmaNonOrtho, BiasCorrection, flag_mean, gamma, N_iter,
N_burn, B, checkBRW, B_check)
< ModInputs$GVARinputs
GVARinputs < ModInputs$JLLinputs
JLLinputs < ModInputs$BRWinputs
BRWinputs
# 3) Prepare the inputs of the likelihood function
< list()
ModelParaList for (i in 1:C){
if (( any(ModelType ==c("GVAR jointQ", "VAR jointQ","JLL original", "JLL NoDomUnit","JLL jointSigma")))
& i >1 ){break}
# 3.1) Compute the inputs that go directly into the loglikelihood function
< InputsForMLEdensity(ModelType, Yields, ZZ, FactorLabels, mat, Economies, DataFrequency,
ATSMInputs
JLLinputs, GVARinputs, BRWinputs)
# 3.2) Initial guesses for Variables that will be concentrared out of from the loglikelihood function
< ATSMInputs$K1XQ
K1XQ if (any(ModelType == c("JLL original", "JLL NoDomUnit"))){ SSZ < NULL} else{SSZ < ATSMInputs$SSZ}
# 4) Build the objective function
< Functionf(ATSMInputs, Economies, mat, DataFrequency, FactorLabels, ModelType)
f
# 5) Set the optimization settings
< ParaLabels(ModelType, StationarityUnderQ)
VarLab
< list()
varargin $K1XQ <list(K1XQ, VarLab[[ModelType]][["K1XQ"]] , NULL , NULL)
varargin$SSZ < list(SSZ, VarLab[[ModelType]][["SSZ"]], NULL, NULL)
varargin$r0 < list(NULL, VarLab[[ModelType]][["r0"]], NULL, NULL)
varargin$se < list(NULL, VarLab[[ModelType]][["se"]], 1e6, NULL)
varargin$K0Z < list(NULL, VarLab[[ModelType]][["K0Z"]], NULL, NULL)
varargin$K1Z < list(NULL, VarLab[[ModelType]][["K1Z"]], NULL, NULL)
varargin$OptRun < c("iter off")
varargin
< c('Value', 'Label', 'LB', 'UB') # Elements of each parameter
LabelVarfor (d in 1:(length(varargin)1)){ names(varargin[[d]]) < LabelVar}
< 1e4
tol
# 6) Optimization of the model
if (ModelType == 'JPS'  ModelType == 'JPS jointP'  ModelType == "GVAR sepQ"){
< Optimization(f, tol, varargin, FactorLabels,
ModelParaList[[ModelType]][[Economies[i]]] $Summary
Economies, ModelType)else{
}< Optimization(f, tol, varargin, FactorLabels, Economies, ModelType,
ModelParaList[[ModelType]] $Summary}
JLLinputs, GVARinputs)
}
# 7) Numerical and graphical outputs
< InputsForOutputs(ModelType, Horiz, DesiredGraphs, OutputLabel, StationarityUnderQ,
InputsForOutputs
UnitMatYields, WishGraphYields, WishGraphRiskFac, WishOrthoJLLgraphs,
WishForwardPremia, FPmatLim, WishBootstrap, Bootlist, WishForecast,
ForecastList)# A) Fit, IRF, FEVD, GIRF, GFEVD, and Term Premia
< NumOutputs(ModelType, ModelParaList, InputsForOutputs, FactorLabels, Economies)
NumericalOutputs
# B) Bootstrap
< Bootstrap(ModelType, ModelParaList, NumericalOutputs, mat, Economies, InputsForOutputs,
Bootstrap
FactorLabels, DataFrequency, varargin, JLLinputs, GVARinputs, BRWinputs)
# C) Outofsample forecasting
< ForecastYields(ModelType, ModelParaList, InputsForOutputs, FactorLabels, Economies,
Forecasts DataFrequency, JLLinputs, GVARinputs, BRWinputs)