65
State Space Modeling in Macroeconomics and Finance Using SsfPack in S+FinMetrics Eric Zivot, Jiahui Wang and Siem-Jan Koopman August 4, 2002 This version: October 10, 2002 Abstract This paper surveys some common state space models used in macroeco- nomics and nance and shows how to specify and estimate these models using the SsfPack algorithms implemented in the S-PLUS module S+FinMetrics. Examples include recursive regression models, time varying parameter models, exact ARMA models and calculation of the Beveridge-Nelson decomposition, unobserved components models, stochastic volatility models, and ane term structure models. 1 Introduction State space modeling in macroeconomics and nance has become widespread over the last decade. Textbook treatments of state space models with applications in eco- nomics and nance are now common and are given in Harvey (1989, 1993), Hamilton (1994a), West and Harrison (1997), and Kim and Nelson (1999), Shumway and Stof- fer (2000), Durbin and Koopman (2001), and Chan (2002). However, until recently there has not been much exible software for the statistical analysis of general models in state space form. Currently, the most modern set of state space modeling tools are available in SsfPack, developed by Siem-Jan Koopman 1 . SsfPack is a suite of C This paper was prepared for the Academy Colloquium Masterclass on State Space and Unob- served Components Models in honour of Professor J. Durbin , sponsored by the Royal Netherlands Academy of Arts and Sciences. Our thanks go to Siem-Jan Koopman for inviting us to participate in this program. Financial support from the Royal Netherlands Academy of Arts and Sciences, and from the Gary Waterman Distinguished Scholar Fund at the University of Washington is gratefully acknowledged. Contact information: [email protected] and [email protected]. Updates to the pa- per, including data and programs used in this paper, are available at the second author’s website: http://faculty.washington.edu/ezivot/ezresearch.htm 1 Information about Ssfpack can be found at http://www.ssfpack.com. 1

State Space Survey

Embed Size (px)

DESCRIPTION

State-space modelling; Kalman filter estimation

Citation preview

Page 1: State Space Survey

State Space Modeling in Macroeconomics andFinance Using SsfPack in S+FinMetrics∗

Eric Zivot, Jiahui Wang and Siem-Jan Koopman†

August 4, 2002This version: October 10, 2002

Abstract

This paper surveys some common state space models used in macroeco-nomics and finance and shows how to specify and estimate these models usingthe SsfPack algorithms implemented in the S-PLUS module S+FinMetrics.Examples include recursive regression models, time varying parameter models,exact ARMA models and calculation of the Beveridge-Nelson decomposition,unobserved components models, stochastic volatility models, and affine termstructure models.

1 Introduction

State space modeling in macroeconomics and finance has become widespread overthe last decade. Textbook treatments of state space models with applications in eco-nomics and finance are now common and are given in Harvey (1989, 1993), Hamilton(1994a), West and Harrison (1997), and Kim and Nelson (1999), Shumway and Stof-fer (2000), Durbin and Koopman (2001), and Chan (2002). However, until recentlythere has not been much flexible software for the statistical analysis of general modelsin state space form. Currently, the most modern set of state space modeling toolsare available in SsfPack, developed by Siem-Jan Koopman1. SsfPack is a suite of C

∗This paper was prepared for the Academy Colloquium Masterclass on State Space and Unob-served Components Models in honour of Professor J. Durbin , sponsored by the Royal NetherlandsAcademy of Arts and Sciences. Our thanks go to Siem-Jan Koopman for inviting us to participatein this program. Financial support from the Royal Netherlands Academy of Arts and Sciences, andfrom the Gary Waterman Distinguished Scholar Fund at the University of Washington is gratefullyacknowledged.

†Contact information: [email protected] and [email protected]. Updates to the pa-per, including data and programs used in this paper, are available at the second author’s website:http://faculty.washington.edu/ezivot/ezresearch.htm

1Information about Ssfpack can be found at http://www.ssfpack.com.

1

Page 2: State Space Survey

routines for carrying out computations involving the statistical analysis of univariateand multivariate models in state space form. The routines allow for a variety of statespace forms from simple time invariant models to complicated time-varying models.Functions are available to put standard models like ARMA and spline models instate space form. General routines are available for filtering, smoothing, simulationsmoothing, likelihood evaluation, forecasting and signal extraction. Full details ofthe statistical analysis is provided in Durbin and Koopman (2001), and the reader isreferred to the papers by Koopman, Shephard and Doornik (1999, 2001) for technicaldetails on the algorithms used in the SsfPack functions.The SsfPack routines are implemented in Ox and in Insightful’s S-PLUS module

S+FinMetrics, and are based on the algorithms in SsfPack version 3.02. The im-plementation of the SsfPack functions in Ox is described in Koopman, Shephard andDoornik (1999), and the implementation of the SsfPack functions in S+FinMetricsis described in chapter fourteen of Zivot and Wang (2003). This paper gives a selectedsurvey of state space modeling in economics and finance utilizing the SsfPack/S+FinMetricsfunctions.This paper is organized as follows. Section two describes the general state space

model and state space representation required for the S+FinMetrics/SsfPack statespace functions. Subsections describe the various S+FinMetrics/SsfPack functionsfor putting common time series models into state space form. The process of sim-ulating observations from a given state space model is also covered. Section threesummarizes the main algorithms used for the analysis of state space models. These in-clude the Kalman filter, Kalman smoother, moment smoothing, disturbance smooth-ing and forecasting. Estimation of the unknown parameters in a state space model isdescribed in Section four. Section five gives several examples of state space modelingin economics and finance. These include recursive least squares estimation, estima-tion and analysis of time varying parameter models, exact ARMA estimation andthe Beveridge-Nelson decomposition, estimation and analysis of unobserved compo-nent models, the estimation of a stochastic volatility model, and the estimation andanalysis of some common affine term structure models.The following typographical conventions are used in this paper. The typewriter

font is used for S-PLUS functions, the output of S-PLUS functions and examples ofS-PLUS sessions. S-PLUS objects of a specified class are expressed in typewriterfont enclosed in quotations “ ”. For example, the S-PLUS function timeSeriescreates objects of class “timeSeries”. Displayed S-PLUS commands are shown withthe prompt character >. For example

2Ox is a matrix programming language, developed by Jurgen Doornik. Information aboutOx is available at http://www.nuff.ox.ac.uk/users/doornik/. S+FinMetrics is an S-PLUS mod-ule for the analysis of economic and financial time series. It was conceived by the authorsand Doug Martin, and developed at Insightful, Inc. Its use and functionality is described indetail in Zivot and Wang (2003). Further information about S+FinMetrics can be found athttp://www.insightful.com/products/default.asp.

2

Page 3: State Space Survey

> summary(ols.fit)

S-PLUS commands that require more than one line of input are displayed with thecontinuation prompt indicated by + or Continue string:.

2 State Space Representation

Many dynamic time series models in economics and finance may be represented instate space form. Some common examples are ARMAmodels, time-varying regressionmodels, dynamic linear models with unobserved components, discrete versions ofcontinuous time diffusion processes, stochastic volatility models, non-parametric andspline regressions. The linear Gaussian state space model in S+FinMetrics/SsfPackis represented as the system of equations

αt+1m×1

= dtm×1

+ Ttm×m

· αtm×1

+Htm×r

· ηtr×1

(1)

θtN×1

= ctN×1

+ ZtN×m

·αtm×1

(2)

ytN×1

= θtN×1

+ GtN×N

· εtN×1

(3)

where t = 1, . . . , n and

α1 ˜N(a,P), (4)

ηt ˜iid N(0, Ir) (5)

εt ˜iid N(0, IN) (6)

and it is assumed thatE[εtη

0t] = 0

In (4), a and P are fixed and known but that can be generalized. The state vector αt

contains unobserved stochastic processes and unknown fixed effects and the transitionequation (1) describes the evolution of the state vector over time using a first orderMarkov structure. The measurement equation (3) describes the vector of observationsyt in terms of the state vector αt through the signal θt and a vector of disturbancesεt. It is assumed that the innovations in the transition equation and the innovationsin the measurement equation are independent, but this assumption can be relaxed.The deterministic matrices Tt,Zt,Ht,Gt are called system matrices and are usuallysparse selection matrices. The vectors dt and ct contain fixed components and maybe used to incorporate known effects or known patterns into the model; otherwisethey are equal to zero.The representation of the transition equation (1) is somewhat non-standard be-

cause the time index on the innovation variance is at t and not t+1. A more common

3

Page 4: State Space Survey

representation of the transition equation, utilized by Harvey (1989, 1993), Hamilton(1994), Kim and Nelson (1999) and others, is

αt= dt+Ttαt−1+Htηt (7)

This representation in (1) simplifies the implementation of many of the recursivealgorithms associated with the Kalman filter and smoother. The notation can beconfusing when certain models need to put in this form, but it is always possible todo it although the interpretation of some state space quantities may be a bit differentthan those in (7).The state space model (1) - (6) may be compactly expressed asµ

αt+1

yt

¶= δt

(m+N)×1+ Φt(m+N)×m

· αtm×1

+ ut(m+N)×1

, (8)

α1 ˜N(a,P) (9)

ut ˜iid N(0,Ωt) (10)

where

δt =

µdt

ct

¶, Φt =

µTt

Zt

¶, ut =

µHtηt

Gtεt

¶, Ωt =

µHtH

0t 0

0 GtG0t

¶The initial value parameters are summarized in the (m+ 1)×m matrix

Σ =

µPa0

¶(11)

For multivariate models, i.e. N > 1, it is assumed that the N × N matrix GtG0t is

diagonal.

2.1 Initial Conditions

The variance matrix P of the initial state vector α1 is assumed to be of the form

P = P∗ + κP∞ (12)

where P∞ and P∗ are symmetric m×m matrices with ranks r∞ and r∗, respectively,and κ is a large scalar value, e.g. κ = 107. The matrix P∗ captures the covariancestructure of the stationary components in the initial state vector, and the matrix P∞is used to specify the initial variance matrix for nonstationary components. Whenthe ith diagonal element of P∞ is negative, the corresponding ith column and rowof P∗ are assumed to be zero, and the corresponding row and column of P∞ willbe taken into consideration. When some elements of state vector are nonstationary,the S+FinMetrics/SsfPack algorithms implement an “exact diffuse prior” approachas described in Durbin and Koopman (2001) and Koopman, Shephard and Doornik(2001).

4

Page 5: State Space Survey

2.2 State Space Representation in S+FinMetrics/SsfPack

State space models in S+FinMetrics/SsfPack utilize the compact representation (8)with initial value information (11). The following examples describe the specificationof a state space model for use in the S+FinMetrics/SsfPack state space modelingfunctions.

Example 1 State space representation of the local level model

Consider the following simple model for the stochastic evolution of the logarithmof an asset price yt

αt+1 = αt + η∗t , η∗t ˜iid N(0, σ2η) (13)

yt = αt + ε∗t , ε∗t ˜iid N(0, σ2ε) (14)

α1 ˜N(a, P ) (15)

where it is assumed that E[ε∗tη∗t ] = 0. In the above model, the observed asset price yt

is the sum of two unobserved components, αt and ε∗t . The component αt is the statevariable and represents the fundamental value (signal) of the asset. The transitionequation (13) shows that the fundamental values evolve according to a random walk.The component ε∗t represents random deviations (noise) from the fundamental valuethat are assumed to be independent from the innovations to αt. The strength of thesignal in the fundamental value relative to the random deviation is measured by thesignal-to-noise ratio of variances q = σ2η/σ

2ε. The model (13) - (15) is called the

random walk plus noise model, signal plus noise model or the local level model.3

The state space form (8) of the local level model has time invariant parameters

δ =

µ00

¶,Φ =

µ11

¶,Ω =

µσ2η 00 σ2ε

¶(16)

with errors σηηt = η∗t and σεεt = ε∗t . Since the state variable αt is I(1), the uncondi-tional distribution of the initial state α1 doesn’t have finite variance. In this case, itis customary to set a = E[α1] = 0 and P = var(α1) to some large positive number,e.g. P = 107, in (15) to reflect that no prior information is available. Using (12),the initial variance is specified with P∗ = 0 and P∞ = 1. Therefore, the initial statematrix (11) for the local level model has the form

Σ =

µ −10

¶(17)

where −1 implies that P∞ = 1.In S+FinMetrics/SsfPack, a state space model is specified by creating either a list

variable with components giving the minimum components necessary for describing

3A detailed technical analysis of this model is given in Durbin and Koopman (2001), chapter 2.

5

Page 6: State Space Survey

State Space Parameter List Component Nameδ mDelta

Φ mPhi

Ω mOmega

Σ mSigma

Table 1: S+FinMetrics/SsfPack state space form list components

a particular state space form or by creating an “ssf” object. To illustrate, considercreating a list variable containing the state space parameters in (16)-(17), with ση =0.5 and σε = 1

> sigma.e = 1

> sigma.n = 0.5

> a1 = 0

> P1 = -1

> ssf.ll.list = list(mPhi=as.matrix(c(1,1)),

+ mOmega=diag(c(sigma.n^2,sigma.e^2)),

+ mSigma=as.matrix(c(P1,a1)))

> ssf.ll.list

$mPhi:

[,1]

[1,] 1

[2,] 1

$mOmega:

[,1] [,2]

[1,] 0.25 0

[2,] 0.00 1

$mSigma:

[,1]

[1,] -1

[2,] 0

In the list variable ssf.ll.list, the component names match the state space formparameters in (8) and (11). This naming convention, summarized in Table 1, mustbe used for the specification of any valid state space model. Also, notice the use ofthe coercion function as.matrix. This ensures that the dimensions of the state spaceparameters are correctly specified.An “ssf” object may be created from the list variable ssf.ll.list using the

