flopez2011 wrote:Dear Tom, when I run the SWARCH.rpf all is ok, but when I run with my own data I can not get values for p's...What can be wrong?...Regards
TomDoan wrote:flopez2011 wrote:Dear Tom, when I run the SWARCH.rpf all is ok, but when I run with my own data I can not get values for p's...What can be wrong?...Regards
As mentioned above, it estimates the probabilities in logistic index form. To transform those to probabilities add
disp %mslogisticp(theta)
TomDoan wrote:You would have to post your program and data.
OPEN DATA "C:\Users\Usuario\Documents\WinRATS Standard 8.1\TLCAN.xls"
DATA(FORMAT=XLS,ORG=COLUMNS) 1 1305 MEX
* Convert to percent daily returns
*
set x = 100.0*log(MEX/MEX{1})
@MSSetup(states=3)
compute q=2
*
* HV will be the relative variances in the states. This will be
* normalized to a relative variance of 1 in the first state, so it's
* dimensioned N-1.
*
dec vect hv(nstates-1)
*
* This will be the vector of ARCH parameters
*
dec vect a(q)
*
* We have three parts of the parameter set: the mean equation parameters
* (here, just an intercept), the ARCH model parameters, and the Markov
* switching parameters, for which we'll use the logistic indexes.
*
nonlin(parmset=meanparms) mu
nonlin(parmset=archparms) a0 a hv
nonlin(parmset=msparms) theta
*
* uu and u are used for the series of squared residuals and the series of
* residuals needed to compute the ARCH variances.
*
clear uu u
*
* ARCHStateF returns a vector of likelihoods for the various states at
* time given residual e. The likelihoods differ in the states based upon
* the values of hv, where the intercept in the ARCH equation is scaled
* up by hv. Again, the elements of hv are offset by 1 since they're
* normalized with the first state at 1.
*
function ARCHStateF time e
type vector ARCHStateF
type real e
type integer time
*
local integer i j
local real vi
*
dim ARCHStateF(nstates)
do i=1,nstates
compute vi=a0*%if(i>1,hv(i-1),1)
do j=1,q
compute vi=vi+a(j)*uu(time-j)
end do i
compute ARCHStateF(i)=%if(vi>0,%density(e/sqrt(vi))/sqrt(vi),0.0)
end do i
end
*
* As is typically the case with Markov switching models, there is no
* global identification of the states. By defining a fairly wide spread
* for hv, we'll hope that we'll stay in the zone of the likelihood where
* state 1 is low variance, state 2 is medium and state 3 is high.
*
compute hv=||10,100||
*
* These are our guess values for the P matrix. We have to invert that to
* get the guess values for the logistic indexes.
*
compute p=||.8,.2,.05|.2,.6,.4||
compute theta=%msplogistic(p)
*
stats x
compute mu=%mean,a0=%variance,a=%const(0.05)
set uu = %variance
*
* We need to keep series of the residual (u) and squared residual (uu).
* Because the mean function is the same across states, we can just
* compute the residual and send it to ARCHStateF, which computes the
* likelihoods for the different ARCH variances.
*
* Because we need 2 lags of uu, the estimation starts at 3.
*
frml logl = u(t)=(x-mu),uu(t)=u(t)^2,$
f=ARCHStateF(t,u(t)),fpt=%MSProb(t,f),log(fpt)
*
@MSFilterInit
*
* The 1-->3 probability is effectively zero, which causes problems with
* the estimation. This pegs the theta(1,3) element to prevent that.
*
nonlin(parmset=pegs) theta(1,3)=-50.00
maximize(start=%(p=%mslogisticp(theta),pstar=%msinit()),$
parmset=meanparms+archparms+msparms+pegs,$
method=bhhh,iters=400,pmethod=simplex,piters=5) logl 3 *
*
@MSSmoothed %regstart() %regend() psmooth
set p1 = psmooth(t)(1)
set p2 = psmooth(t)(2)
set p3 = psmooth(t)(3)
disp %mslogisticp(theta)
spgraph(vfields=2,samesize)
graph(style=stacked,maximum=1.0,picture="##.##",$
header="Smoothed Probabilities of Variance States",$
key=none,klabels=||"Low Variance","Medium Variance","High Variance"||) 3
# p1 400 500
# p2 400 500
# p3 400 500
graph(picture="##.##",header="Data")
# x 400 500
spgraph(done)zy761 wrote:Dear Tom:
I'm now running the SWARCH(3,2) model and I have two questions:
1. I get the trasition probability matrix using disp %mslogisticp(theta). It is a 2*3 matrix. But what does each element in the matrix mean? I thought it should be a 3*3 matrix.
zy761 wrote: 2. Can RATS run a bivariate SWARCH model?
TomDoan wrote:zy761 wrote:Dear Tom:
I'm now running the SWARCH(3,2) model and I have two questions:
1. I get the trasition probability matrix using disp %mslogisticp(theta). It is a 2*3 matrix. But what does each element in the matrix mean? I thought it should be a 3*3 matrix.
The bottom rows just make the columns add up to 1. P(i,j) is the probability of moving from j to i.
TomDoan wrote:zy761 wrote: 2. Can RATS run a bivariate SWARCH model?
Do you have a reference? There's no particular reason it couldn't, but there is no obvious generalization from univariate to bivariate.
TomDoan wrote:The bottom rows just make the columns add up to 1. P(i,j) is the probability of moving from j to i.
zy761 wrote:But what the about the probability of moving from i to i, say, the persistence of state i?
flopez2011 wrote:After reading the Edwards&Susmel paper I think very desirable to get a routine to estimate bivariate swarch(K,q) models, but not assuming a constant correlation matrix but time variyng so as empirical evidence suggests
Return to Structural Breaks and Switching Models
Users browsing this forum: No registered users and 1 guest