Page 1 of 1

Diebold, Rudebusch & Aruoba (2006)—Dynamic Latent Factors

Posted: Tue Jan 05, 2010 9:16 am
by TomDoan
dra_joe_2006.zip is a zip with a replication for Diebold, Rudebusch & Aruoba (2006), "The macroeconomy and the yield curve: a dynamic latent factor approach," Journal of Econometrics, vol. 131(1-2), pages 309-338. (This paper is also included in the RATS distribution). The drajoe2006_v7 program is for use with RATS versions earlier than 7.3. 7.3 added several features which simplifies the calculation.

It should be a simple modification to switch the data sets. You might have to change the guess values for mu, but everything else should go through the same as with this. The estimation behavior seems to be especially sensitive to the choice of mu if the data are near unit-root; it doesn't seem to be as sensitive to the guess values for the variances.

The three factor model without the other observables is included in the Durbin and Koopman, 2nd Edition, examples as durkp202.rpf.

Re: Dynamic Latent Factor Model

Posted: Tue Jan 05, 2010 4:10 pm
by buianhtuan2000
Thank you very much Tom

Could you please advise me
What are cu pi ffr ?
and, How can I save the loading i.e. Lt,St, and Ct for each point of time in an excel file?

I look forward to hearing your relpy.
All the best

Re: Dynamic Latent Factor Model

Posted: Wed Jan 20, 2010 11:19 am
by TomDoan
buianhtuan2000 wrote:Thank you very much Tom

Could you please advise me
What are cu pi ffr ?
Those are the three observable "factors". CU is capacity utilization, PI is price inflation and FFR is the Federal Funds rate.
buianhtuan2000 wrote: and, How can I save the loading i.e. Lt,St, and Ct for each point of time in an excel file?

I look forward to hearing your relpy.
All the best
Add the TYPE=SMOOTH option and the XSTATES parameter to the DLM instruction. Then pull out the factors from the states and do a COPY.

Code: Select all

dlm(startup=%(DRASetup3(),sw=%diag(swdiag)),$
  a=a,sw=sw,sv=sv,c=lambda,y=%eqnxvector(yvars,t)-muy,$
   presample=ergodic,method=bfgs,iters=400,$
   type=smooth) / xstates
set lt = xstates(t)(1)
set st = xstates(t)(2)
set ct = xstates(t)(3)
copy(format=xls,org=columns) / lt st ct

Re: Dynamic Latent Factor Model

Posted: Thu May 27, 2010 8:39 pm
by atbui
TomDoan wrote:This is a full running example of the base model that should work with version 7. It should be a simple modification to switch the data sets. You might have to change the guess values for mu, but everything else should go through the same as with this.
Dear Tom

Could you please show me how you estimate the guess value of mu, a, sw, swdiag, svdiag and lam. I wonder if the results change when we use a difference set of guess value or not?

Thank you very much

Re: Dynamic Latent Factor Model

Posted: Fri May 28, 2010 3:12 am
by TomDoan
Unfortunately, I don't really have any good advice on that; mine (particularly the mu's) came largely from the published results, and the authors don't seem to have a record of where they started. The estimation behavior seems to be especially sensitive to the choice of mu if the data are near unit-root; it doesn't seem to be as sensitive to the guess values for the variances.

Re: Dynamic Latent Factor Model

Posted: Tue Mar 22, 2011 6:24 am
by mike80
Dear Tom,

I tried to get the shocks from the transition equation (etas in equation 5 on page 313). Is it right that these shocks can be obained by inlcuding the "what" option in the DLM instruction?

dlm(startup=%(DRASetup3(),sw=%diag(swdiag)),$
a=a,sw=sw,sv=sv,c=lambda,y=%eqnxvector(yvars,t)-muy,$
presample=ergodic,method=bfgs,iters=400,what=shocks)
then
set shockL %regstart() %regend() = shocks(t)(1)

In doing so, I have a problem with the generated series. The new series are generally not filled except an "na" as the third observation. In addition, the range of dates (heavily) exceeds the defined one. I am working with Rats 7.3.

Thanks in advance.

Kind regards.

Re: Dynamic Latent Factor Model

Posted: Tue Mar 22, 2011 5:59 pm
by TomDoan
mike80 wrote:Dear Tom,

I tried to get the shocks from the transition equation (etas in equation 5 on page 313). Is it right that these shocks can be obained by inlcuding the "what" option in the DLM instruction?

dlm(startup=%(DRASetup3(),sw=%diag(swdiag)),$
a=a,sw=sw,sv=sv,c=lambda,y=%eqnxvector(yvars,t)-muy,$
presample=ergodic,method=bfgs,iters=400,what=shocks)
then
set shockL %regstart() %regend() = shocks(t)(1)

In doing so, I have a problem with the generated series. The new series are generally not filled except an "na" as the third observation. In addition, the range of dates (heavily) exceeds the defined one. I am working with Rats 7.3.

Thanks in advance.

Kind regards.
WHAT's aren't computed when you filter, just when you smooth (or simulate). If you use the same instruction, but add TYPE=SMOOTH, you'll get the full sample estimates for the state disturbances.

Re: Dynamic Latent Factor Model

Posted: Wed Aug 10, 2011 5:27 pm
by econometrics
When I added the code for the betas I just added and not replaced and that 's why I had some added betas. Thank you for your quick replay. I am new to Rats , I just used it a little in the past. Also Tom how can I get the residuals from the fitted curve month by month?

