Page 1 of 2

Running Kalman filter with initial data

Posted: Fri Aug 06, 2010 5:52 am
by king_luca
Hi everyone,

I'm sorry to post again a topic on Kalman Filter estimation but I'm really stuck...

I'm trying to estimate time varying betas with a kalman filter. I used to work with matlab but I have to use Eviews now and I'm new here...

Here is my workfile and the code :

@signal CON_AR = sv1*BONDS + sv2*CMDTY + sv3*CREDITS + sv4*EMMB + sv5*EMME + sv6*SP + sv7*USD + [var = exp(c(1))]

@state sv1 = sv1(-1) + [var = exp(c(2))]
@state sv2 = sv2(-1) + [var = exp(c(3))]
@state sv3 = sv3(-1) + [var = exp(c(4))]
@state sv4 = sv4(-1) + [var = exp(c(5))]
@state sv5 = sv5(-1) + [var = exp(c(6))]
@state sv6 = sv6(-1) + [var = exp(c(7))]
@state sv7 = sv7(-1) + [var = exp(c(8))]

@mprior SVEC0
@vprior SVAR0

When I hit "estimate" a message error appears : "Initial state variance prior "SVAR0" is not defined or is not a Sym object"

I don't understand, I followed the step of the manual guide to define SVEC0 and SVAR0. In my case, SVAR0 has to be a matrix 7x7 full of zeros...

I don't know if someone could run this workfile and tell me if it works ? I updated Eviews 7 but still the same problem and if I don't specify SVAR0, I get : "Missing value found in state variance matrix"

Please help me :lol:

Thank you, I really appreciate your help!

Re: Running Kalman filter with initial data

Posted: Fri Aug 06, 2010 6:41 am
by trubador
Initial state variance matrix (SVAR0 in your case) has to be a sym object not an ordinary matrix. If you have initial values for state variances as a vector (e.g. vars), then you can create a symmetric matrix as follows:

Code: Select all

sym SVAR0 = @makediagonal(vars)

Re: Running Kalman filter with initial data

Posted: Fri Aug 06, 2010 6:55 am
by king_luca
Thank you for your answer.

If I'm right, I have to create a Vector with initial values of the variance (zeros in my case) and then insert the the code you gave me instead of "SVAR0" ?

My last row of code will be : @vprior sym SVAR0 = @makediagonal(vars) ?

Thank you again

Re: Running Kalman filter with initial data

Posted: Fri Aug 06, 2010 7:06 am
by trubador
The code is for generating the symmetric matrix outside (in the command window). Do not place it into State Space object. You do not have to change the specification of your state space, since the only problem is the type of your SVAR0 matrix.

Re: Running Kalman filter with initial data

Posted: Fri Aug 06, 2010 7:08 am
by king_luca
I'm sorry, I did what you told me but I still get the error message "Missing value found in state variance matrix"...

Can you help me ? I'm really lost.

Thank you very much

Re: Running Kalman filter with initial data

Posted: Fri Aug 06, 2010 7:26 am
by trubador
Initialize the coefficents as well and fix them at the start of each estimation. Otherwise, in each estimation EViews will use the stored values in the coefficient vector from the previous estimation. Add the following line to State Space specification below your code:

Code: Select all

param c(1) .0 c(2) .0 c(3) .0 c(4) .0 c(5) .0 c(6) .0 c(7) .0 c(8) .0


Of course, you can assign different values if you have a priori information.

Re: Running Kalman filter with initial data

Posted: Fri Aug 06, 2010 8:46 am
by king_luca
I'm truly sorry but I get the same error message... "Missing value found in state variance matrix". Here is my code :

@signal CON_AR = sv1*BONDS + sv2*CMDTY + sv3*CREDITS + sv4*EMMB + sv5*EMME + sv6*SP + sv7*USD + [var = exp(c(1))]

@state sv1 = sv1(-1) + [var = exp(c(2))]
@state sv2 = sv2(-1) + [var = exp(c(3))]
@state sv3 = sv3(-1) + [var = exp(c(4))]
@state sv4 = sv4(-1) + [var = exp(c(5))]
@state sv5 = sv5(-1) + [var = exp(c(6))]
@state sv6 = sv6(-1) + [var = exp(c(7))]
@state sv7 = sv7(-1) + [var = exp(c(8))]

@mprior svec0
@vprior svar0

param c(1) .0 c(2) .0 c(3) .0 c(4) .0 c(5) .0 c(6) .0 c(7) .0 c(8) .0

and I computed sym SVAR0 = @makediagonal(vars) in the command window as you told me...

I'm sorry but could you check if it works on your system ?

Thank you trubador

Re: Running Kalman filter with initial data

Posted: Fri Aug 06, 2010 9:04 am
by startz
I opened the workfile, double-clicked on SS01, and hit Estimate. It ran with no problem, although it did report WARNING: Singular covariance.

Re: Running Kalman filter with initial data

Posted: Fri Aug 06, 2010 9:09 am
by king_luca
I don't understand why it doesn't work ?!?

Can I abuse of your kindness and ask you the results you get ? Could you post them ?

Thank you very much

Re: Running Kalman filter with initial data

Posted: Fri Aug 06, 2010 9:21 am
by startz
Glad to lend a bit of a hand. Here's the estimate using EViews 7.1 and the latest update.
Capture.JPG
Capture.JPG (114.28 KiB) Viewed 13341 times

Re: Running Kalman filter with initial data

Posted: Fri Aug 06, 2010 9:30 am
by king_luca
Thank you very much for all your help!

Have a nice day

Re: Running Kalman filter with initial data

Posted: Fri Aug 06, 2010 9:36 am
by startz
king_luca wrote:Thank you very much for all your help!

Have a nice day

I wish I could be more helpful.

You may have already answered this, but are you using the most uptodate version of EViews?

Re: Running Kalman filter with initial data

Posted: Fri Aug 06, 2010 9:54 am
by king_luca
Yes I do, I updated it... But the workfile seems to work on the system of a friend of mine.

However, I'd have one last question : how can I specify that my 7 regressors must sum to 1 ?

Thank you again for your help!

Re: Running Kalman filter with initial data

Posted: Fri Aug 06, 2010 10:18 am
by king_luca
I have 2 other, maybe silly, questions : are the results of the estimation for the coefficient c(1) to c(8) in percent ? and how can I constraint the coefficient c(1) to c(8) to be positiv ?

Thank you for all your help

Re: Running Kalman filter with initial data

Posted: Fri Aug 06, 2010 10:19 am
by startz
king_luca wrote:Yes I do, I updated it... But the workfile seems to work on the system of a friend of mine.

However, I'd have one last question : how can I specify that my 7 regressors must sum to 1 ?

Thank you again for your help!

If you mean the coefficients on the variables, replace SV7 with (1-SV1-SV2-SV3-SV4-SV5-SV6)