Dear Tom,
I estimated a model using Gray's code. Here is the results. Is there enough evidence about the existence of second regime?
I don't know why P(1,2) is such low. What does is mean here? Especially, why is A12 greater than minus one? Does it has show that something is wrong with the model?
Linear Regression - Estimation by Least Squares
With Heteroscedasticity-Consistent (Eicker-White) Standard Errors
Dependent Variable DRATE
Daily(5) Data From 2003:01:06 To 2012:12:06
Usable Observations 2589
Degrees of Freedom 2587
Centered R^2 0.2162382
R-Bar^2 0.2159353
Uncentered R^2 0.2162382
Mean of Dependent Variable -0.000019215
Std Error of Dependent Variable 0.710001062
Standard Error of Estimate 0.628687695
Sum of Squared Residuals 1022.5071405
Log Likelihood -2471.0231
Durbin-Watson Statistic 2.3494
Variable Coeff Std Error T-Stat Signif
************************************************************************************
1. Constant 0.000001372 0.012350981 1.11101e-004 0.99991135
2. DRATE{1} -0.465022692 0.029848275 -15.57955 0.00000000
MAXIMIZE - Estimation by BFGS
Convergence in 14 Iterations. Final criterion was 0.0000048 <= 0.0000100
Daily(5) Data From 2003:01:03 To 2012:12:06
Usable Observations 2590
Function Value -1233.4961
Variable Coeff Std Error T-Stat Signif
************************************************************************************
1. A01 0.034373643 0.016306202 2.10801 0.03503009
2. A02 -0.018158900 0.005627435 -3.22685 0.00125160
3. A11 -0.987049117 0.024645457 -40.04994 0.00000000
4. A12 -1.036718008 0.031279355 -33.14384 0.00000000
5. B01 0.676242638 0.013864548 48.77495 0.00000000
6. B02 0.178090890 0.005701714 31.23462 0.00000000
7. P(1,1) 0.964435993 0.006934697 139.07400 0.00000000
8. P(1,2) 0.038301809 0.005753795 6.65679 0.00000000
Lag Corr Partial LB Q Q Signif
1 0.089 0.089 20.64769 0.0000
2 0.309 0.303 268.42934 0.0000
3 0.122 0.084 307.28896 0.0000
4 0.101 -0.003 333.89765 0.0000
5 0.082 0.018 351.45483 0.0000
6 0.031 -0.013 354.02735 0.0000
7 0.044 0.006 359.06825 0.0000
8 0.022 0.006 360.29757 0.0000
9 0.055 0.041 368.24714 0.0000
10 0.052 0.040 375.21940 0.0000
11 0.068 0.039 387.30424 0.0000
12 0.089 0.056 408.03453 0.0000
13 0.072 0.028 421.61656 0.0000
14 0.111 0.057 453.70138 0.0000
15 0.091 0.043 475.14533 0.0000
GARCH Model - Estimation by BFGS
Convergence in 31 Iterations. Final criterion was 0.0000059 <= 0.0000100
Dependent Variable DRATE
Daily(5) Data From 2003:01:06 To 2012:12:06
Usable Observations 2589
Log Likelihood -1640.8258
Variable Coeff Std Error T-Stat Signif
************************************************************************************
1. Constant -0.002580050 0.004870402 -0.52974 0.59629165
2. DRATE{1} -0.486710196 0.017265759 -28.18933 0.00000000
3. C 0.001934000 0.000469922 4.11558 0.00003862
4. A 0.318002213 0.026901340 11.82105 0.00000000
5. B 0.744130400 0.017127159 43.44739 0.00000000
Lag Corr Partial LB Q Q Signif
1 -0.031 -0.031 2.552248 0.1101
2 0.070 0.069 15.294223 0.0005
3 -0.028 -0.024 17.282169 0.0006
4 -0.015 -0.021 17.855229 0.0013
5 -0.039 -0.037 21.893056 0.0005
6 -0.043 -0.043 26.625084 0.0002
7 -0.036 -0.035 30.074676 0.0001
8 -0.038 -0.037 33.871933 0.0000
9 -0.032 -0.034 36.612003 0.0000
10 -0.001 -0.003 36.617247 0.0001
11 -0.022 -0.025 37.857947 0.0001
12 -0.011 -0.021 38.194854 0.0001
13 -0.012 -0.017 38.548140 0.0002
14 -0.029 -0.037 40.769661 0.0002
15 0.002 -0.006 40.779242 0.0003
MAXIMIZE - Estimation by BFGS
Convergence in 9 Iterations. Final criterion was 0.0000091 <= 0.0000100
Daily(5) Data From 2003:01:03 To 2012:12:06
Usable Observations 2590
Function Value -1054.8672
Variable Coeff Std Error T-Stat Signif
************************************************************************************
1. A01 0.013619894 0.013106682 1.03916 0.29873196
2. A02 -0.014933917 0.004393704 -3.39894 0.00067649
3. A11 -0.935668475 0.028987754 -32.27806 0.00000000
4. A12 -1.064079366 0.034639104 -30.71902 0.00000000
5. B01 0.067855137 0.006098469 11.12659 0.00000000
6. B11 0.136280582 0.028697956 4.74879 0.00000205
7. B21 0.807379310 0.029557752 27.31532 0.00000000
8. B02 0.003801359 0.000683465 5.56189 0.00000003
9. B12 0.310732981 0.049463576 6.28206 0.00000000
10. B22 0.292483566 0.028278038 10.34313 0.00000000
MAXIMIZE - Estimation by BFGS
Convergence in 21 Iterations. Final criterion was 0.0000094 <= 0.0000100
Daily(5) Data From 2003:01:03 To 2012:12:06
Usable Observations 2590
Function Value -1050.5437
Variable Coeff Std Error T-Stat Signif
************************************************************************************
1. A01 0.010285521 0.012745732 0.80698 0.41967938
2. A02 -0.015746220 0.004411478 -3.56937 0.00035783
3. A11 -0.934642290 0.030346397 -30.79912 0.00000000
4. A12 -1.085577499 0.037463795 -28.97671 0.00000000
5. B01 0.050692332 0.009910202 5.11517 0.00000031
6. B11 0.157356240 0.031981527 4.92022 0.00000086
7. B21 0.802614140 0.049317631 16.27439 0.00000000
8. B02 0.003374801 0.001166368 2.89343 0.00381063
9. B12 0.229441167 0.070668669 3.24672 0.00116744
10. B22 0.246944292 0.038749720 6.37280 0.00000000
11. P(1,1) 0.960576407 0.013708449 70.07185 0.00000000
12. P(1,2) 0.075710440 0.020554312 3.68343 0.00023011
MAXIMIZE - Estimation by BFGS
NO CONVERGENCE IN 12 ITERATIONS
LAST CRITERION WAS 0.0000000
SUBITERATIONS LIMIT EXCEEDED.
ESTIMATION POSSIBLY HAS STALLED OR MACHINE ROUNDOFF IS MAKING FURTHER PROGRESS DIFFICULT
TRY HIGHER SUBITERATIONS LIMIT, TIGHTER CVCRIT, DIFFERENT SETTING FOR EXACTLINE OR ALPHA ON NLPAR
RESTARTING ESTIMATION FROM LAST ESTIMATES OR DIFFERENT INITIAL GUESSES MIGHT ALSO WORK
Daily(5) Data From 2003:01:03 To 2012:12:06
Usable Observations 2590
Function Value -1018.0690
Variable Coeff Std Error T-Stat Signif
************************************************************************************
1. A01 -0.013393998 0.000380707 -35.18194 0.00000000
2. A02 0.045332574 0.002076028 21.83620 0.00000000
3. A11 -1.097700039 0.005548809 -197.82625 0.00000000
4. A12 -0.303118795 0.027167144 -11.15755 0.00000000
5. B01 -0.001011178 0.000002767 -365.49626 0.00000000
6. B11 0.059900700 0.000807929 74.14101 0.00000000
7. B21 0.609069171 0.000384612 1583.59479 0.00000000
8. B02 0.019938741 0.000145776 136.77666 0.00000000
9. B12 0.045280994 0.000174983 258.77336 0.00000000
10. B22 1.870801841 0.029521412 63.37101 0.00000000
11. P(1,1) 0.820696725 0.000355251 2310.18726 0.00000000
12. P(1,2) 0.723588475 0.006872191 105.29226 0.00000000
And here is ex ante and smoothed probabilities:

- figure 5.png (28.08 KiB) Viewed 45475 times
Here is the code:
Code: Select all
All of this was out of Gray's paper, "Modeling the conditional
* distribution of interest rates as a regime-switching process", J. of
* Financial Economics 42, 1996, pp 27-62.
*
* Revision Schedule:
* 01/2005 Written by Tom Doan, Estima
* 09/2005 Comments added. Changed to use new %MSSMOOTH procedure
*
OPEN DATA data.xlsx
CALENDAR(D) 2003:1:2
all 2012:12:06
DATA(FORMAT=XLSX,ORG=COLUMNS) 2003:01:02 2012:12:06 rupee rate
set rate = rate*100.0
diff rate / drate
spgraph(vfields=2,window="Figure 3")
graph(header="One Month T-Bill Rates")
# rate
graph(header="One Month T-Bill Yields")
# drate
spgraph(done)
*
* This makes extensive use of the Markov switching functions and
* procedures from MSSetup.src
*
@MSSetup(states=2)
*
* The P and Q values in Gray's notation are handled in MSSetup as an M-1
* x M matrix (called P here), with P(i,j) giving the probabilities of
* moving from state j to state i. The Mth row is implicit, as it's just
* the 1-sum of rest of the column.
*
*******************************************************************************
*
* Table 1 information
*
stats drate
cmom(corr,print)
# drate rate{1}
*******************************************************************************
*
* Table 2 estimates
*
* Single regime is linear regression
*
linreg(robust) drate
# constant drate{1}
*
* We're going to use these later for initial conditions
*
compute olsvar =%seesq
compute olsbeta=%beta
*
* Constant variance regime switching model
* This uses Gray's notation for all the variables other than "P"
*
nonlin a01 a02 a11 a12 b01 b02 p
*
* Initial guess values for MS models are always a bit tricky because the
* model isn't globally identified. This is starting with OLS results for
* state 1 and 0 mean coefficients for state 2.
*
compute a01=olsbeta(1),a11=olsbeta(2),b01=sqrt(olsvar)
compute a02=a12=0.0,b02=b01
*
* The p matrix is initialized to make both states fairly persistent.
* (The 2,2 transition is 1-.1=.9).
*
compute p=||.8,.1||
*
* SimpleRegimeF returns the 2-vector of densities in the two regimes. It
* is specific to the data series used (dependent variable <<drate>>) and
* the precise parameterization, and so would need to be altered slightly
* for a different application. Note that this needs to return the actual
* density, not its log.
*
function SimpleRegimeF t
type vector SimpleRegimeF
type integer t
*
compute SimpleRegimeF=||%density((drate(t)-a01-a11*rate(t-1))/b01)/b01,$
%density((drate(t)-a02-a12*rate(t-1))/b02)/b02||
end
*
* This is the standard log likelihood FRML for a Markov switching model.
*
frml logl = f=SimpleRegimeF(t),fpt=%MSProb(t,f),log(fpt)
@MSFilterInit
maximize(start=(pstar=%MSInit()),method=bfgs,iters=100,pmethod=simplex,piters=5) logl 2 2012:12:06
*
* It's not clear what residuals are used for the diagonostics for the
* regime switching model. The standardized residuals weighted by the ex
* ante probabilities of the two states seem to give LB's which are
* fairly close to those in the paper.
*
set ustd = %dot(pt_t1,||(drate-a01-a11*drate{1})/b01,(drate-a02-a12*drate{1})/b02||)
graph
# ustd
set usqr = ustd^2
@regcorrs(report,number=15) usqr
*
* Compute the smoothed probabilities and the ex ante probabilities
*
@MSSmoothed %regstart() %regend() psmooth
set exante %regstart() %regend() = pt_t1(t)(1)
set smooth %regstart() %regend() = psmooth(t)(1)
*
* And the conditional standard deviation
*
set condstddev = sqrt(exante*b01^2+(1-exante)*b02^2)
*
spgraph(vfields=2,window="Figure 4")
graph(max=1.0,header="Regime Probabilities") 2
# exante
# smooth
graph(header="Conditional Standard Deviation")
# condstddev
spgraph(done)
*******************************************************************************
*
* Table 3 estimates
*
* Single regime GARCH model
*
garch(p=1,q=1,reg,resids=u,hseries=h) / drate
# constant drate{1}
compute onestate=%beta
*
set usqr = u^2/h
@regcorrs(number=15,report) usqr
*
* Regime-switching GARCH
*
nonlin a01 a02 a11 a12 b01 b11 b21 b02 b12 b22 p
compute a01=%beta(1),a11=%beta(2),b01=olsvar,b11=0.0,b21=0.0
compute a02=%beta(1),a12=%beta(2),b02=%beta(3),b12=%beta(4),b22=%beta(5)
compute p=||.95,.05||
*
set uu = olsvar
set h = olsvar
*
* RegimeGARCHF returns the 2 vector of densities in the two regimes.
* Again, many lines in this are specific to the problem at hand.
*
function RegimeGARCHF t
type vector RegimeGARCHF
type integer t
local real hh1 hh2 mu1 mu2 mu
*
* Compute state dependent variances
*
compute hh1=b01+b11*uu(t-1)+b21*h(t-1)
compute hh2=b02+b12*uu(t-1)+b22*h(t-1)
*
* Compute state dependent means
*
compute mu1=a01+a11*rate(t-1)
compute mu2=a02+a12*rate(t-1)
*
* Compute the return vector (densities in the two states)
*
compute RegimeGARCHF=||%density((drate(t)-mu1)/sqrt(hh1))/sqrt(hh1),$
%density((drate(t)-mu2)/sqrt(hh2))/sqrt(hh2)||
*
* Compute the values of uu (squared residual) and h (variance) to be
* used for the period following.
*
compute mu=mu1*pstar(1)+mu2*pstar(2)
compute uu(t)=(drate(t)-mu)^2
compute h(t)=pstar(1)*(mu1^2+hh1)+pstar(2)*(mu2^2+hh2)-mu^2
end
*
frml logl = f=RegimeGARCHF(t),fpt=%MSProb(t,f),log(fpt)
*
* This combination is able to locate Gray's results - the first MAXIMIZE
* works with the "p" matrix fixed at a fairly high level of persistence,
* and tries to get estimates which separate the two states. The second
* then adds the p matrix to the parmset.
*
nonlin a01 a02 a11 a12 b01 b11 b21 b02 b12 b22
maximize(start=(pstar=%MSInit()),method=bfgs,iters=100,pmethod=simplex,piters=50) logl 2 2012:12:06
nonlin a01 a02 a11 a12 b01 b11 b21 b02 b12 b22 p
maximize(start=(pstar=%MSInit()),method=bfgs,iters=100) logl 2 2012:12:06
*
* Compute the smoothed probabilities and the ex ante probabilities
*
@MSSmoothed %regstart() %regend() psmooth
set exante %regstart() %regend() = pt_t1(t)(1)
set smooth %regstart() %regend() = psmooth(t)(1)
*
* And the conditional standard deviation
*
set condstddev = sqrt(h)
*
spgraph(vfields=2,window="Figure 5")
graph(max=1.0,header="Regime Probabilities") 2
# exante
# smooth
graph(header="Conditional Standard Deviation")
# condstddev
spgraph(done)
*
*
* However, this set of initial guess values (which are actually the
* result of a typo in trying to reproduce the article's numbers) find a
* local max with quite a bit higher likelihood, and dramatically
* different behavior. How one might find this systematically is unclear.
*
compute a01=.1407,a02=-.0011,a11=-.0141,a12=.0006,b01=.0004,b11=.4609,b21=.1977,b02=.0099,b12=.1655,b22=.2685,p=||.9739,1-.9896||
maximize(start=(pstar=%MSInit()),method=bfgs,iters=100,pmethod=simplex,piters=50) logl 2 2012:12:06
*******************************************************************************