S+FinMetrics/SsfPack function CheckSsf:

> ssf.ll = CheckSsf(ssf.ll.list)

6

Page 7: State Space Survey

> class(ssf.ll)

[1] ’’ssf’’

> names(ssf.ll)

[1] ’’mDelta’’ ’’mPhi’’ ’’mOmega’’ ’’mSigma’’ ’’mJPhi’’

[6] ’’mJOmega’’ ’’mJDelta’’ ’’mX’’ ’’cT’’ ’’cX’’

[11] ’’cY’’ ’’cSt’’

> ssf.ll

$mPhi:

[,1]

[1,] 1

[2,] 1

$mOmega:

[,1] [,2]

[1,] 0.25 0

[2,] 0.00 1

$mSigma:

[,1]

[1,] -1

[2,] 0

$mDelta:

[,1]

[1,] 0

[2,] 0

$mJPhi:

[1] 0

$mJOmega:

[1] 0

$mJDelta:

[1] 0

$mX:

[1] 0

$cT:

[1] 0

7

Page 8: State Space Survey

$cX:

[1] 0

$cY:

[1] 1

$cSt:

[1] 1

attr(, ’’class’’):

[1] ’’ssf’’

The function CheckSsf takes a list variable with a minimum state space form, co-erces the components to matrix objects and returns the full parameterization of astate space model used in many of the S+FinMetrics/SsfPack state space modelingfunctions.

Example 2 State space representation of a time varying parameter regression model

Consider the Capital Asset Pricing Model (CAPM) with time varying interceptand slope

rt = αt + βM,trM,t + νt, νt ˜GWN(0, σ2ν) (18)

αt+1 = αt + ξt, ξt ˜GWN(0, σ2ξ) (19)

βM,t+1 = βM,t + ς t, ς t ˜GWN(0, σ2ς ) (20)

where rt denotes the return on an asset in excess of the risk free rate, and rM,t

denotes the excess return on a market index. In this model, both the abnormalexcess return αt and asset risk βM,t are allowed to vary over time following a randomwalk specification. Let αt = (αt, βM,t)

0, yt = rt, xt = (1, rM,t)0, Ht = diag(σξ, σς)

0

and Gt = σν. Then the state space form (8) of (18) - (20) isµαt+1

yt

¶=

µI2x0t

¶αt +

µHηt

Gεt

¶and has parameters

Φt =

µI2x0t

¶, Ω =

σ2ξ 0 00 σ2ς 00 0 σ2ν

(21)

Since αt is I(1) the initial state vector α1 doesn’t have finite variance so it is cus-tomary to set a = 0 and P = κI2 where κ is large. Using (12), the initial variance is

8

Page 9: State Space Survey

specified with P∗ = 0 and P∞ = I2. Therefore, the initial state matrix (11) for thetime varying CAPM has the form

Σ =

−1 00 −10 0

The state space parameter matrix Φt in (21) has a time varying system element

Zt= x0t. In S+FinMetrics/SsfPack, the specification of this time varying element in

Φt requires an index matrix JΦ and a data matrix X to which the indices in JΦ refer.The index matrix JΦ must have the same dimension as Φt. The elements of JΦ areall set to −1 except the elements for which the corresponding elements of Φt are timevarying. The non-negative index value indicates the column of the data matrix Xwhich contains the time varying values. For example, in the time varying CAPM, theindex matrix JΦ has the form

JΦ =

−1 −1−1 −11 2

The specification of the state space form for the time varying CAPM requires val-

ues for the variances σ2ξ , σ2ς , and σ

2ν as well as a data matrix X whose rows correspond

with Zt = x0t = (1, rM,t). For example, let σ

2ξ = (0.01)

2, σ2ς = (0.05)2 and σ2ν = (0.1)

2

and construct the data matrix X using the excess return data in the S+FinMetrics“timeSeries” excessReturns.ts