Thank you.

Re: Dynamic Latent Factor Model

Posted: Fri Aug 12, 2011 4:08 am
by TomDoan
econometrics wrote:When I added the code for the betas I just added and not replaced and that 's why I had some added betas. Thank you for your quick replay. I am new to Rats , I just used it a little in the past. Also Tom how can I get the residuals from the fitted curve month by month?

Thank you.
Add a VHAT option to the DLM instruction. That will generate a SERIES of VECTORS. To pull out a specific component of that (assuming the option was VHAT=VHAT), you would do something like:

set r1 = vhat(t)(1)
set r2 = vhat(t)(2)
...

Re: Dynamic Latent Factor Model

Posted: Wed Aug 17, 2011 5:16 pm
by econometrics
Thank you Tom for all your help and patience.
I've wrote the code as you said and run it on the data provided for Diebold et al and are approximately the same. What I’ve did is just add a new DLM function modified for the residuals and run it separately, saving a copy in excel , but I’ve noticed that the estimated parameters have changed. I tried to run several times with just the added what=what and set the residuals for all the vectors in the DLM function, not adding a new DLM function but then the window to save the residuals didn’t appeared. Maybe you can give me some advise on how to treat the new DLM function.

Regards,
Rosa

Re: Dynamic Latent Factor Model

Posted: Fri Aug 19, 2011 5:43 pm
by econometrics
Hi Tom,

I have a problem with the estimated betas. I’ve run the program on my data and plotted the estimated factors with the empirical ones and it didn’t look good, the gap is too big especially the level. I thought to plot also the Diebold estimated betas with the empirical ones and see if are ok, the same behaviour. I must be doing something wrong and I can’t figure it out. The estimated level should be positive and starts at 5-6 percent in Diebold’s paper and the level that I’ve estimated is negative. I will attach the excel file just to see what betas I’ve got.
Thank you Tom.
Regards,
Rosa

Re: Dynamic Latent Factor Model

Posted: Sat Aug 20, 2011 7:56 am
by TomDoan
econometrics wrote:Hi Tom,

I have a problem with the estimated betas. I’ve run the program on my data and plotted the estimated factors with the empirical ones and it didn’t look good, the gap is too big especially the level. I thought to plot also the Diebold estimated betas with the empirical ones and see if are ok, the same behaviour. I must be doing something wrong and I can’t figure it out. The estimated level should be positive and starts at 5-6 percent in Diebold’s paper and the level that I’ve estimated is negative. I will attach the excel file just to see what betas I’ve got.
Thank you Tom.
Regards,
Rosa
Have you allowed for the fact that the model includes a separate mean parameter. The data is modelled as Y(t)=mu+Lambda F(t) + noise. The factors are supposed to be mean zero.

Re: Dynamic Latent Factor Model

Posted: Mon Aug 22, 2011 5:02 pm
by econometrics
Thank you Tom , it worked, really appreciating all your help!
I have another inquiry and I was trying to find information from the forum and also from your Nile files. Is about forecasting. I would like to test the out of the sample forcasting performance of the DRA model using RMSE for1 month, 6 months and 12 months ahead.How should I handle this in Rats?

I was trying :

Code: Select all

dlm(startup=%(DRASetup3()),$
a=a,sw=sw,sv=sv,c=lambda,y=%eqnxvector(yvars,t)-muy,$
presample=ergodic,method=bfgs,iters=400,type=smooth) / xstates vstates

dlm(startup=%(DRASetup3()),$
a=a,sw=sw,sv=sv,c=lambda,y=%eqnxvector(yvars,t)-muy,$
x0=xstates(2000:12),sx0=vstates(2000:12),yhat=yhat,svhat=svhat) 2001:1 2001:6

set forecast 2001:1 2001:6 = %scalar(yhat)
set stderr   2001:1 2001:6 = sqrt(%scalar(svhat))
Regards,

Rosa

Re: Dynamic Latent Factor Model

Posted: Mon Apr 23, 2018 3:49 pm
by TomDoan
econometrics wrote:Thank you Tom , it worked, really appreciating all your help!
I have another inquiry and I was trying to find information from the forum and also from your Nile files. Is about forecasting. I would like to test the out of the sample forcasting performance of the DRA model using RMSE for1 month, 6 months and 12 months ahead.How should I handle this in Rats?

I was trying :

Code: Select all

dlm(startup=%(DRASetup3()),$
a=a,sw=sw,sv=sv,c=lambda,y=%eqnxvector(yvars,t)-muy,$
presample=ergodic,method=bfgs,iters=400,type=smooth) / xstates vstates

dlm(startup=%(DRASetup3()),$
a=a,sw=sw,sv=sv,c=lambda,y=%eqnxvector(yvars,t)-muy,$
x0=xstates(2000:12),sx0=vstates(2000:12),yhat=yhat,svhat=svhat) 2001:1 2001:6

set forecast 2001:1 2001:6 = %scalar(yhat)
set stderr   2001:1 2001:6 = sqrt(%scalar(svhat))
Regards,

Rosa
If you're trying to forecast multiple steps, you don't want the "Y" option, as if you supply data, DLM which will keep doing the Kalman updating (rather than just prediction) for as long as it has observed data. Without the Y option, your second DLM would forecast for one to six periods ahead starting in 2001:1. If you want a string of six-period ahead forecasts, you would need to do that type of calculation in a loop over the end period of estimation and the start of forecasts.