Page 1 of 1

MS Regression Time Varying TP Overwriting the Transition Mat

Posted: Wed Jul 27, 2016 9:29 am
by Jules89
Hello Tom,
I am quiet new on RATS and have to estimate a TVTP MS model of the following form:

Number of states: 2

deurchf=a_t +e_t, e_t~N(0, sigma^2_t)

deurchf is the first difference of the exchange rate, a_t is an intercept which is switching between state 1 and state 2. The variance sigma^2 is also switching between state 1 and state 1.

My FTP code is the following:

Code: Select all

@MSREGRESSION(States=2, Switch=CH) DEURCHF
# Constant

nonlin(parmset=regparms) betas sigsqv gammas
nonlin(parmset=msparms) p

compute gstart=2011:09:06,gend=2015:12:15
@MSRegInitial gstart gend

compute sigmalimit=1.e-6*%minvalue(sigsqv)

frml logl = f=%MSRegFVec(t),fpt=%MSProb(t,f),log(fpt)

@MSFilterInit

maximize(start=%(sigmatest=%MSRegInitVariances(),pstar=%msinit()),$
parmset=regparms+msparms,$
reject=sigmatest<sigmalimit,$
method=bfgs) logl gstart gend
Now I have the following variable for the TVTP: drreur1m
I tryed to use the code and suggestions of the following post: https://estima.com/forum/viewtopic.php? ... vtp#p11162

Here is the TVTP code I wrote:

Code: Select all

source msregression.src

@MSREGRESSION(States=2, Switch=CH) DEURCHF
# Constant

nonlin(parmset=regparms) betas sigsqv gammas
nonlin(parmset=tvtpparms) d10 d11 d20 d21

*************Overwiting the Transition Matrix:**************

frml pfrml = %cdf(d10+d11*drreur1m)
frml qfrml = %cdf(d20+d21*drreur1m)


function %MSRegPMat time
type rect %MSRegPmat
type int time
*
compute %MSRegPMat=||pfrml(time),1-qfrml(time)|1-pfrml(time),qfrml(time)||
end

**************************************************************

*Guess values for the first iteration drawn from the FTP Model:
compute d10 = 1.845
compute d20 = -1.21

compute gstart = 2011:09:06
compute gend = 2015:12:15
@MSRegInitial gstart gend

compute sigmalimit=1.e-6*%minvalue(sigsqv)

frml logl = fpt=%MSRegProb(t),log(fpt)

@MSFilterInit
maximize(start=%(sigmatest=%MSRegInitVariances(),pstar=%msinit()),$
  parmset=regparms+tvtpparms,$
  reject=sigmatest<sigmalimit,$
  method=bfgs,pmethod=simplex,piters=5) logl gstart gend
The estimates are the following:

Code: Select all

MAXIMIZE - Estimation by BFGS
Convergence in    14 Iterations. Final criterion was  0.0000085 <=  0.0000100

Daily(5) Data From 2011:09:07 To 2015:12:15
Usable Observations                      1115
Function Value                      4806.6321

    Variable                        Coeff      Std Error      T-Stat      Signif
************************************************************************************
1.  BETAS(1)(1)                  -0.000206005  0.000050549     -4.07534  0.00004595
2.  BETAS(2)(1)                   0.000107612  0.000459697      0.23409  0.81491235
3.  SIGSQV(1)                     0.000001883  0.000000171     10.98407  0.00000000
4.  SIGSQV(2)                     0.000121085  0.000010378     11.66757  0.00000000
5.  D10                              1.845000000  0.000000000      0.00000  0.00000000
6.  D11                              0.000000000  0.000000000      0.00000  0.00000000
7.  D20                             -1.210000000  0.000000000      0.00000  0.00000000
8.  D21                              0.000000000  0.000000000      0.00000  0.00000000

What did I do wrong? Could you send me any example code which is doing tvtp estimates and which is simple? I tryed to read the Filardo(1994) replication code, but it is very complicated for someone who is new to RATS.

Thank you very much for your help!

Best

Jules

Re: MS Regression Time Varying TP Overwriting the Transition

Posted: Wed Jul 27, 2016 3:33 pm
by TomDoan
Please post the whole program (not just two pieces) and the data set. I really can't tell without seeing how it runs.

Re: MS Regression Time Varying TP Overwriting the Transition

Posted: Thu Jul 28, 2016 2:18 am
by Jules89
Hi Tom,
thank you for the quick reply and sorry for not posting the whole code/data. Here it is:

Code: Select all

CALENDAR(D) 2011:9:6

*Data:
OPEN DATA "C:\Users\Jules\Desktop\DataRats.xlsx"
CALENDAR(D) 2011:09:06 
DATA(FORMAT=XLSX,NOLABELS,ORG=COLUMNS,TOP=2) 2011:09:06 2015:12:15 RR1M EXRATE


*--------------------- Differences ---------------------*
diff rr1m / drr1m
diff EXRATE / DEXRATE


*--------------------- Markov Switching Without TVTP ---------------------*

source msregression.src


@MSREGRESSION(States=2, Switch=CH) DEXRATE
# Constant

nonlin(parmset=regparms) betas sigsqv
nonlin(parmset=msparms) p



compute gstart=2011:09:06,gend=2015:12:15

@MSRegInitial gstart gend

compute sigmalimit=1.e-6*%minvalue(sigsqv)

frml logl = f=%MSRegFVec(t),fpt=%MSProb(t,f),log(fpt)

@MSFilterInit