> X.mat = cbind(1,as.matrix(seriesData(excessReturns.ts[,’’SP500’’]))

The state space form may be created using

> Phi.t = rbind(diag(2),rep(0,2))

> Omega = diag(c((.01)^2,(.05)^2,(.1)^2))

> J.Phi = matrix(-1,3,2)

> J.Phi[3,1] = 1

> J.Phi[3,2] = 2

> Sigma = -Phi.t

> ssf.tvp.capm = list(mPhi=Phi.t,

+ mOmega=Omega,

+ mJPhi=J.Phi,

+ mSigma=Sigma,

+ mX=X.mat)

> ssf.tvp.capm

$mPhi:

[,1] [,2]

[1,] 1 0

9

Page 10: State Space Survey

[2,] 0 1

[3,] 0 0

$mOmega:

[,1] [,2] [,3]

[1,] 0.0001 0.0000 0.00

[2,] 0.0000 0.0025 0.00

[3,] 0.0000 0.0000 0.01

$mJPhi:

[,1] [,2]

[1,] -1 -1

[2,] -1 -1

[3,] 1 2

$mSigma:

[,1] [,2]

[1,] -1 0

[2,] 0 -1

[3,] 0 0

$mX:

numeric matrix: 131 rows, 2 columns.

SP500

1 1 0.002803

2 1 0.017566

...

131 1 -0.0007548

Notice in the specification of Φt the values associated with x0t in the third row are

set to zero. In the index matrix JΦ, the (3,1) element is 1 and the (3,2) element is2 indicating that the data for the first and second columns of x0t come from the firstand second columns of the component mX, respectively.In the general state space model (8), it is possible that all of the system matrices

δt, Φt and Ωt have time varying elements. The corresponding index matrices Jδ, JΦand JΩ indicate which elements of the matrices δt, Φt and Ωt are time varying andthe data matrix X contains the time varying components. The naming conventionfor these components is summarized in Table 2.

10

Page 11: State Space Survey

Parameter Index Matrix List Component NameJδ mJDelta

JΦ mJPhi

JΩ mJOmega

Time Varying Component Data Matrix List Component NameX mX

Table 2: S+FinMetrics/SsfPack time varying state space components

Function DescriptionGetSsfReg Create state space form for linear regression modelGetSsfArma Create state space form for stationary and invertible ARMA modelGetSsfRegArma Create state space form for linear regression model with ARMA errorsGetSsfStsm Create state space form for structural time series modelGetSsfSpline Create state space form for nonparametric cubic spline model

Table 3: S+FinMetrics/SsfPack functions for creating common state space models

2.3 S+FinMetrics/SsfPack Functions for Specifying the StateSpace Form for Some Common Time Series Models

S+FinMetrics/SsfPack has functions for the creation of the state space representa-tion of some common time series models. These functions and models are summarizedin Table 3.

A complete description of the underlying statistical models and use of thesefunctions is given in Zivot and Wang (2003), chapter fourteen. The applicationssection later on illustrate the use of some of these functions.

2.4 Simulating observations from the State Space Model

Once a state space model has been specified, it is often interesting to draw simulatedvalues from the model. Simulation from a given state space model is also necessary forMonte Carlo and bootstrap exercises. The S+FinMetrics/SsfPack function SsfSimmay be used for such a purpose. The arguments expected from SsfSim are

> args(SsfSim)

function(ssf, n = 100, mRan = NULL, a1 = NULL)

where ssf represents either a list with components giving a minimal state spaceform or a valid “ssf” object, n is the number of simulated observations, mRan isuser-specified matrix of disturbances, and a1 is the initial state vector.

Example 3 Simulating observations from the local level model

11

Page 12: State Space Survey

0 50 100 150 200 250

-6-4

-20

24

6

StateResponse

Figure 1: Simulated values from local level model created using the S+FinMetricsfunction SsfSim.

To generate 250 observations on the state variable αt+1 and observations yt in thelocal level model (13) - (15) use

> set.seed(112)

> ll.sim = SsfSim(ssf.ll.list,n=250)

> class(ll.sim)

[1] ’’matrix’’

> colIds(ll.sim)

[1] ’’state’’ ’’response’’

The function SsfSim returns a matrix containing the simulated state variables αt+1

and observations yt. These values are illustrated in Figure ??

12

Page 13: State Space Survey

3 Algorithms

3.1 Kalman Filter

The Kalman filter is a recursive algorithm for the evaluation of moments of the nor-mally distributed state vector αt+1 conditional on the observed dataYt = (y1, . . . , yt).To describe the algorithm, let at = E[αt|Yt−1] denote the conditional mean of αt

based on information available at time t − 1 and let Pt = var(αt|Yt−1) denote theconditional variance of αt.The filtering or updating equations of the Kalman filter compute at|t = E[αt|Yt]

and Pt|t = var(αt|Yt) using

at|t = at+Ktvt (22)

Pt|t = Pt−PtZ0tK0t (23)

where

vt = yt−ct − Ztat (24)

Ft = ZtPtZ0t+GtG

0t (25)

Kt = PtZ0tF−1t (26)

The variable vt is the measurement equation innovation or prediction error, Ft =var(vt) and Kt is the Kalman gain matrix.The prediction equations of the Kalman filter compute at+1 and Pt+1 using

at+1 = Ttat|t (27)

Pt+1 = TtPt|tT0t+HtH0t (28)

The S+FinMetrics/SsfPack function KalmanFil implements the Kalman filterrecursions in a computationally efficient way. The output of KalmanFil is primarilyused by other S+FinMetrics/SsfPack functions, but it can also be used to evaluatethe appropriateness of a given state space model through the analysis of the innova-tions vt. The S+FinMetrics/SsfPack function SsfMomentEst computes the filteredstate and response estimates from a given state space model and observed data withthe optional argument task=\STFIL". Predicted state and response estimates arecomputed using SsfMomentEst with the optional argument task=\STPRED".

3.2 Kalman Filter Initialization

To be written by Siem-Jan

13

Page 14: State Space Survey

3.3 Kalman Smoother

The Kalman filtering algorithm is a forward recursion which computes one-step aheadestimates at+1 and Pt+1 based on Yt for t = 1, . . . , n. The Kalman smoothing algo-rithm is a backward recursion which computes the mean and variance of specificconditional distributions based on the full data set Yn = (y1, . . . , yn). The smoothingequations are

r∗t = T0trt, N∗t= TtNtT

0t, K

∗t= N

∗tKt (29)

et = F−1t vt−K0tr∗t , Dt= F

−1t +KtK

∗0t

and the backwards updating equations are

rt−1= Z0tet+r∗t , Nt−1= Z0tDtZt− < K∗

tZt> +N∗t (30)

for t = n, . . . , 1 with initializations rn = 0 and Nn = 0. For any square matrix A,the operator < A >= A+A0. The values rt are called state smoothing residuals andthe values et are called response smoothing residuals. The recursions (29) and (30)are somewhat non-standard. Durbin and Koopman (2001) show how they may bere-expressed in more standard form.The S+FinMetrics/SsfPack function KalmanSmo implements the Kalman smoother

recursions in a computationally efficient way. The output of KalmanSmo is primarilyused by other S+FinMetrics/SsfPack functions, but it can also be used to evaluatethe appropriateness of a given state space model following the arguments in Harveyand Koopman (1992) and de Jong and Penzer (1998).

3.4 Smoothed State and Response Estimates

The smoothed estimates of the state vector αt and its variance matrix are denotedαt = E[αt|Yn] (or at|n) and var(αt|Yn), respectively. The smoothed estimate αt isthe optimal estimate of αt using all available information Yn, whereas the filteredestimate at|t is the optimal estimate only using information available at time t,Yt.The computation of αt and its variance from the Kalman smoother algorithm isdescribed in Durbin and Koopman (2001).The smoothed estimate of the response yt and its variance are computed using

yt = θt = E[θt|Yn] = ct+Ztαt

var(yt|Yn) = Ztvar(αt|Yn)Z0t

Smoothed estimates of the state and response may be computed using the S+FinMetrics/SsfPackfunctions SsfCondDens and SsfMomentEstwith the optional argument task=\STSMO".The function SsfCondDens only computes the smoothed states and responses whereasSsfMomentEst also computes the associated variances.

14

Page 15: State Space Survey

3.5 Smoothed Disturbance Estimates

The smoothed disturbance estimates are the estimates of the measurement equationsinnovations εt and transition equation innovations ηt based on all available infor-mation Yn, and are denoted εt = E[εt|Yn] (or εt|n) and ηt = E[ηt|Yn] (or ηt|n),respectively. The computation of εt and ηt from the Kalman smoother algorithm isdescribed in Durbin and Koopman (2001). These smoothed disturbance estimates areuseful for parameter estimation by maximum likelihood and for diagnostic checking.See chapter seven in Durbin and Koopman (2001) for details.The S+FinMetrics/SsfPack functions SsfCondDens and SsfMomentEst, with the

optional argument task=\DSSMO", may be used to compute smoothed estimates of themeasurement and transition equation disturbances. The function SsfCondDens onlycomputes the smoothed states and responses whereas SsfMomentEst also computesthe associated variances.

3.6 Forecasting

The Kalman filter prediction equations (27) - (28) produces one-step ahead predic-tions of the state vector, at+1 = E[αt+1|Yt], along with prediction variance matricesPt+1. In the Kalman filter recursions, if there are missing values in yt then vt= 0,F−1t = 0 and Kt = 0. This allows out-of-sample forecasts of αt and yt to be computedfrom the updating and prediction equations. Out of sample predictions, together withassociated mean square errors, can be computed from the Kalman filter predictionequations by extending the data set y1, . . . ,yn with a set of missing values. Whenyτ is missing, the Kalman filter reduces to the prediction step described above. As aresult, a sequence of m missing values at the end of the sample will produce a set ofh− step ahead forecasts for h = 1, . . . , m.Forecasts from state space models may be computed using the S+FinMetrics/SsfPack

function SsfMomentEst with the optional argument task=\STPRED".

3.7 Simulation Smoothing

The simulation of state and response vectors αt and yt or disturbance vectors ηt

and εt conditional on the observations Yn is called simulation smoothing. Simula-tion smoothing is useful for evaluating the appropriateness of a proposed state spacemodel and for the Bayesian analysis of state space models using importance samplingand Markov chain Monte Carlo (MCMC) techniques. The S+FinMetrics/SsfPackfunction SimSmoDraw generates random draws from the distributions of the state andresponse variables or from the distributions of the state and response disturbances.

15

Page 16: State Space Survey

3.8 Prediction Error Decomposition of Log-Likelihood

The prediction error decomposition of the log-likelihood function for the unknownparameters ϕ of a state space model may be conveniently computed using the outputof the Kalman filter

lnL(ϕ|Yn) =nX

t=1

ln f(yt|Yt−1;ϕ) (31)

= −nN2ln(2π)− 1

2

nXt=1

¡ln |Ft|+ v0tF−1t vt

¢where f(yt|Yt−1;ϕ) is a conditional Gaussian density implied by the state spacemodel (1) - (6). The vector of prediction errors vt and prediction error variancematrices Ft are computed from the Kalman filter recursions.The S+FinMetrics/SsfPack functions KalmanFil and SsfLogLik may be used

to evaluate the prediction error decomposition of the log-likelihood function for agiven set of parameters ϕ. The S+FinMetrics function SsfFit may be used to findthe maximum likelihood estimators of the unknown parameters ϕ, subject to boxconstraints, using the S-PLUS function nlminb4.

3.8.1 Concentrated log-likelihood

In some models, e.g. linear regression models and ARMA models, it is possible tosolve explicitly for one scale factor and concentrate it out of the log-likelihood function(31). The resulting log-likelihood function is called the concentrated log-likelihood orprofile log-likelihood and is denoted lnLc(ϕ|Yn). Following Koopman, Shephard andDoornik (1999), let σ denote such a scale factor, and let

yt= θt+Gctε

ct

with εct ˜iid N(0, σ2I) denote the scaled version of the measurement equation (3).The state space form (1) - (3) applies but with Gt = σGc

t and Ht = σHct . This

formulation implies that one non-zero element of σGct or σH

ct is kept fixed, usually at

unity, which reduces the dimension of the parameter vector ϕ by one. The solutionfor σ2 from (31) is given by

σ2(ϕ) =1

Nn

nXt=1

v0t (Fct )−1 vt

and the resulting concentrated log-likelihood function is

lnLc(ϕ|Yn) = −nN

2ln(2π)− nN

2ln¡σ2(ϕ) + 1

¢− 12

nXt=1

ln |Fct| (32)

4There are several optimization algorithms available in S-PLUS besides nlminb. Most notableare the functions ms and optim (in the MASS library). SsfFit may be easily modified to use theseroutines.

16

Page 17: State Space Survey

Function Description TasksKalmanIni Initialize Kalman filter AllKalmanFil Kalman filtering and likelihood eval AllKalmanSmo Kalman smoothing NoneSsfCondDens Conditional density/mean calculation STSMO,DSSMO

SsfMomentEst Moment estimation and smoothing STFIL,STPRED,STSMO,DSSMO

SimSmoDraw Simulation smoother draws STSIM,DSSIM

SsfLogLik Log-likelihood of state space model NoneSsfFit Estimate state space model parameters None

Table 4: General S+FinMetrics/SsfPack state space functions

Task DescriptionKFLIK Kalman filtering and loglikelihood evaluationSTFIL State filteringSTPRED State predictionSTSMO State smoothingDSSMO Disturbance smoothingSTSIM State simulationDSSIM Disturbance simulation

Table 5: Task argument to S+FinMetrics/SsfPack functions

For a given set of parameters ϕ, the concentrated log-likelihood may be evaluatedusing the functions KalmanFil and SsfLogLik. Maximization of the concentrated log-likelihood function may be specified in the S+FinMetrics/SsfPack function SsfFitby setting the optional argument conc=T.

3.9 Function Summary

The S+FinMetrics/SsfPack functions for computing the algorithms described aboveare summarized in Table 4.

All of the functions except KalmanSmo have an optional argument task whichcontrols the task to be performed by the function. The values of the argument taskwith brief descriptions are given in Table 5.

4 Applications in Macroeconomics and Finance

The following sections illustrate the use of the S+FinMetrics/SsfPack state spacemodeling and analysis functions for some commonly used time series models inmacroeconomics and finance.

17

Page 18: State Space Survey

4.1 Recursive least Squares Estimation and Tests for Struc-tural Stability

Consider the CAPM regression

rt = α + βMrM,t + ξt, ξt ˜GWN(0, σ2ξ)

where rt denotes the return on an asset in excess of the risk free rate, and rM,t denotesthe excess return on a market index. This is a linear regression model of the form

yt= x0tβ+ξt, ξt ˜GWN(0, σ2ξ),

where xt = (1, rM,t)0 is a 2 × 1 vector of data, and β = (α, βM)

0 is a 2 × 1 fixedparameter vector. A state space representation isµ

αt+1

yt

¶=

µIkx0t

¶αt +

µ0

σξεt

¶(33)

where the state vector satisfies

αt+1= αt= β.

The state space system matrices are Tt= Ik,Zt= x0t, Gt = σξ and Ht = 0. The coef-

ficient vector β is fixed and unknown so that the initial conditions are α1 ˜N(0, κIk)where κ is large.To illustrate the CAPM, we use the monthly excess return data on Microsoft and

the S&P 500 index over the period February, 1990 through December, 2000 in theS+FinMetrics “timeSeries” excessReturns.ts:

> X.mat = cbind(1,as.matrix(seriesData(excessReturns.ts[,"SP500"])))

> msft.ret = excessReturns.ts[,"MSFT"]

The state space form for the CAPM as a linear regression with fixed regressors maybe created using the S+FinMetrics/SsfPack function GetSsfReg:

> ssf.reg = GetSsfReg(X.mat)

> ssf.reg

$mPhi:

[,1] [,2]

[1,] 1 0

[2,] 0 1

[3,] 0 0

$mOmega:

[,1] [,2] [,3]

18

Page 19: State Space Survey

[1,] 0 0 0

[2,] 0 0 0

[3,] 0 0 1

$mSigma:

[,1] [,2]

[1,] -1 0

[2,] 0 -1

[3,] 0 0

$mJPhi:

[,1] [,2]

[1,] -1 -1

[2,] -1 -1

[3,] 1 2

$mX:

numeric matrix: 131 rows, 2 columns.

SP500

[1,] 1 0.0028027064

...

[131,] 1 -0.0007548068

By default, the variance of the regression error is set equal to unity and the statevariables are given a diffuse initialization.

4.1.1 Recursive least squares estimation

An advantage of analyzing the linear regression model in state space form is that re-cursive least squares (RLS) estimates of the regression coefficient vector β are readilycomputed from the Kalman filter. The RLS estimates are based on estimating themodel

yt = β0txt + ξt, t = 1, . . . , n (34)

by least squares recursively for t = 3, . . . , n giving n−2 least squares (RLS) estimates(β3, . . . , βT ). If β is constant over time then the recursive estimates βt should quicklysettle down near a common value. If some of the elements in β are not constant thenthe corresponding RLS estimates should show instability. Hence, a simple graphicaltechnique for uncovering parameter instability is to plot the RLS estimates βit (i =1, 2) and look for instability in the plots.The RLS estimates are simply the filtered state estimates from the model (33),

and may be computed using the S+FinMetrics/SsfPack function SsfMomentEst withthe optional argument task=\STFIL":

19

Page 20: State Space Survey

> filteredEst.reg = SsfMomentEst(msft.ret,ssf.reg,task="STFIL")

> class(filteredEst.reg)

[1] "SsfMomentEst"

> names(filteredEst.reg)

[1] "state.moment" "state.variance" "response.moment"

[4] "response.variance" "task" "positions"

The component state.moment contains the filtered state estimates at|t for t = 1, . . . , n,which are the RLS estimates of the linear regression coefficients, and the componentresponse.moment contains the filtered response estimates yt|t. The first column of thecomponent state.moment contains the RLS estimates of α, and the second columncontains the RLS estimates of βM : 5

> filteredEst.reg$state.moment

numeric matrix: 131 rows, 2 columns.

state.1 state.2

[1,] 0.05967933 0.0001672637

[2,] 0.05044782 3.2939515044

[3,] 0.07455946 1.1812959990

...

[131,] 0.01281735 1.525871

The last row contains the full sample least squares estimates of α and βM , which maybe verified using the S+FinMetrics function OLS:

> ols.fit = OLS(MSFT~SP500,data=excessReturns.ts)

> coef(ols.fit)

(Intercept) SP500

0.01281735 1.525871

The RLS estimates may be visualized using the generic plot method for objects ofclass “SsfMomentEst”:

> plot(filteredEst.reg,strip.text=c("alpha","beta","expected return"))

The resulting plot is illustrated in Figure 2. Notice that the RLS estimates of βM

seem fairly constant whereas the RLS estimates of α do not.Since the data passed to SsfMomentEst is a “timeSeries” object, the time and

date information is available in the positions component of the object filteredEst.reg.Therefore, a time series plot of the RLS estimates may be computed using

> rls.coef = timeSeries(pos=filteredEst.reg$positions,

+ data=filteredEst.reg$state.moment)

> seriesPlot(rls.coef,one.plot=F,strip.text=c("alpha","beta"))

The resulting plot is illustrated in Figure 3.

5Since the Kalman filter is given an exact diffuse initialization, the RLS estimates are availablefor t = 1, 2. The usual formula for computing RLS estimates starts at t = 3.

20

Page 21: State Space Survey

0.02

0.04

0.06

0.08

0 20 40 60 80 100 120

alpha

01

23

beta

-0.1

0.0

0.1

0.2

expected return

Valu

es

Filtered estimates: RLS

Figure 2: RLS estimates of CAPM for Microsoft using the Kalman filter.

4.1.2 Tests for constant parameters

Formal tests for structural stability of the regression coefficients, such as the CUSUMtest of Brown, Durbin and Evans (1976), may be computed from the standardized1− step ahead recursive residuals

wt =vt√ft=

yt − β0t−1xt√ft

where ft is an estimate of the recursive error variance

σ2£1 + x0t(X

0t−1Xt−1)

−1xt¤

and Xt is the (t×k) matrix of observations on xs using data from s = 1, . . . , t. Thesestandardized recursive residuals result as a by-product of the Kalman filter recursionsand may be extracted using the S+FinMetrics/SsfPack function KalmanFil

> kf.reg = KalmanFil(msft.ret,ssf.reg)

> class(kf.reg)

[1] "KalmanFil"

> names(kf.reg)

21

Page 22: State Space Survey

0.02

0.04

0.06

1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001

alpha

12

3

beta

Figure 3: RLS estimates of CAPM for Microsoft using the Kalman filter

[1] "mOut" "innov" "std.innov" "mGain"

[5] "loglike" "loglike.conc" "dVar" "mEst"

[9] "mOffP" "task" "err" "call"

[13] "positions"

> w.t = kf.reg$std.innov[-c(1,2)] # first two innovations are equal to zero

Diagnostic plots of the standardized innovations may be created using the plotmethod for objects of class “KalmanFil”

> plot(kf.reg)

Make a plot selection (or 0 to exit):

1: plot: all

2: plot: innovations

3: plot: standardized innovations

4: plot: innovation histogram

5: plot: normal QQ-plot of innovations

6: plot: innovation ACF

Selection:

22

Page 23: State Space Survey

-0.3

-0.2

-0.1

0.0

0.1

1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001

innovationsVa

lues

Standardized Prediction Errors

Figure 4: Standardized innovations, wt = vt/√ft, computed from the RLS estimates

of the CAPM for Microsoft.

Selection 3 produces the graph shown in Figure 4.The CUSUM test is based on the cumulated sum of the standardized recursive

residuals

CUSUMt =tX

j=k+1

wj

σw

where σw is the sample standard deviation of wj and k denotes the number of esti-mated coefficients. Under the null hypothesis that β in (34) is constant, CUSUMt

has mean zero and variance that is proportional to t − k − 1. Brown, Durbin andEvans (1976) show that approximate 95% confidence bands for CUSUMt are givenby the two lines which connect the points (k,±0.948√n− k − 1) and (n,±0.948 ·3√n− k − 1). If CUSUMt wanders outside of these bands, then the null of param-

eter stability may be rejected. The S-PLUS commands to compute CUSUMt andcreate the CUSUM plot are

> cusum.t = cumsum(w.t)/stdev(w.t)

> nobs = length(cusum.t)

> tmp = 0.948*sqrt(nobs)

> upper = seq(tmp,3*tmp,length=nobs)

23

Page 24: State Space Survey

1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001

-30

-20

-10

010

2030

Figure 5: CUSUM test for parameter constancy in CAPM regression for Microsoft

> lower = seq(-tmp,-3*tmp,length=nobs)

> tmp.ts = timeSeries(pos=kf.reg$positions[-c(1,2)],

+ data=cbind(cusum.t,upper,lower))

> plot(tmp.ts,reference.grid=F,

+ plot.args=list(lty=c(1,2,2),col=c(1,2,2)))

The resulting CUSUM plot is illustrated in Figure 5.The CUSUM test indicates thatthe CAPM for Microsoft has stable parameters.As mentioned in Koopman, Shephard and Doornik (1999), the output of the

basic smoothing recursions can be used to construct t-tests for structural change inregression models using the results of de Jong and Penzer (1998). In particular, thenull hypothesis βi = β∗i with respect to the ith explanatory variable in the k− variableregression

yt = · · ·+ xi,tβi + · · ·+ ξt, for t = 1, . . . , τ

yt = · · ·+ xi,tβ∗i + · · ·+ ξt, for t = τ + 1, . . . , n

against the alternative βi 6= β∗i can be tested using the standardized smoothingresidual

ri,τ/pNii,τ , τ = 1, . . . , n− 1 (35)

24

Page 25: State Space Survey

where rt and Nt are computed from the smoothing equation (30). Under the nullof no structural change, βi = β∗i , (35) is distributed Student-t with n− k degrees offreedom. The standardized smoothing residuals (35) for the CAPM regression maybe computed using the S+FinMetrics/SsfPack function KalmanSmo

> ks.reg = KalmanSmo(kf.reg,ssf.reg)

> class(ks.reg)

[1] "KalmanSmo"

> names(ks.reg)

[1] "state.residuals" "response.residuals" "state.variance"

[4] "response.variance" "aux.residuals" "scores"

[7] "positions" "call"

The first two columns of the component aux.residuals contain the standardizedsmoothing residuals (35) for the state variables and the last column contains thestandardized response smoothing residuals from (29):

> colIds(ks.reg$aux.residuals)

[1] "state.1" "state.2" "response"

The t-tests (35), illustrated in Figure 6, do not indicate any structural change in thecoefficients.

4.1.3 Least squares residuals

To compute the residuals based on the full sample least squares estimates using theKalman filter, the state space model must be modified so that the initial value of thestate vector is the least squares estimate and the variance of the initial vector is equalto zero:

> ssf.reg$mSigma[3,] = filteredEst.reg$state.moment[131,]

> ssf.reg$mSigma[1,1]=ssf.reg$mSigma[2,2]=0

The Kalman filter applied to the modified state space then give the least squaresresiduals:

> kf.ols = KalmanFil(msft.ret,ssf.reg)

> res.ols = kf.ols$innov

4.2 Estimation of CAPM with Time Varying Parameters

Consider estimating the CAPM with time varying coefficients (18) - (20) subject torandom walk evolution, using monthly data on Microsoft and the S&P 500 index overthe period February, 1990 through December, 2000 contained in the S+FinMetrics

25

Page 26: State Space Survey

1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001

-0.2

-0.1

0.0

0.1

0.2

t-alphat-beta

Figure 6: t-tests for structural change in the parameters of the CAPM for Microsoftbased on standardized smoothing residuals.

“timeSeries” excessReturns.ts. Neumann (2002) surveys several estimation strate-gies for time varying parameter models and concludes that the state space modelwith random walk specifications for the evolution of the time varying parametersgenerally performs very well. The parameters of the model are the variances ofthe innovations to the transition and measurement equations: σ2 = (σ2ξ , σ

2ς , σ

2ν)0.

Since these variances must be positive the log-likelihood is parameterized using ϕ =(ln(σ2ξ), ln(σ

2ς ), ln(σ

2ν))

0, so that σ2 = (exp(ϕ1), exp(ϕ2), exp(ϕ3))0. Since the state

space form for the CAPM with time varying coefficients requires a data matrix Xcontaining the excess returns on the S&P 500 index, the function SsfFit requires asinput a function which takes both ϕ and X and returns the appropriate state spaceform. One such function is

tvp.mod = function(parm,mX=NULL)

parm = exp(parm)

ssf.tvp = GetSsfReg(mX=mX)

26

Page 27: State Space Survey

diag(ssf.tvp$mOmega) = parm

CheckSsf(ssf.tvp)

Starting values for ϕ are specified as

> tvp.start = c(0,0,0)

> names(tvp.start) = c(’’ln(s2.alpha)’’,’’ln(s2.beta)’’,’’ln(s2.y)’’)

The maximum likelihood estimates for ϕ based on SsfFit are computed using

> tvp.mle = SsfFit(tvp.start,msft.ret,"tvp.mod",mX=X.mat)

Iteration 0 : objective = 183.2072

...

Iteration 18 : objective = -124.4641

RELATIVE FUNCTION CONVERGENCE

> class(tvp.mle)

[1] "list"

> names(tvp.mle)

[1] "parameters" "objective" "message" "grad.norm"

[5] "iterations" "f.evals" "g.evals" "hessian"

[9] "scale" "aux" "call" "vcov"

The estimates of ϕ = (ln(σ2ξ), ln(σ2ς ), ln(σ

2ν))

0 are in the component parameters

> tvp.mle$parameters

ln(s2.alpha) ln(s2.beta) ln(s2.y)

-11.56685 -5.314272 -4.855237

and the estimated asymptotic variances (based on the inverse of the empirical hessian)are in the component vcov. Estimates of the asymptotic standard errors are:

> sqrt(diag(tvp.mle$vcov))

[1] 1.8917852 2.2581790 0.1298533

The estimates for the standard deviations σξ, σς and σν are

> sigma.mle = sqrt(exp(tvp.mle$parameters))

> names(sigma.mle) = c("s.alpha","s.beta","s.y")

> sigma.mle

s.alpha s.beta s.y

0.001950676 0.05234977 0.08996629

The asymptotic standard errors for the estimated standard deviations, from the deltamethod, are

27

Page 28: State Space Survey

> dg = diag(exp(tvp.mle$parameters)/2)

> se.sigma = sqrt(diag(dg%*%tvp.mle$vcov%*%dg))

> names(se.sigma) = names(sigma.mle)

> se.sigma

s.alpha s.beta s.y

5.332895e-006 0.004232753 0.0005200605

4.2.1 Filtered estimates

Given the estimated parameters, the filtered estimates of the time varying parametersαt and βM,t may be computed using SsfMomentEst

> filteredEst.tvp = SsfMomentEst(msft.ret,

+ tvp.mod(tvp.mle$parameters,mX=X.mat),task="STFIL")

> class(filteredEst.tvp)

[1] "SsfMomentEst"

> names(filteredEst.tvp)

[1] "state.moment" "state.variance" "response.moment"

[4] "response.variance" "task" "positions"

The component state.moment contains the filtered state estimates, at|t, and thecomponent response.moment contains the filtered response estimate yt|t. The corre-sponding variances are in the components state.variance and response.variance,respectively. The filtered moments, without standard error bands, may be visualizedusing the plot method for objects of class “SsfMomentEst”

> plot(filteredEst.tvp,strip.text=c("alpha(t)",

+ "beta(t)","Expected returns"),main="Filtered Estimates")

The resulting graph is illustrated in Figure 7. The filtered estimates of the parametersfrom the CAPMwith time varying parameters look remarkably like the RLS estimatescomputed earlier.Figure 8 shows time series plots of the filtered estimates along with approximate

95% confidence intervals.

4.2.2 Smoothed estimates

The smoothed estimates of the time varying parameters αt and βM,t as well as theexpected returns may be extracted using SsfCondDens:

> smoothedEst.tvp = SsfCondDens(msft.ret,

+ tvp.mod(tvp.mle$parameters,mX=X.mat),

+ task=’’STSMO’’)

> class(smoothedEst.tvp)

[1] "SsfCondDens"

28

Page 29: State Space Survey

-0.1

0.0

0.1

0.2

0 20 40 60 80 100 120

Expected returns

0.02

0.04

0.06

0.08

alpha(t)

01

23

beta(t)Va

lues

Filtered Estimates

Figure 7: Filtered estimates of CAPM for Microsoft with time varying parameters

> names(smoothedEst.tvp)

[1] "state" "response" "task" "positions"

Notice that SsfCondDens does not compute estimated variances for the smoothedstate and response variables. The plotmethod may be used to visualize the smoothedestimates:

> plot(smoothedEst.tvp,strip.text=c(’’alpha(t)’’,

+ ’’beta(t)’’,’’Expected returns’’),main=’’Smoothed Estimates’’)

Figure 9 shows the resulting plot. Notice that the smoothed state estimates are quitedifferent from the filtered state estimates shown in Figure 7. If standard error bandsfor the smoothed estimates are desired, then SsfMomentEst with task=\STSMO" mustbe used and the state variances are available in the component state.variance.

29

Page 30: State Space Survey

Filtered estimates of alpha(t)

1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001

-0.1

50.

050.

25

Filtered estimates of beta(t)

1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001

-10

-50

510

1520

Figure 8:

4.3 Exact ARMA Model Estimation and The Beveridge-Nelson Decomposition of U.S. Real GDP

Consider the problem of decomposing the movements in the natural logarithm of U.S.postwar quarterly real GDP into permanent and transitory (cyclical) components.The levels and growth rate data, multiplied by 100, over the period 1947:I to 1998:IIare illustrated in Figure 10. Beveridge and Nelson (1980) proposed a definition for thepermanent component of an I(1) time series yt with drift µ as the limiting forecastas horizon goes to infinity, adjusted for the mean rate of growth:

BNt = limh→∞

Et[yt+h − µh]

where Et[·] denotes expectation conditional on information available at time t. Thetransitory or cycle component is then defined as the gap between the present level ofthe series and its long-run forecast:

ct = yt −BNt

30

Page 31: State Space Survey

-0.2

-0.1

0.0

0.1

0 20 40 60 80 100 120

Expected returns

0.01

00.

015

0.02

00.

025

alpha(t)

1.4

1.5

1.6

1.7

1.8 beta(t)

Mea

n

Smoothed Estimates

Figure 9: Smoothed estimates of CAPM for Microsoft with time varying parameters

This permanent-transitory decomposition is often referred to as the “BN decomposi-tion”. In practice, the BN decomposition is obtained by fitting an ARMA(p, q) modelto ∆yt, and then computing BNt and ct from the fitted model.As shown recently by Morley (2002), the BN decomposition may be easily com-

puted using the Kalman filter by putting the forecasting model for ∆yt − µ in statespace form. In particular, suppose ∆yt−µ is a linear combination of the elements ofthe m× 1 state vector αt :

∆yt − µ =£z1 z2 · · · zm

¤αt

where zi (i = 1, . . . , m) is the weight of the ith element of αt in determining ∆yt−µ.Suppose further that

αt+1= Tαt+η∗t , η

∗t ˜iid N(0,V),

such that all of the eigenvalues of T have modulus less than unity, and T is invertible.

31

Page 32: State Space Survey

Log Postwar Quarterly Real GDP

1950 1955 1960 1965 1970 1975 1980 1985 1990 1995

740

780

820

860

Quarterly Growth Rate

1950 1955 1960 1965 1970 1975 1980 1985 1990 1995

-2-1

01

23

4

Figure 10: U.S. postwar quarterly real GDP

Then, Morley shows that

BNt = yt +£z1 z2 · · · zm

¤T(Im−T)−1at|t (36)

ct = yt −BNt = −£z1 z2 · · · zm

¤T(Im−T)−1at|t

where at|t denotes the filtered estimate of αt.

4.3.1 Estimation of ARMA(2,2) model

To illustrate the process of constructing the BN decomposition for U.S. postwarquarterly real GDP, we follow Morley, Nelson and Zivot (2002) (hereafter MNZ) andconsider fitting the ARMA(2,2) model

∆yt − µ = φ1(∆yt−1 − µ) + φ2(∆yt−2 − µ) + εt + θ1εt−1 + θ2εt−2εt ˜ iid N(0, σ2)

where yt denotes the natural log of real GDP multiplied by 100. In S+FinMetrics/SsfPack,the ARMA(p, q) model for a demeaned stationary variable y∗t has a state space rep-resentation with transition and measurement equations

αt+1 = Tαt +Hξt, ξt ˜N(0, σ2ε)

y∗t = Zαt

32

Page 33: State Space Survey

and time invariant system matrices

T =

φ1 1 0 · · · 0φ2 0 1 0...

. . ....

φm−1 0 0 1φm 0 0 · · ·

, H =

1θ1...

θm−1θm

, (37)

Z =¡1 0 · · · 0 0

¢where d, c and G of the state space form (1)-(3) are all zero and m = max(p, q + 1).The state vector αt has the form

αt =

y∗t

φ2y∗t−1 + · · ·+ φpy

∗t−m+1 + θ1ξt + · · ·+ θm−1ξt−m+2

φ3y∗t−1 + · · ·+ φpy

∗t−m+2 + θ2ξt + · · ·+ θm−1ξt−m+3

...φmy

∗t−1 + θm−1ξt

(38)

The exact maximum likelihood estimates of the ARMA(2,2) parameters may becomputed using the S+FinMetrics/SsfPack functions GetSsfArma and SsfFit. Thefunction SsfFit requires as input a function which takes the unknown parameters ϕand produces the state space form for the ARMA(2,2). One such function is

arma22.mod = function(parm)

phi.1 = parm[1]

phi.2 = parm[2]

theta.1 = parm[3]

theta.2 = parm[4]

sigma2 = exp(parm[5])

ssf.mod = GetSsfArma(ar=c(phi.1,phi.2),ma=c(theta.1,theta.2),

sigma=sqrt(sigma2))

CheckSsf(ssf.mod)

Notice that the function arma22.mod parameterizes the error variance as σ2 = exp(γ),−∞ < γ < ∞, to ensure that the estimated value of σ2 is positive, and utilizes theS+FinMetrics/SsfPack function GetSsfArma to create the state space form for theARMA(2,2) function. Starting values for the estimation are given by (conditionalmle’s using S-PLUS function arima.mle)

> arma22.start = c(1.34,-0.70,-1.05,0.51,-0.08)

> names(arma22.start) = c("phi.1","phi.2","theta.1","theta.2","ln.sigma2")

33

Page 34: State Space Survey

The data used for the estimation is in the “timeSeries” lny.ts and the demeanedfirst difference data is in the “timeSeries” dlny.ts.dm. The exact maximum likeli-hood estimates for ϕ = (φ1, φ2, θ1, θ2, γ)

0 are computed using SsfFit6:

> arma22.mle = SsfFit(arma22.start,dlny.ts.dm,"arma22.mod")

Iteration 0 : objective = 284.6686

...

Iteration 27 : objective = 284.651

RELATIVE FUNCTION CONVERGENCE

> arma22.mle$parameters

phi.1 phi.2 theta.1 theta.2 ln.sigma2

1.341793 -0.7058402 -1.054205 0.5187025 -0.06217022

> exp(arma22.mle$parameters["ln.sigma2"])

ln.sigma2

0.9397229

4.3.2 Residual diagnostics

Residual diagnostics to evaluate the fit of the state space model may be computedusing the S+FinMetrics/SsfPack function KalmanFil:

> kf.arma22 = KalmanFil(dlny.ts.dm,

+ arma22.mod(arma22.mle$parameters))

> class(kf.arma22)

[1] "KalmanFil"

> names(kf.arma22)

[1] "mOut" "innov" "std.innov" "mGain"

[5] "loglike" "loglike.conc" "dVar" "mEst"

[9] "mOffP" "task" "err" "call"

[13] "positions"

Of particular interest are the components innov and std.innov, which contain theinnovations, vt, and the standardized innovations, vt/

√Ft, respectively. Properties

of these components may be visualized using the plot method for objects of class“KalmanFil”:

> plot(kf.arma22)

Make a plot selection (or 0 to exit):

1: plot: all

2: plot: innovations

6An estimate of the asymptotic covariance matrix is given in the vcov component of arma22.mle.An estimate of the variance of σ2 = exp(γ) may be computed using the “delta method”.

34

Page 35: State Space Survey

Lag

ACF

0 5 10 15 20

0.0

0.2

0.4

0.6

0.8

1.0

Autocorrelation Function

Figure 11: ACF of innovations vt from ARMA(2,2) model fit to real GDP growth.

3: plot: standardized innovations

4: plot: innovation histogram

5: plot: normal QQ-plot of innovations

6: plot: innovation ACF

Selection:

Selection 6 is shown in Figure 11.

4.3.3 BN decomposition

Given the maximum likelihood estimates ϕ, the filtered estimate of the state vectormay be computed using the S+FinMetrics/SsfPack function SsfMomentEst withoptional argument task=\STFIL"

> filteredEst.arma22 = SsfMomentEst(dlny.ts.dm,

+ arma22.mod(arma22.mle$parameters),task="STFIL")

> at.t = filteredEst.arma22$state.moment

35

Page 36: State Space Survey

Log Real GDP and BN Trend

1950 1955 1960 1965 1970 1975 1980 1985 1990 1995

740

780

820

860

BN Cycle

1950 1955 1960 1965 1970 1975 1980 1985 1990 1995

-1.5

-0.5

0.5

1.5

Figure 12: BN decomposition for U.S. postwar quarterly real GDP.

The BN decomposition (36) may then be computed using

> filteredEst.arma22 = SsfMomentEst(dlny.ts.dm,

+ arma22.mod(arma22.mle$parameters),task="STFIL")

> xt.t = filteredEst.arma22$state.moment

> T.mat = ssf.arma22$mPhi[1:3,1:3]

> tmp = t(T.mat%*%solve((diag(3)-T.mat))%*%t(at.t))

> BN.t = lny[2:nobs,] + tmp[,1]

> c.t = lny[2:nobs,] - BN.t

Figure 12 illustrates the results of the BN decomposition for U.S. real GDP. The BNtrend follows the data very closely, and the BN cycle does not display much cyclicalbehavior.

4.4 Unobserved Components Decompositions of Real GDP:Clark’s Model

Harvey (1985) and Clark (1987) provide an alternative to the BN decomposition ofan I(1) time series with drift into permanent and transitory components based onunobserved components structural time series models. For example, Clark’s model

36

Page 37: State Space Survey

for the natural logarithm of postwar real GDP specifies the trend as a pure randomwalk, and the cycle as a stationary AR(2) process:

yt = τ t + ct (39)

τ t = µ+ τ t−1 + vt

ct = φ1ct−1 + φ2ct−2 + wt

where the roots of φ(z) = 1− φ1z− φ2z2 = 0 lie outside the complex unit circle. For

identification purposes, Clark assumes that the trend innovations and cycle innova-tions are uncorrelated and normally distributed:µ

vtwt

¶iid N

µµ00

¶,

µσ2v 00 σ2w

¶¶The Clark model may be put in state-space form (8) with

αt+1 =

τ t+1ct+1ct

, δ =

µ000

,Φ =

1 0 00 φ1 φ20 1 01 1 0

ut =

µη∗t0

¶,η∗t =

vt+1wt+1

0

,Ω =

σ2v 0 0 00 σ2w 0 00 0 0 00 0 0 0

Since the trend component is nonstationary, it is given a diffuse initialization. Theinitial covariance matrix P∗ of the stationary cycle is determined from

vec(P∗) = (I4−(F⊗ F)−1)vec(Vw)

where

F =

µφ1 φ21 0

¶, Vw =

µσ2w 00 0

¶The initial value parameter matrix (11) is then

Σ =

−1 0 0p11 p12 0p22 p21 00 0 0

where pij denotes the (i, j) element of P∗.

37

Page 38: State Space Survey

4.4.1 Estimation

The exact maximum likelihood estimates of the Clark model parameters, based onthe prediction error decomposition of the log-likelihood function, may be computedusing the S+FinMetrics/SsfPack SsfFit. The function SsfFit requires as input afunction which takes the unknown parameters ϕ and produces the state space formfor the Clark model. One such function is

Clark.mod = function(parm)

mu = parm[1]

phi1 = parm[2]

phi2 = parm[3]

sigma2.v = exp(parm[4])

sigma2.w = exp(parm[5])

bigV = diag(c(sigma2.v,sigma2.w))

Omega = matrix(0,4,4)

Omega[1:2,1:2] = bigV

a1 = matrix(0,3,1)

# solve for initial variance of stationary part

bigF = matrix(c(phi1,1,phi2,0),2,2)

vecV = c(sigma2.w,0,0,0)

vecP = solve(diag(4)-kronecker(bigF,bigF))%*%vecV

P.ar2 = matrix(vecP,2,2)

Sigma = matrix(0,4,3)

Sigma[1,1] = -1

Sigma[2:3,2:3] = P.ar2

# create state space list

ssf.mod = list(mDelta=c(mu,0,0,0),

mPhi=rbind(c(1,0,0),c(0,phi1,phi2),c(0,1,0),c(1,1,0)),

mOmega=Omega,

mSigma = Sigma)

CheckSsf(ssf.mod)

Notice that the state variances are parameterized as σ2v = exp(γv) and σ2w = exp(γw),

−∞ < γv, γw < ∞, to ensure positive estimates. Starting values for the parametersare based on values near the estimates of the Clark model from MNZ:

> Clark.start=c(0.81,1.53,-0.61,-0.74,-0.96)

> names(Clark.start) = c("mu","phi.1","phi.2",

+ "ln.sigma2.v","ln.sigma2.w")

The data used for the estimation is in the “timeSeries” lny.ts, and is thesame data used to compute the BN decomposition earlier. The maximum likelihood

38

Page 39: State Space Survey

estimates and asymptotic standard errors of the parameters ϕ = (µ, γv, γw, φ1, φ2)0

using SsfFit are7

> Clark.mle = SsfFit(Clark.start,lny.ts,"Clark.mod")

Iteration 0 : objective = 287.5252

...

Iteration 19 : objective = 287.5243

RELATIVE FUNCTION CONVERGENCE

> Clark.mle$parameters

mu phi.1 phi.2 ln.sigma2.v ln.sigma2.w

0.8119143 1.530305 -0.6097297 -0.7440539 -0.956487

> sqrt(diag(Clark.mle$vcov))

[1] 0.05005272 0.10194946 0.11463581 0.30134294 0.42546854

> sqrt(exp(Clark.mle$parameters[4:5]))

ln.sigma2.v ln.sigma2.w

0.6893357 0.6198712

The maximum likelihood estimates for the Clark model parameters are almost iden-tical to those found by MNZ8.

4.4.2 Filtered estimates

The filtered estimates of the trend, τ t|t, and cycle, ct|t, given the estimated parame-ters may be computed using the function SsfMomentEst with the optional argumenttask=\STFIL"

> filteredEst.Clark = SsfMomentEst(lny.ts,

+ Clark.mod(Clark.mle$parameters),task="STFIL")

> names(filteredEst.Clark)

[1] "state.moment" "state.variance" "response.moment"

[4] "response.variance" "task" "positions"

The filtered trend estimate is in the first column of the state.moment componentand the filtered cycle is in the second column. The plot method gives time plots ofthe columns of the state.moment component and response.moment component:

7In the estimation, no restrictions were imposed on the AR(2) parameters φ1 and φ2 to ensurethat the cycle is stationary. The function SsfFit uses the S-PLUS optimization algorithm nlminb,which performs minimization of a function subject to box constraints. Box constraints on φ1 andφ2 may be used to constrain their estimated values to be near the appropriate stationary region.

8MNZ estimate the Clark model in GAUSS using the prediction error decomposition with thevariance of the initial state for the nonstationary component set to a large positive number. Thestate space representation of the Clark model in S+FinMetrics utilizes an exact initialization of theKalman filter.

39

Page 40: State Space Survey

-4-2

02

4

0 50 100 150 200

cycle(t)

-4-2

02

4

cycle(t-1)

750

800

850

trend(t)

750

800

850

0 50 100 150 200

y(t)

Valu

es

Filtered estimates

Figure 13: Filtered estimates of the state and response variables from the Clark modelfor U.S. real GDP.

> plot(filteredEst.Clark,

+ strip.text=c("trend(t)","cycle(t)","cycle(t-1)","y(t)"),

+ main="Filtered estimates")

These plots are illustrated in Figure 13 .Since the data passed to SsfMomentEst is an object of class “timeSeries”, the

positions component of the object filteredEst.Clark contains the time and datepositions of the data. The filtered trend and cycle estimates as “timeSeries” objectsmay be computed using

> trend.filter = timeSeries(data=filteredEst.Clark$state.moment[,1],

+ positions=filteredEst.Clark$positions)

> cycle.filter = timeSeries(data=filteredEst.Clark$state.moment[,2],

+ positions=filteredEst.Clark$positions)

Figure 14 shows the filtered estimates of trend and cycle from the Clark model basedon the “timeSeries” trend.filter and cycle.filter.The filtered trend estimate is fairly smooth and is quite similar to a linear trend. Thefiltered cycle estimate is large in amplitude and has a period of about eight years.

40

Page 41: State Space Survey

Log Real GDP and Filtered Trend from Clark Model

1950 1955 1960 1965 1970 1975 1980 1985 1990 1995

740

780

820

860

Filtered Cycle from Clark Model

1950 1955 1960 1965 1970 1975 1980 1985 1990 1995

-4-3

-2-1

01

23

4

Figure 14: Filtered estimates of the trend and cycle from the Clark model estimatedto U.S. real GDP.

In comparison to the BN decomposition, the trend-cycle decomposition based on theClark model gives a much smoother trend and longer cycle, and attributes a greateramount of the variability of log output to the transitory cycle.

4.4.3 Smoothed estimates

The smoothed estimates of the trend, τ t|n, and cycle, ct|n, along with estimated stan-dard errors, given the estimated parameters, may be computed using the functionSsfMomentEst with the optional argument task=\STSMO":

> smoothedEst.Clark = SsfMomentEst(lny.ts,

+ Clark.mod(Clark.mle$parameters),task="STSMO")

The smoothed cycle estimates with 95% standard error bands are illustrated in Figure15.

4.4.4 Specification test

The Clark model assumes that the unobserved trend evolves as a random walk withdrift. If the variance of the drift innovation, σ2v, is zero then the trend becomes

41

Page 42: State Space Survey

1950 1955 1960 1965 1970 1975 1980 1985 1990 1995

-8-6

-4-2

02

46

Figure 15: Smoothed cycle estimate, ct|n, with 95% error bands from Clark model forU.S. real GDP.

deterministic. A number of statistics have been proposed to test the null hypoth-esis that σ2v = 0, see Harvey (2001) for a review. One of the most popular is theKPSS statistic described in Kwiatkowski et. al. (1992). The S+FinMetrics functionstationaryTest implements the KPSS test. Applying this test to the U.S. real GDPdata gives

> stationaryTest(lny.ts,trend="ct")

Test for Stationarity: KPSS Test

Null Hypothesis: stationary around a linear trend

Test Statistics:

lny

0.7804**

* : significant at 5% level

** : significant at 1% level

42

Page 43: State Space Survey

Total Observ.: 206

Bandwidth : 4

The KPSS test rejects the null that σ2v = 0 at the 1% level.

4.5 Unobserved Components Decompositions of Real GDP:MNZ Model

Recently, Morley, Nelson and Zivot (2002) have shown that the apparent differencebetween BN decomposition and the Clark model trend-cycle decomposition is due tothe assumption of independence between trend and cycle innovations in the Clarkmodel. In particular, they show that the independence assumption is actually anoveridentifying restriction in the Clark model, and once this assumption is relaxed toallow correlated components the difference between the decompositions disappears.The MNZ model is simply Clark’s model (39) where the trend and cycle innova-

tions are allowed to be correlated with correlation coefficient ρvw:µvtwt

¶iid N

µµ00

¶,

µσ2v ρvwσvσw

ρvwσvσw σ2w

¶¶The new state space system matrix Ω becomes

Ω =

σ2v ρvwσvσw 0 0

ρvwσvσw σ2w 0 00 0 0 00 0 0 0

4.5.1 Estimation

An S-PLUS function, to be passed to SsfFit, to compute the new state space form is

MNZ.mod = function(parm)

delta = parm[1]

phi1 = parm[2]

phi2 = parm[3]

sigma.v = exp(parm[4])

sigma.w = exp(parm[5])

rho.vw = parm[6]

sigma.vw = sigma.v*sigma.w*rho.vw

bigV = matrix(c(sigma.v^2,sigma.vw,sigma.vw,sigma.w^2),2,2)

Omega = matrix(0,4,4)

Omega[1:2,1:2] = bigV

a1 = matrix(0,3,1)

# solve for initial variance of stationary part

43

Page 44: State Space Survey

bigF = matrix(c(phi1,1,phi2,0),2,2)

vecV = c(sigma.w^2,0,0,0)

vecP = solve(diag(4)-kronecker(bigF,bigF))%*%vecV

P.ar2 = matrix(vecP,2,2)

Sigma = matrix(0,4,3)

Sigma[1,1] = -1

Sigma[2:3,2:3] = P.ar2

ssf.mod= list(mDelta=c(delta,0,0,0),

mPhi=rbind(c(1,0,0),c(0,phi1,phi2),c(0,1,0),c(1,1,0)),

mOmega=Omega,

mSigma = Sigma)

CheckSsf(ssf.mod)

Notice that no restrictions are placed on the correlation coefficient ρvw in the functionMNZ.mod. A box constraint −0.999 < ρvw < 0.999 will be placed on ρvw during theestimation. Starting values for the parameters are based on values near the estimatesof the Clark model from MNZ:

> MNZ.start=c(0.81,1.34,-0.70,0.21,-0.30,-0.9)

> names(MNZ.start) = c("mu","phi.1","phi.2",

+ "ln.sigma.v","ln.sigma.w","rho")

Box constraints on the AR parameters φ1 and φ2, to encourage stationarity, and thecorrelation coefficient ρvw, to enforce validity, are specified using

> low.vals = c(0,0,-2,-Inf,-Inf,-0.999)

> up.vals = c(2,2,2,Inf,Inf,0.999)

The maximum likelihood estimates and asymptotic standard errors of the parametersϕ = (µ, γv, γw, φ1, φ2, ρvw)

0 using SsfFit are

> MNZ.mle = SsfFit(MNZ.start,lny.ts,"MNZ.mod",

+ lower=low.vals,upper=up.vals)

Iteration 0 : objective = 285.6087

...

Iteration 29 : objective = 285.5696

RELATIVE FUNCTION CONVERGENCE

> MNZ.mle$parameters

mu phi.1 phi.2 ln.sigma.v ln.sigma.w rho

0.8156033 1.341859 -0.7059066 0.2125406 -0.2894671 -0.9062222

> sqrt(diag(MNZ.mle$vcov))

[1] 0.08648871 0.14473281 0.14928410 0.13088972 0.38325780

[6] 0.12658984

> # estimated standard deviations

44

Page 45: State Space Survey

Log Real GDP and Filtered Trend from MNZ Model

1950 1955 1960 1965 1970 1975 1980 1985 1990 1995

740

780

820

860

Filtered Cycle from MNZ Model

1950 1955 1960 1965 1970 1975 1980 1985 1990 1995

-1.5

-0.5

0.5

1.5

Figure 16: Filtered estimates from Clark model with correlated components for U.S.real GDP

> exp(MNZ.mle$parameters[4:5])

ln.sigma.v ln.sigma.w

1.236816 0.7486624

These estimates are almost identical to those reported by MNZ. Notice that theestimated value of ρvw is −0.91 and that the estimated standard deviation of thetrend innovation is much larger than the estimated standard deviation of the cycleinnovation.

4.5.2 Filtered estimates

The filtered estimates of the trend, τ t|t, and cycle, ct|t, given the estimated parametersare computed using

> filteredEst.MNZ = SsfMomentEst(lny.ts,

+ MNZ.mod(MNZ.mle$parameters),task="STFIL")

and are illustrated in Figure 16. Notice that the filtered estimates of trend and cycleare identical to those determined from the BN decomposition.

45

Page 46: State Space Survey

4.6 Quasi-Maximum Likelihood Estimation of Stochastic Volatil-ity Model

Let rt denote the continuously compounded return on an asset between times t−1 andt. Following Harvey, Ruiz and Shephard (1994), hereafter HRS, a simple stochasticvolatility (SV) model has the form

rt = σtεt, εt ˜iid N(0, 1) (40)

ht = lnσ2t = γ + φht−1 + ηt, ηt ˜iid N(0, σ2η)

E[εtηt] = 0

where 0 < φ < 1. Defining yt = ln r2t , and noting that E[ln ε

2t ] = 1.27 and var(ln ε

2t ) =

π2/2 an unobserved components state space representation for yt has the form

yt = −1.27 + ht + ξt, ξt ˜iid (0, π2/2)

ht = γ + φht−1 + ηt, ηt ˜iid N(0, σ2η)

E[ξtηt] = 0

If ξt were iid Gaussian then the parameters ϕ = (γ, φ, σ2η)0 of the SV model could

be efficiently estimated by maximizing the prediction error decomposition of the log-likelihood function constructed from the Kalman filter recursions. However, sinceξt = ln ε

2t is not normally distributed the Kalman filter only provides minimum mean

squared error linear estimators of the state and future observations. Nonetheless,HRS point out that even though the exact log-likelihood cannot be computed fromthe prediction error decomposition based on the Kalman filter, consistent estimatesof ϕ = (γ, φ, σ2η)

0 can still be obtained by treating ξt as though it were iid N(0, π2/2)and maximizing the quasi log-likelihood function constructed from the predictionerror decomposition.The state space representation of the SV model has system matrices

δ =

µγ−1.27

¶, Φ =

µφ1

¶, Ω =

µσ2η 00 π2/2

¶Assuming that |φ| < 1, the initial value matrix has the form

Σ =

µσ2η/(1− φ2)γ/(1− φ)

¶If φ = 1 then use

Σ =

µ −10

¶A function to compute the state space form of the SV model given a vector of

parameters, assuming |φ| < 1 is Use logistictransfor-mation toimpose therestriction0 < φ < 1.

46

Page 47: State Space Survey

sv.mod = function(parm)

g = parm[1]

sigma2.n = exp(parm[2])

phi = parm[3]

ssf.mod = list(mDelta=c(g,-1.27),

mPhi=as.matrix(c(phi,1)),

mOmega=matrix(c(sigma2.n,0,0,0.5*pi^2),2,2),

mSigma=as.matrix(c((sigma2.n/(1-phi^2)),g/(1-phi))))

CheckSsf(ssf.mod)

4.6.1 Simulated Data

T = 1000 observations are simulated from the SV model using the parameters γ =−0.3556, σ2η = 0.0312 and φ = 0.9646 :

> parm.hrs = c(-0.3556,log(0.0312),0.9646)

> nobs = 1000

> set.seed(179)

> e = rnorm(nobs)

> xi = log(e^2)+1.27

> eta = rnorm(nobs,sd=sqrt(0.0312))

> sv.sim = SsfSim(sv.mod(parm.hrs),

+ mRan=cbind(eta,xi),a1=(-0.3556/(1-0.9646)))

The simulated squared returns, r2t , and latent squared volatility, σ2t , are shown in

Figure 17.

4.6.2 Estimation

Starting values for the estimation of ϕ = (γ, φ, σ2η)0 are values close to the true values:

sv.start = c(-0.3,log(0.03),0.9)

names(sv.start) = c("g","ln.sigma2","phi")

Using SsfFit, the quasi-maximum likelihood (QML) estimates are

> low.vals = c(-Inf,-Inf,-0.999)

> up.vals = c(Inf,Inf,0.999)

> sv.mle = SsfFit(sv.start,sv.sim[,2],"sv.mod",

+ lower=low.vals,upper=up.vals)

Iteration 0 : objective = 5147.579

...

Iteration 13 : objective = 2218.26

RELATIVE FUNCTION CONVERGENCE

47

Page 48: State Space Survey

Simulated values from SV model

0 200 400 600 800 1000

0.0

0.00

020.

0004

0.00

060.

0008

0.00

10volatilitysquared returns

Figure 17: Simulated data from SV model.

> sv.mle$parameters

g ln.sigma2 phi

-0.481554 -3.561523 0.9508832

> exp(sv.mle$parameters[2])

sigma2

0.02839554

These values are fairly close to the true values9.

4.6.3 Filtered and Smoothed Estimates

The filtered and smoothed estimates of log-volatility and volatility are computedusing

9Currently, SsfFit does not compute the “sandwhich” covariance matrix estimator required forthe quasi-mles.

48

Page 49: State Space Survey

0 200 400 600 800 1000

-11

-10

-9-8

actualfilteredsmoothed

Figure 18: Actual and estimated log-volatility from simulated stochastic volatilitymodel.

# compute filtered and estimates of log volatility

filteredEst.sv = SsfMomentEst(sv.sim[,2],

sv.mod(sv.mle$parameters),task="STFIL")

filtered.var = exp(filteredEst.sv$state.moment)

smoothedEst.sv = SsfMomentEst(sv.sim[,2],

sv.mod(sv.mle$parameters),task="STSMO")

smoothed.var = exp(smoothedEst.sv$state.moment)

These estimates are illustrated in Figure 18.

4.7 Monte Carlo Maximization Likelihood Estimation of Stochas-tic Volatility Model

The QML estimation of the SV model (40) described in the previous section is con-sistent but inefficient. Sandmann and Koopman (1998) consider maximization ofthe exact log-likelihood function of the SV model using importance sampling-basedMonte Carlo methods to approximate the exact log-likelihood function based on thelog χ21 density of ξt = ln ε

2t . To illustrate the method, let ϕ = (γ, φ, σ

2η)0 denote the

49

Page 50: State Space Survey

parameters of the SV model and let yt = ln r2t denote the log squared returns. The

exact log-likelihood of the non-Gaussian SV model may be expressed as

lnL(y|ϕ) = lnLG(y|ϕ) + lnEG

·ptrue(ξ|ϕ)pG(ξ|ϕ)

¸(41)

where lnLG(y|ϕ) is the log-likelihood function of the approximating Gaussian model,ptrue(ξ|ϕ) is the true density function of the measurement disturbances (log χ21 den-sity), pG(ξ|ϕ) is the Gaussian (importance) density of the measurement disturbancesof the approximating model and EG denotes expectation with respect to the Gaus-sian (importance) density pG(ξ|ϕ). Equation (41) shows that the non-Gaussian log-likelihood may be decomposed into a Gaussian log-Likelihood plus a correction termto account for departures from normality. Sandmann and Koopman propose to esti-mate ϕ by maximizing the unbiased estimate of (41):

\lnL(ϕ) = lnLG(y|ϕ) + ln w + s2w2Nw2

(42)

The terms w and s2w are computed using the following algorithm:

1. Choose a Gaussian approximating model from which a feasible sampling schemecan be deducted based on the importance density pG(ξ|y,ϕ).

2. Compute lnLG(y|ϕ), and ξ = E[ξ|y,ϕ] for the approximating model via theKalman smoother

3. Generate a sample ξ(i) = (ξ(i)1 , . . . , ξ

(i)T )

0 from the importance density pG(ξ|y,ϕ)using the simulation smoother

4. Construct an antithetic sample: ξ(i)= 2ξ − ξ(i)

5. Compute

w(i) =w(ξ(i)) + w(ξ

(i))

2, w(ξ) =

ptrue(ξ|ϕ)pG(ξ|ϕ)

6. Repeat steps 3-5 until N samples are drawn

7. Calculate w and s2w as the sample mean and variance of w(i), i = 1, . . . , N.

The Monte Carlo maximum likelihood (MCML) estimates of ϕ are those which max-imize (42). Starting values for the optimization may be based on the QML estimates.The choice of N in step 6 determines the accuracy of (42). Sandmann and Koopmanfind that N = 5 is sufficient.The following S-PLUS function implements the above algorithm for constructing

the non-Gaussian log-likelihood function (42).

Insert S-PLUS function code here

Add comments to code

50

Page 51: State Space Survey

4.8 Affine Term Structure Models

Traditionally the study of the term structure of interest rates focuses on either thecross sectional aspect of the yield curve, or the time series properties of the inter-est rate. Recently, reserchers have utilized state space models and Kalman filteringtechniques to estimate affine term structure models, by combining both time seriesand cross sectional data. For simple models, the state space representation is oftenlinear and Gaussian and analysis is straightforward. For more general models, theunobserved state variables generally influence the variance of the transition equa-tion errors making the errors non-Gaussian. In these cases, non-standard state spacemethods are necessary. This section illustrates how some common affine term struc-ture models may be expressed in state space form, estimated and evaluated using theKalman filter and smoothing algorithms in S+FinMetrics/SsfPack. The notationand examples are taken from Duan and Simonato (1999).

4.8.1 Brief Review of Affine Term Structure Models

Duffie and Kan (1996) show that many of the theoretical term structure models,such as the Vasicek (1977) Ornstein-Uhlenbeck model, Cox, Ingersoll and Roll (1985)square root diffusion model and its multi-factor extensions (for example, see Chenand Scott, 1993), Longstaff and Schwartz (1992) two-factor model, and Chen (1996)three factor model, are special cases of the class of affine term structure models. Theclass of affine term structure models is one in which the yields to maturity on default-free pure discount bonds and the instantaneous interest rate are affine (constant pluslinear term) functions of m unobservable state variables Xt, which are assumed tofollow an affine diffustion process

dXt = U(Xt;Ψ)dt+Σ(Xt;Ψ)dWt, (43)

whereWt is an m× 1 vector of independent Wiener processes; Ψ is a p× 1 vector ofof model specific parameters; U(·) and Σ(·) are affine functions in Xt such that (43)has a unique solutions. The functions U(·) and Σ(·) can be obtained as the solutionto some ordinary differential equations. In this class of models, the price at time t ofa default-free prue discount bond with time to maturity τ has the form

Pt(Xt;Ψ, τ ) = A(Ψ, τ) exp −B(Ψ, τ )0Xt (44)

where A(τ ,Ψ) is a scalar function and B(τ ,Ψ) is an m×1 vector function. The time-t continuously compounded yield-to-maturity on a pure discount bond with time tomaturity τ is defined as

Yt(Xt;Ψ, τ ) = − lnPt(Xt;Ψ, τ)

τ, (45)

which, using (45), has the form

Yt(Xt;Ψ, τ) = − lnA(Ψ, τ)

τ+B(Ψ, τ)0Xt

τ(46)

51

Page 52: State Space Survey

4.8.2 State Space Representation

Although (46) dictates an exact relationship between the yield Yt(τ) and the statevariables Xt, in econometric estimation it is usually treated as an approximationgiving rise to the measurement equation

Yt(τ) = − lnA(Ψ, τ)

τ+B(Ψ, τ)0Xt

τ+ εt(τ), (47)

where εt is a normally distributed measurement error with zero mean and varianceσ2τ . For any time to maturity τ , the above equation can be naturally treated asthe measurement equation of a state space model, with Xt being the unobservedstate variable. To complete the state space representation, the transition equationfor Xt over a discrete time interval h needs to be specified. Defining Φ(Xt;Ψ, h) =var(Xt+h|Xt), Duan and Simonato (1999) show that the transition equation for Xt

has the formXt+h = a(Ψ, h) + b(Ψ, h)Xt +Φ(Xt;Ψ, h)1/2ηt+h (48)

where ηt ˜iid N(0, Im), and Φ(Xt;Ψ, h)1/2 represents the Cholesky factorization ofΦ(Xt;Ψ, h).In general, the state space model defined by (47) and (48) is non-Gaussian because

the conditional variance of Xt+h in (48) depends on Xt. Only for the special case inwhichΣ(·) in (43) is not a function ofXt, is the conditional variance termΦ(Xt;Ψ, h)also not a function ofXt and the state space model is Gaussian

10. See Lund (1997) fora detailed discussion of the econometric issues associated with estimating affine termstructure models using the Kalman filter. Although the quasi-maximum likelihoodestimator of the model parameters based on the modified Kalman filter is inconsisi-tent, the Monte Carlo results in Duan and Simonato (1999) and de Jong (2000) showthat bias is very small even for moderately small samples likely to be encountered inpractice.

4.8.3 Data for Examples

The data used for the following examples are in the S+FinMetrics “timeSeries”fama.bliss, and consist of four monthly yield series over the period April, 1964 toDecember, 1997 for the U.S. Treasury debt securities with maturities of 3, 6, 12 and60 months, respectively. All rates are continuously componed rates expressed on anannual basis. These rates are displayed in Figure 19.

4.8.4 Estimation of Vasicek’s Model

In the Vasicek (1977) model, the state variable driving the term structure is theinstantaneous (short) interest rate, rt, and is assumed to follow the mean-reverting

10To estimate the non-Gaussian state space model, Duan and Simonato modify the Kalman fil-ter recursions to incorporate the presense of Φ(Xt;Ψ, h) in the conditional variance of η

t+h. The

S+FinMetrics/SsfPack functions KalmanFil and SsfLoglike were modified accordingly.

52

Page 53: State Space Survey

1965 1970 1975 1980 1985 1990 1995

0.04

0.06

0.08

0.10

0.12

0.14

0.16

3M6M12M60M

Figure 19: Monthly yields on U.S. treasury debt securities.

diffusion processdrt = κ(θ − rt)dt+ σdWt, κ ≥ 0, σ > 0 (49)

where Wt is a scalar Wiener process, θ is the long-run average of the short rate, κis a speed of adjustment parameter, and σ is the volatility of rt.Duan and Simonato(1999) show that the functions A(·), B(·), a(·), b(·) and Φ(·) have the form

lnA(Ψ, τ) = γ(B(Ψ, τ)− τ )− σ2B2(Ψ, τ )

4κ, B(Ψ, τ) =

1

κ(1− exp(−κτ))

γ = θ +σλ

κ− σ2

2κ2

a(Ψ, h) = θ(1− exp(−κh)), b(Ψ, h) = exp(−κh)Φ(Xt;Ψ, h) = Φ(Ψ, h) =

σ2

2κ(1− exp(−2κh))

where λ is the risk premium parameter. The model parameters are Ψ = (κ, θ, σ, λ)0.Notice that for the Vasicek model, Φ(Xt;Ψ, h) = Φ(Ψ, h) so that the state variable

53

Page 54: State Space Survey

rt does not influence the conditional variance of transition equation errors, the statespace model is Gaussian.The state space representation of the Vasicek model has system matrices

δ =

a(Ψ, h)

− lnA(Ψ, τ 1)/τ 1...

− lnA(Ψ, τ 4)/τ 4

, Φ =

b(Ψ, h)

B(Ψ, τ 1)/τ 1...

B(Ψ, τ 4)/τ 4

(50)

Ω = diag(Φ(Ψ, h), σ2τ1 , . . . , σ2τ4)

and initial value matrix

Σ =

µθ

σ2/2κ

¶based on the stationary distribution of the short rate in (49). Notice that this amultivariate state space model.A function to compute the state space form of the Vasicek model for a given set

of parameters Ψ, number of yields τ 1, . . . , τN , and sampling frequency h is

vasicek.ssf = function(param, tau=NULL, freq=1/52)

## 1. Check for valid input.

if (length(param) < 5)

stop("param must have length greater than 4.")

N = length(param) - 4

if (length(tau) != N)

stop("Length of tau is inconsistent with param.")

## 2. Extract parameters and impose constraints.

Kappa = exp(param[1]) ## Kappa > 0

Theta = exp(param[2]) ## Theta > 0

Sigma = exp(param[3]) ## Sigma > 0

Lamda = param[4]

Var = exp(param[1:N+4]) ## meas eqn stdevs

## 3. Compute Gamma, A, and B.

Gamma = Theta + Sigma * Lamda / Kappa - Sigma^2 / (2 * Kappa^2)

B = (1 - exp(-Kappa * tau)) / Kappa

lnA = Gamma * (B - tau) - Sigma^2 * B^2 / (4 * Kappa)

## 4. Compute a, b, and Phi.

a = Theta * (1 - exp(-Kappa * freq))

b = exp(-Kappa * freq)

Phi = (Sigma^2 / (2 * Kappa)) * (1 - exp(-2 * Kappa * freq))

## 5. Compute the state space form.

mDelta = matrix(c(a, -lnA/tau), ncol=1)

54

Page 55: State Space Survey

mPhi = matrix(c(b, B/tau), ncol=1)

mOmega = diag(c(Phi, Var^2))

## 6. Duan and Simonato used this initial setting.

A0 = Theta

P0 = Sigma * Sigma / (2*Kappa)

mSigma = matrix(c(P0, A0), ncol=1)

## 7. Return state space form.

ssf.mod = list(mDelta=mDelta, mPhi=mPhi, mOmega=mOmega, mSigma=mSigma)

CheckSsf(ssf.mod)

Notice that the exponential transformation is used for those parameters that shouldbe positive, and, since the data in fama.bliss are monthly, the default length of thediscrete sampling interval, h, is set to 1/12.Starting values for the parameters and the matruity specification for the yields

are

> start.vasicek = c(log(0.1), log(0.06), log(0.02), 0.3, log(0.003),

+ log(0.001), log(0.003), log(0.01))

> names(start.vasicek) = c("ln.kappa","ln.theta","ln.sigma","lamda",

+ "ln.sig.3M","ln.sig.6M","ln.sig.12M","ln.sig.60M")

> start.tau = c(0.25, 0.5, 1, 5)

The maximum likelihood estimates for the parametersϕ = (lnκ, ln θ, lnσ, λ, lnστ1 , lnστ2 , lnστ3 , lnστ4)0

using SsfFit are

> ans.vasicek = SsfFit(start.vasicek, fama.bliss, vasicek.ssf,

+ tau=start.tau, freq=1/12, trace=T,

+ control=nlminb.control(abs.tol=1e-6, rel.tol=1e-6,

+ x.tol=1e-6, eval.max=1000, iter.max=500))

Iteration 0 : objective = -6347.453

...

Iteration 37 : objective = -6378.45

RELATIVE FUNCTION CONVERGENCE

> ssf.fit = vasicek.ssf(ans.vasicek$parameters,tau=start.tau,freq=1/12)

> ans.vasicek$parameters[-4] = exp(ans.vasicek$parameters[-4])

> names(ans.vasicek$parameters) = c("kappa","theta","sigma","lamda",

+ "sig.3M","sig.6M","sig.12M","sig.60M")

> dg = ans.vasicek$parameters; dg[4] = 1

> ans.vasicek$vcov = diag(dg) %*% ans.vasicek$vcov %*% diag(dg)

> summary(ans.vasicek,digits=4)

Log-likelihood: -6378.45

1620 observations

55

Page 56: State Space Survey

Parameters:

Value Std. Error t value

kappa 0.11883000 0.0135799 8.7504

theta 0.05738660 0.0267813 2.1428

sigma 0.02138420 0.0007906 27.0489

lamda 0.34769500 0.1493230 2.3285

sig.3M 0.00283512 0.0001011 28.0453

sig.6M 0.00002155 0.0005905 0.0365

sig.12M 0.00301624 0.0001083 27.8416

sig.60M 0.00990032 0.0003718 26.6254

These results are almost identical to those reported by Duan and Simonato (1999). Allparameters are significant at the 5% level except the measurement equation standarddeviation for the six month matruity yield. The largest measurement equation errorstandard deviation is for the sixty month yield, indicating that the model has thepoorest fit for this yield. The short rate is mean reverting since κ > 0, and the long-run average short rate is θ = 5.74% per year. The estimated risk premium parameter,λ = 0.3477, is positive indicating a positive risk premium for bond prices.The smoothed estimates of the short-rate and the yields are computed using

SsfCondDens with task=\STSMO"

> m.s = SsfCondDens(fama.bliss, ssf.fit)

The smoothed yield estimates are displayed in Figure 20. The model fits well on theshort end of the yield curve but poorly on the long end. As another check on thefit of the model, the presence of serial correlation in the standardized innovations istested using the Box-Ljung modified Q-statistic (computed using the S+FinMetricsfunction autocorTest)

> autocorTest(KalmanFil(fama.bliss,ssf.fit)$std.innov)

Test for Autocorrelation: Ljung-Box

Null Hypothesis: no autocorrelation

Test Statistics:

3M 6M 12M 60M

Test Stat 80.9471 282.4316 756.3304 3911.7736

p.value 0.0000 0.0000 0.0000 0.0000

Dist. under Null: chi-square with 26 degrees of freedom

Total Observ.: 405

The null of no serial correlation is easily rejected for the standardized innovations ofall yields.

56

Page 57: State Space Survey

Actual vs. Smoothed: 3M

1965 1970 1975 1980 1985 1990 1995

0.04

0.08

0.12

0.16

Actual vs. Smoothed: 6M

1965 1970 1975 1980 1985 1990 1995

0.04

0.08

0.12

0.16

Actual vs. Smoothed: 12M

1965 1970 1975 1980 1985 1990 1995

0.04

0.08

0.12

0.16

Actual vs. Smoothed: 60M

1965 1970 1975 1980 1985 1990 1995

0.04

0.08

0.12

Figure 20: Smoothed estimated of yields from Vasicek term structure model.

4.8.5 Estimation of Chen and Scott’s Two Factor Model

In the two factor model of Chen and Scott (1992), the unobserved state variables areassumed to follow the mean-reverting square root diffusions

dXi,t = κi(θi − xi,t)dt+ σi

pXi,tdWi,t, i = 1, 2

where W1,t and W2,t are independent Wiener processes. As in the Vasicek model,κi is a mean-reversion parameter and θi measures the long-run average level of thestate variable. However, unlike the Vasicek model, the levels of the state variablesinfluence their volatility. For this model, Duan and Simonato (1999) show that thefunctions A(·) and B(·) have the form

A(Ψ, τ) = A1(Ψ, τ ) · A2(Ψ, τ )

B(Ψ, τ) = [B1(Ψ, τ), B2(Ψ, τ)]

57

Page 58: State Space Survey

where

Ai(Ψ, τ) =

·2γi exp((κi + λi + γi)τ/2

(κi + λi + γi)(exp(γiτ)− 1) + 2γi

¸2κiθi/σ2i

Bi(Ψ, τ) =2(exp(γiτ )− 1)

(κi + λi + γi)(exp(γiτ)− 1) + 2γi

γi =q(κi + λi)2 + 2σ2i

for i = 1, 2. They also show that the functions a(·),b(·) and Φ(·) are given by

a(Ψ, h) =

µθ1(1− exp(−κ1h))θ2(1− exp(−κ2h))

¶(51)

b(Ψ, h) =

µexp(−κ1h) 0

0 exp(−κ2h)¶

(52)

Φ(Xt;Ψ, h) =

µΦ1(X1,t;Ψ, h) 0

0 Φ2(X2,t;Ψ, h)

¶(53)

with

Φi(Xi,t;Ψ, h) = Xi,t

µσ2iκi

¶[exp(−κih)− exp(−2κih)] + θi

µσ2i2κi

¶[1− exp(−κih)]

2

for i = 1, 2. The risk premium parameters are λ1 and λ2, and λi < 0 implies apositive premium in bond prices for factor i = 1, 2. The model parameters are Ψ =(κ1, κ2, θ1, θ2, σ1, σ2, λ1, λ2)

0. Notice that for the Chen-Scott model, the state variablesXt influence the conditional variance of transition equation errors and so the statespace model is non-Gaussian.The state space representation of the Chen-Scott model has system matrices of

the form (50), where a(Ψ, h) is replaced by (51), b(Ψ, h) is replaced by the 2 × 1vector of non-zero elements of (52), and Φ(Ψ, h) is replaced by (53).A function to compute the state space form of the Chen-Scott model for a given

set of parameters Ψ, number of yields τ 1, . . . , τN , and sampling frequency h is

chen.ssf =

function(param, tau=NULL, freq=1/52, n.factors=2)

## 1. Check for valid input.

if (length(param) <= n.factors*4)

stop("param must have length greater than ", 4*n.factors)

N = length(param) - 4*n.factors

if (length(tau) != N)

stop("Length of tau is inconsistent with param.")

## 2. Extract parameters and impose constraints.

58

Page 59: State Space Survey

Kappa = exp(param[1:n.factors]) ## Kappa > 0

Theta = exp(param[n.factors+1:n.factors]) ## Theta > 0

Sigma = exp(param[2*n.factors+1:n.factors]) ## Sigma > 0

Lambda = param[3*n.factors+1:n.factors] ## Lambda < 0

Var = exp(param[1:N+n.factors*4])

## 3. Compute Gamma, A, and B.

Gamma = sqrt((Kappa + Lambda)^2 + 2 * Sigma^2)

A = B = matrix(0, N, n.factors)

for (i in 1:n.factors)

denom = (Kappa[i] + Lambda[i] + Gamma[i])*

(exp(Gamma[i]*tau) - 1) + 2 * Gamma[i]

A[,i] = (2*Gamma[i]*exp((Kappa[i]+Lambda[i]+Gamma[i])

*tau/2)/denom)^(2*Kappa[i]*Theta[i]/(Sigma[i]^2))

B[,i] = 2*(exp(Gamma[i]*tau)-1)/denom

AA = rep(1, length(tau))

for (i in 1:n.factors)

AA = AA * A[,i]

## 4. Compute a, b, Phi, and vS. Notice new mAffine term

a = Theta * (1 - exp(-Kappa * freq))

b = diag(exp(-Kappa * freq))

Phi = Theta * (Sigma^2) / (2 * Kappa) * (1 - exp(-Kappa*freq))^2

mAffine = Sigma^2 / Kappa * (exp(-Kappa*freq) - exp(-2*Kappa*freq))

## 5. Computer the state space form.

mDelta = matrix(c(a, -log(AA)/tau), ncol=1)

mPhi = rbind(b, B/tau)

mOmega = diag(c(Phi, Var^2))

## 6. Duan and Simonato used this initial setting.

A0 = Theta

P0 = diag(Sigma^2 * Theta / (2*Kappa))

mSigma = rbind(P0, A0)

## 7. Return state space form.

ssf.mod = list(mDelta=mDelta, mPhi=mPhi, mOmega=mOmega,

mSigma=mSigma, mAffine=mAffine)

CheckSsf(ssf.mod)

Since state variables influence the conditional variance of the state equation errors,the S+FinMetrics/SsfPack functions KalmanFil and SsfLoglike were modified tohandle this. As a result, a new component mAffine is allowed in the state spacerepresentation to specify how the state variables influence the conditional variance.Starting values for the parameters and the matruity specification for the yields

59

Page 60: State Space Survey

are

> start.chen = c(log(0.3), log(0.2), log(0.06), log(0.03), log(0.04),

> log(0.02), -0.5, -0.5, log(0.001), log(0.001), log(0.001), log(0.001))

> names(start.chen) = c(paste("kappa", 1:2, sep="."),

+ paste("theta", 1:2, sep="."),

+ paste("sigma", 1:2, sep="."),

+ paste("lamda", 1:2, sep="."),

+ paste("s",1:4,sep=""))

start.tau = c(0.25, 0.5, 1, 5)

The maximum likelihood estimates for the parametersϕ = (Ψ0, lnστ1 , lnστ2, lnστ3 , lnστ4)0

using SsfFitFast are

> ans.chen = SsfFitFast(start.chen, fama.bliss, chen.ssf,

+ n.factors=2, tau=start.tau, freq=1/12, trace=T,

+ control=nlminb.control(abs.tol=1e-6, rel.tol=1e-6, x.tol=1e-6))

Iteration 0 : objective = 295973.9

...

Iteration 52 : objective = -7161.388

RELATIVE FUNCTION CONVERGENCE

> ssf.fit = chen.ssf(ans.chen$parameters, tau=start.tau, freq=1/12, n.factors=2)

> ans.chen$parameters[-c(7,8)] = exp(ans.chen$parameters[-c(7,8)])

> tmp = ans.chen$parameters

> tmp[7:8] = 1

> ans.chen$vcov = diag(tmp) %*% ans.chen$vcov %*% diag(tmp)

> summary(ans.chen,digits=4)

RELATIVE FUNCTION CONVERGENCE

Log-likelihood: -7161.39

1620 observations

Parameters:

Value Std. Error t value

kappa.1 0.89165700 0.06854230 13.0089

kappa.2 0.01265400 0.01250360 1.0120

theta.1 0.06972790 0.00482700 14.4454

theta.2 0.03805760 0.04609060 0.8257

sigma.1 0.07521550 0.00292212 25.7400

sigma.2 0.27804600 0.01321010 21.0480

lamda.1 -0.55659100 0.05947970 -9.3577

lamda.2 -1.51277000 0.22298200 -6.7843

s1 0.00237142 0.00008490 27.9304

s2 0.00001733 0.00010150 0.1707

s3 0.00218652 0.00007874 27.7682

60

Page 61: State Space Survey

Smoothed Estimate of 1st Factor

1965 1970 1975 1980 1985 1990 1995

0.04

0.08

0.12

0.16

Smoothed Estimate of 2nd Factor

1965 1970 1975 1980 1985 1990 1995

-0.0

11-0

.007

-0.0

03

Figure 21: Smoothed estimates of state variables from the Chen-Scott two factormodel.

s4 0.00056721 0.00029906 1.8966

The estimation results for the Chen-Scott model are different from those reported byDuan and Simonato (1999), but are qualitatively similar. The first factor appearsto be strongly mean reverting, but the small estimated value of κ2 suggests thatthe second factor is close to being non-stationary. Both risk premium parametersare estimated to be negative, indicating a positive risk premium on bonds. Themagnitudes of the estimated measurement error standard deviations indicate thatthe model fits best at the six month and twleve month maturities and worst at thethree month maturity.The smoothed estimates of the factors are given in Figure 21. The first factor

may be interpreted as a short-rate. It is not clear how to interpret the second factor.The smoothed yield estimates are displayed in Figure . Overall, the Chen-Scott twofactor model fits the term structure much better than the one vactor Vasicek model.

61

Page 62: State Space Survey

Actual vs. Smoothed: 3M

1965 1970 1975 1980 1985 1990 1995

0.04

0.08

0.12

0.16

Actual vs. Smoothed: 6M

1965 1970 1975 1980 1985 1990 1995

0.04

0.08

0.12

0.16

Actual vs. Smoothed: 12M

1965 1970 1975 1980 1985 1990 1995

0.04

0.08

0.12

0.16

Actual vs. Smoothed: 60M

1965 1970 1975 1980 1985 1990 1995

0.04

0.06

0.08

0.10

0.12

0.14

Figure 22: Smoothed estimates of yields from Chen-Scott two factor model.

62

Page 63: State Space Survey

References

[1] Bomhoff, E. J. (1994). Financial Forecasting for Business and Economics.Academic Press, San Diego.

[2] Carmona, R. (2001). Statistical Analysis of Financial Data, with an Imple-mentation in Splus. Textbook under review.

[3] Chan, N.H. (2002). Time Series: Applications to Finance. John Wiley & Sons,New York.

[4] Chen, R.-R., and L. Scott (1993). “Maximum Likelihood Estimation for aMultifactor Equilibrium Model of the Term Structure of Interest Rates”, Journalof Fixed Income, 3, 14-31.

[5] Clark, P. K. (1987). “The Cyclical Component of U.S. Economic Activity,”The Quarterly Journal of Economics, 102, 797-814.

[6] Cox, J. C., J. E. Ingersoll, and S. A. Ross (1985). “A Theory of theTerm Structure of Interest Rates”, Econometrica, 53, 385-408.

[7] Dai, Q. and K. J. Singleton (2000). “Specification Analysis of Affine TermStructure Models”, Journal of Finance, 55 (5), 1943-1978.

[8] de Jong, P. and J. Penzer (1998). “Diagnosing Shocks in Time Series,”Journal of the American Statistical Association, 93, 796-806.

[9] de Jong, F. (2000). “Time Series and Cross Section Information in Affine TermStructure Models”, Journal of Business and Economic Statistics, 18 (3), 300-314.

[10] Durbin, J. and S.J. Koopman (2001). Time Series Analysis by State SpaceMethods. Oxford University Press, Oxford.

[11] Duan, J.-C., and Sinomato, J. (1999). “Estimating and Testing Exponential-Affine Term Structure Models by Kalman Filter”, Review of Quantitative Fi-nance and Accounting, 13, 111-135.

[12] Duan, J.-C. and J.-G. Simonato (1999). “Estimating Exponential-AffineTerm Structure Models by Kalman Filter,” Review of Quantitative Finance andAccounting, 13, 111-135.

[13] Duffie, D. and R. Kan (1996). “A Yield-Factor Model of Interest Rates”,Mathematical Finance, 6 (4), 379-406.

[14] Hamilton, J.D. (1994a). Time Series Analysis. Princeton University Press,Princeton.

63

Page 64: State Space Survey

[15] Hamilton, J.D. (1994a). “State-Space Models,” in Handbook of Econometrics,e.d. R.F. Engel and D.L. McFadden, vol. 4, chapter 50, 3014-3077.

[16] Harvey, A. C. (1985). “Trends and Cycles in Macroeconomic Time Series,”Journal of Business and Economic Statistics, 3, 216-27.

[17] Harvey, A. C. (1985). “Applications of the Kalman Filter in Econometrics,”in Advances in Econometrics, Fifth World Congress of the Econometric Society,ed. T. Bewley, vol. 1., 285-313.

[18] Harvey, A. C. (1989). Forecasting, Structural Time Series Models and theKalman Filter. Cambridge University Press, Cambridge.

[19] Harvey, A.C. (1993). Time Series Models, 2nd edition. MIT Press, Cambridge.

[20] Harvey, A.C. (2001). “Testing in Unobserved Components Models,” Journalof Forecasting, 20, 1-19.

[21] Harvey, A.C. and S.-J. Koopman (1992). “Diagnostic Checking ofUnobserved-Component Time Series Models,” Journal of Business and Eco-nomic Statistics, 10, 377-389.

[22] Harvey, A.C., E. Ruiz and N. Shephard (1994). “Multivariate StochasticVariance Models,” Review of Economic Studies, 61, 247-264.

[23] Kim, C.-J., and C.R. Nelson (1999). State-Space Models with Regime Switch-ing. MIT Press, Cambridge.

[24] Kwiatkowski, D., P.C.B. Phillips, P. Schmidt, and Y. Shin (1992).“Testing the Null Hypothesis of Stationarity Against the Alternative of a UnitRoot: How Sure Are We that Economic Time Series Have a Unit Root?”, Journalof Econometrics, 44, 159-178.

[25] Koopman, S.J., N. Shephard, and J.A. Doornik (1999). “Statistical Al-gorithms for State Space Models Using SsfPack 2.2,” Econometrics Journal, 2,113-166.

[26] Koopman, S.J., N. Shephard, and J.A. Doornik (2001). “SsfPack 3.0beta:Statistical Algorithms for Models in State Space,” unpublished manuscript, FreeUniversity, Amsterdam.

[27] Lund, J. (1997). “Econometric Analysis of Continuous-Time Arbitrage-FreeModels of the Term Structure of Interest Rates,” unpublished manuscript, De-partment of Finance, The Aarhus School of Business, Denmark.

64

Page 65: State Space Survey

[28] Engle, R.F. and M.W. Watson (1987). “The Kalman Filter: Applications toForecasting and Rational Expectations Models,” in T.F. Bewley (ed.) Advancesin Econometrics: Fifth World Congress, Volume I. Cambridge University Press,Cambridge.

[29] Morley, J.C. (2002). “A State-Space Approach to Calculating the Beveridge-Nelson Decomposition,” Economics Letters, 75, 123-127.

[30] Morley, J.C., C.R. Nelson and E. Zivot (2002). “Why are Beveridge-Nelson and Unobserved Components Decompositions of GDP So Different?,”forthcoming in Review of Economics and Statistics.

[31] Neumann, T. (2002). “Time-Varying Coefficient Models: A Comparison of Al-ternative Estimation Strategies,” unpublished manuscript, DZ Bank, Germany.

[32] Sandmann, G. and S.J. Koopman (1998). “Estimation of Stochastic Volatil-ity Models via Monte Carlo Maximum Likelihood,” Journal of Econometrics, 87,271-301.

[33] Shumway, R.H. and D.S. Stoffer (2000). Time Series Analysis and ItsApplications. Springer-Verlag, New York.

[34] Vasicek, O. A. (1977). “An Equilibrium Characterization of the Term Struc-ture”, Journal of Financial Economics, 49, 1278-1304.

[35] West, M. and J. Harrison (1997). Bayesian Forecasting and Dynamic Mod-els, 2nd edition. Springer-Verlag, New York.

[36] Zivot, E. and J. Wang (2003).Modeling Financial Time Series with S-PLUS.Springer-Verlag, New York.

65