Page 1 of 1

Mean Reverting Model_Parameter Transformation

Posted: Wed Mar 19, 2014 5:49 am
by vtsa
Dear Tom,
I’m trying to estimate time varying beta using Kalman filter and assuming that beta is mean reverting. The RATS codes are shown below. In mean reverting model, I’d like to restrict the parameter phi to the values between zero and unity by application of the parameter transformation: teta=sqrt(phi/(1-phi). In the second step, the estimated transformed parameter will be converted back to the constrained phi parameter. But I couldn’t do this parameter transformation with the RATS codes shown below. How can I implement this constraint in the estimation procedure? Could you please recommend me the solution?
Yours Faithfully
*
linreg ex_rxbank
# ex_rxu
*
*
compute beta=%beta(1),sigsqeps=%sigmasq
*
nonlin beta phi sigsqeps varw1 varw2=0.0
dec frml[rect] a
frml a = ||phi,0.0|0.0,1.0||
dec frml[rect] c
frml c = ||ex_rxu,ex_rxu||
*compute varw1=sigsqeps*0.2,varw2=sigsqeps*0.0
compute varw1=0.1,varw2=0.0
compute f=||1.0,0.0|0.0,1.0||
*
dlm(a=a,c=c,f=f,sv=sigsqeps,sw=%diag(||varw1,varw2||),exact,$
method=BFGS,y=ex_rxbank,type=filter,vhat=vhat,svhat=svhat) / xstates vstates

Re: Mean Reverting Model_Parameter Transformation

Posted: Wed Mar 19, 2014 7:44 am
by TomDoan
I'm confused about your model. You have

ex_rkbank(t) = ex_rxu(t) * beta1(t) + ex_rxu(t) * beta2(t) + noise

where beta1(t) is mean reverting and beta2(t) is a random walk. I don't know if that was your intent, but it's unlikely to work well when there is so little difference between the two. Also, EXACT is the wrong choice for a model with a stationary component; use PRESAMPLE=ERGODIC instead.

To enforce the restriction (which might not work, since the optimum might be on the boundary), you can just use

frml a = ||%cdf(theta),0.0|0.0,1.0||

where theta is the free parameter and runs between -inf and inf.

Re: Mean Reverting Model_Parameter Transformation

Posted: Wed Mar 19, 2014 2:58 pm
by vtsa
Dear Tom,
My intent is that,
Measurement equation:
Ri = (ex_rxu ex_rxu)(beta(t)-betamean|betamean) + u(t)= beta(t)*Rm+ u(t)

Transition Equation:
(beta(t)-betamean|betamean) = (phi, 0 | 0 , 1)(beta(t-1)-betamean|betamean) + (1 , 0 |0 , 1)(eta | 0)
*
set tvbetademean = xstates(t)(1)
set betam = xstates(t)(2)
set tvbeta = tvbetademean + betam
*
Am I right? If I'm not right, please inform me...

I used frml a = ||%cdf(sqrt(phi/(1-phi))),0.0|0.0,1.0|| with presample=ergodic option and i got the following result:
DLM - Estimation by BFGS
Convergence in 8 Iterations. Final criterion was 0.0000001 <= 0.0000100
Weekly Data From 2002:01:11 To 2013:08:02
Usable Observations 604
Rank of Observables 601
Log Likelihood -1102.7696

Variable Coeff Std Error T-Stat Signif
************************************************************************************
1. BETA 1.223369453 0.000000000 0.00000 0.00000000
2. PHI -0.000000002 0.000000628 -0.00291 0.99767788
3. SIGSQEPS 1.917589301 0.138166630 13.87882 0.00000000
4. VARW1 0.019245374 0.005729876 3.35878 0.00078288

That is and insignificant boundary solution for phi.

But with a = ||phi,0.0|0.0,1.0|| and presample=ergodic option I got the following:

DLM - Estimation by BFGS
Convergence in 9 Iterations. Final criterion was 0.0000009 <= 0.0000100
Weekly Data From 2002:01:11 To 2013:08:02
Usable Observations 604
Rank of Observables 602
Log Likelihood -1100.7313

Variable Coeff Std Error T-Stat Signif
************************************************************************************
1. BETA 1.223369453 0.000000000 0.00000 0.00000000
2. PHI -0.145994622 0.171548038 -0.85104 0.39474590
3. SIGSQEPS 1.787519758 0.136228476 13.12148 0.00000000
4. VARW1 0.032923753 0.008259275 3.98628 0.00006712

Again an insignificant phi. I will try other methods like moving mean-reverting models. I thank You very much, and I will wait for your response…

Re: Mean Reverting Model_Parameter Transformation

Posted: Wed Mar 19, 2014 3:40 pm
by TomDoan
I have no idea what sqrt(phi/(1-phi)) is supposed to do. You want the AR parameter (that is, the 1,1 element in A) bounded in [0,1]---that's typically done by using a distribution function (Normal or logistic) applied to a parameter running from -inf to inf. Note that if the optimum is at a boundary (possibly zero in this case), then you'll get some approximation to -inf as the parameter value.

Given the setup of the model, you need to use PRESAMPLE=ERGODIC,FREE=1 to get the correct log likelihood. See the description of the FREE option (which is to handle the treatment of the beta-mean) in the Reference Manual.

Re: Mean Reverting Model_Parameter Transformation

Posted: Fri Mar 21, 2014 12:38 pm
by vtsa
Dear Tom,
I’m new in RATS, and sometimes I’m doing mistakes. I suppose that 0<phi<1 and –inf<theta<inf. If the following codes are true (especially construction of theta parameter), I’m very grateful to You for your help. If it is not, I will study carefully users guide and reference manual.

*
nonlin beta phi theta sigsqeps varw1 varw2=0.0
compute theta = sqrt(phi/(1-phi))
dec frml[rect] a
frml a = ||%cdf(theta),0.0|0.0,1.0||
dec frml[rect] c
frml c = ||ex_rxu100,ex_rxu100||
compute varw1=0.2,varw2=0.0
compute f=||1.0,0.0|0.0,1.0||
*
dlm(a=a,c=c,f=f,sv=sigsqeps,sw=%diag(||varw1,varw2||),presample=ergodic,free=1,$
method=BFGS,y=ex_rxbank,type=filter,vhat=vhat,svhat=svhat) / xstates vstates

and I got the following results:

**
1. BETA 1.22336945 0.00000000 0.00000 0.00000000
2. PHI 0.00000000 0.00000000 0.00000 0.00000000
3. THETA -7.17011269 50.48152340 -0.14203 0.88705284
4. SIGSQEPS 1.79470574 0.09361477 19.17118 0.00000000
5. VARW1 0.03276672 0.00052025 62.98269 0.00000000

Here phi=(theta)^2/(1+theta^2)= 0.763088 (cause theta = sqrt(phi/(1-phi))= -7.17011269 )

Re: Mean Reverting Model_Parameter Transformation

Posted: Fri Mar 21, 2014 1:57 pm
by TomDoan
I don't see where "beta" is entering the model at all. As you have this modeled, your two beta's are states (one time varying, one fixed); you'll have to pull them out of the state vector from the DLM when you've finished estimating.

phi is also never entering the model. (compute theta=sqrt(phi/(1-phi)) will set a guess value for theta, but a "compute" instruction is executed once and is done, and so will not affect the estimation). You have %cdf(theta) is the reversion parameter, which means (with theta=-7.17) that you're estimating a zero there. There's nothing wrong with that---it just means that while there seems to be some time-variation in the beta, there's no serial correlation in the deviations.