maximize(start=%(sigmatest=%MSRegInitVariances(),pstar=%msinit()),$
parmset=regparms+msparms,$
reject=sigmatest<sigmalimit,$
method=bfgs) logl gstart gend


*--------------------- Markov Switching With TVTP ---------------------*



source msregression.src

@MSREGRESSION(States=2, Switch=CH) DEXRATE
# Constant

nonlin(parmset=regparms) betas sigsqv
nonlin(parmset=tvtpparms) d10 d11 d20 d21

*************Overwiting the Transition Matrix:**************

frml pfrml = %cdf(d10+d11*drr1m)
frml qfrml = %cdf(d20+d21*drr1m)


function %MSRegPMat time
type rect %MSRegPmat
type int time
*
compute %MSRegPMat=||pfrml(time),1-qfrml(time)|1-pfrml(time),qfrml(time)||
end

**************************************************************

*Guess values for the first iteration drawn from the FTP Model:
compute d10 = 1.845
compute d20 = -1.21

compute gstart = 2011:09:06
compute gend = 2015:12:15
@MSRegInitial gstart gend

compute sigmalimit=1.e-6*%minvalue(sigsqv)

frml logl = fpt=%MSRegProb(t),log(fpt)

@MSFilterInit
maximize(start=%(sigmatest=%MSRegInitVariances(),pstar=%msinit()),$
  parmset=regparms+tvtpparms,$
  reject=sigmatest<sigmalimit,$
  method=bfgs,pmethod=simplex,piters=5) logl gstart gend

Re: MS Regression Time Varying TP Overwriting the Transition

Posted: Thu Jul 28, 2016 11:36 am
by TomDoan
You didn't give guess values to the two "slope" coefficients in the TVTP function (though those are assumed 0, which is probably the best guess anyway). However, the problem is that you need a newer version of msregression.src.
msregression.src
(16.63 KiB) Downloaded 904 times

Re: MS Regression Time Varying TP Overwriting the Transition

Posted: Thu Jul 28, 2016 12:04 pm
by Jules89
Hey Tom,
thank you so much for your help! It works. Is there a possibility to do this regression also in the MSVARSetup enviroment? So my question ist whether it is possible to overwrite the transition matrix in this way for any of the MSxxxx(VAR,SYS, etc) procedures?
Do I also need newer Versions of the procedures?

Thank you again so much for your help! You saved my day

Best

Jules

Re: MS Regression Time Varying TP Overwriting the Transition

Posted: Fri Jul 29, 2016 3:52 am
by Jules89
Hey Tom,
in the post before I meant something like the following code, which should estimate something similar as the one above by using the @MSVARSetup:

Code: Select all


CALENDAR(D) 2011:9:6

*Data:
OPEN DATA "C:\Users\Jules\Desktop\DataRats.xlsx"
CALENDAR(D) 2011:09:06
DATA(FORMAT=XLSX,NOLABELS,ORG=COLUMNS,TOP=2) 2011:09:06 2015:12:15 RR1M EXRATE


*--------------------- Differences ---------------------*
diff rr1m / drr1m
diff EXRATE / DEXRATE

source msvarsetup.src

@MSVARSetup(lags=0 ,States=2, Switch=IH)
# DEXRATE

nonlin(parmset=regparms) mu phi sigmav
nonlin(parmset=tvtpparms) d10 d11 d20 d21

*Guess values for the first iteration drawn from the FTP Model:



*************Overwiting the Transition Matrix:**************

compute d10 = 1.845
compute d20 = -1.21
compute d11 = 0.0
compute d21 = 0.0

frml pfrml = %cdf(d10+d11*drr1m)
frml qfrml = %cdf(d20+d21*drr1m)



function %MSVARPMat t
type rect %MSVARPmat
type int t
*
compute %MSVARPMat=||pfrml(t),1-qfrml(t)|1-pfrml(t),qfrml(t)||
end

**************************************************************


compute gstart = 2011:09:06
compute gend = 2015:12:15
@msvarinitial gstart gend


frml logl = fpt=%MSVARProb(t),log(fpt)

maximize(parmset=regparms+tvtpparms,$
         start=(pstar=%MSVARInit()),$
         reject=%MSVARInitTransition()==0.0,$
         method=bfgs) logl

The same problem as before comes up. Here is the output:

Code: Select all

MAXIMIZE - Estimation by BFGS
Convergence in    22 Iterations. Final criterion was  0.0000064 <=  0.0000100

Daily(5) Data From 2011:09:07 To 2015:12:15
Usable Observations                      1115
Function Value                      4806.5584

    Variable                        Coeff      Std Error      T-Stat      Signif
************************************************************************************
1.  MU(1)(1)                      0.000273941  0.000289383      0.94664  0.34382355
2.  MU(2)(1)                     -0.000207977  0.000044048     -4.72165  0.00000234
3.  SIGMAV(1)(1,1)             0.000120321  0.000009950     12.09276  0.00000000
4.  SIGMAV(2)(1,1)             0.000001922  0.000000119     16.14361  0.00000000
5.  D10                              1.845000000  0.000000000      0.00000  0.00000000
6.  D11                              0.000000000  0.000000000      0.00000  0.00000000
7.  D20                             -1.210000000  0.000000000      0.00000  0.00000000
8.  D21                              0.000000000  0.000000000      0.00000  0.00000000

It would be very nice if you could also have a look at that. The data are the same as before.

Thank you very much in advance, I really appreciate your help.

Best

Jules