TVTP Markov Regime switching model

Discussion of models with structural breaks or endogenous switching.
superper2008
Posts: 32
Joined: Tue Mar 27, 2012 12:48 pm

TVTP Markov Regime switching model

Unread post by superper2008 »

Dear Tom:

Now I met one big touble to apply Markov regime switching TM model (to test market timing) from a new paper "Business cycles and mutual fund timing performance: an application of regime switching and Garch modelling". In the paper, the authors uses transition probability model to find time varying probability depending on one economic indicator (VIX) by equation P(t)= cumulative normal function (c1+d1*log (vix(t-1)); Q(t)=cumulative normal function (c2+d2*log(VIX(t-1))). And then they estimate C1,C2,D1 and D2. (Ithink that I can estimate them by means of RATS, right? ).

Moreover, when getting c1,c2, d1 and d2, the authors regards d1 (negative) as state 1(S1) and regard d2 (positive) as state 2(S2). Finally the authors appply these four estimators derived from transition probability modelling into markov regime TM switching (in the paper, they extended markov switching by adding one more varialbes). The equation is shown in the following: return(j,t)= alpha(j, St)+beta(j, St)*X+gamma(t,St)*(X^2)+error term; error term follows N(0, Variance(St)). However, I have no idea how to apply c1,c2,d1, d2 into the extended markov regime switching model [return(j,t)= alpha(j, St)+beta(j, St)*X+gamma(t,St)*(X^2)+error term]when using RATS to estimate the coefficients of time varying transtion probability modelling.

Could you give me some suggestions how to code them by means of RATS.

Appreciate you very much for your patience, help and consideration. Look forward to your reply at your earliest convenience.

Best regards,
Feiyu
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: TVTP Markov Regime switching model

Unread post by TomDoan »

That will be similar to the Filardo JBES 1994 replication except they are using Normal rather than logistics to compute the time-varying probabilities. To convert the rather slow maximum likelihood estimates would be a very simple adjustment to the %MSVARPMAT function—the following two lines are specific to the logistic:

Code: Select all

compute p(1,1)=%(z=exp(%dot(%eqnxvector(p1eq,time),v1)),z/(1+z))
compute p(1,2)=%(z=exp(%dot(%eqnxvector(p2eq,time),v2)),1/(1+z))
superper2008
Posts: 32
Joined: Tue Mar 27, 2012 12:48 pm

Re: TVTP Markov Regime switching model

Unread post by superper2008 »

Dear Tom:

Appreciate you very much for your help. However, I have one small question about that. When I estimate the coefficients (c1,c2,d1,d2) by means of filardo replications, I have to use these four coefficents which determine state 1(d1<0) or state 2 (d2>0) and put them into the extended markov regime switching model [return(j,t)= alpha(j, State)+beta(j, State)*X+gamma(t,State)*(X^2)+error term, in the model, there are totally six coefficients estimated in two different states respectively (alpha1, alpha2, beta1, beta2, gamma1and gamma2). Could you please give me more suggestions about that?

Appreciate your very much for your help.

Sincerely,
Feiyu
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: TVTP Markov Regime switching model

Unread post by TomDoan »

Filardo is actually more complicated than that, because he is using a Hamilton style mean switching model which requires augmenting regimes to handle all the combinations for current and four lags. I'm not sure what you mean by "extended Markov regime switching model". That looks like a relatively straightforward Markov switching linear regression other than time-varying transitions.
superper2008
Posts: 32
Joined: Tue Mar 27, 2012 12:48 pm

Re: TVTP Markov Regime switching model

Unread post by superper2008 »

Hello Tom:

Appreciate you for your help. You are right. The model I are using is one linear regressionl with two independent variables. However, I have to use c1,c2, d1,d2 derived from time varying transition probability modelling (normal function) to put them into the linear regression. Could you please give me some suggestions about them? Which example can I refer to in RATS forum?

Thanks again for your reply and kindly help.

Regards,
Feiyu
superper2008
Posts: 32
Joined: Tue Mar 27, 2012 12:48 pm

Re: TVTP Markov Regime switching model

Unread post by superper2008 »

Hello Tom:

I may make one mistake. The markov regime switching model should be one non-linear regression with two independent variables including X and Y. Could you please give me more suggestions how to code them by using coeffients estimated from time varying transition probability>

Thank you very much for your understanding.

Sincerely,
Feiyu
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: TVTP Markov Regime switching model

Unread post by TomDoan »

superper2008 wrote:Hello Tom:

I may make one mistake. The markov regime switching model should be one non-linear regression with two independent variables including X and Y. Could you please give me more suggestions how to code them by using coeffients estimated from time varying transition probability>

Thank you very much for your understanding.

Sincerely,
Feiyu
Actually, it's linear in the parameters---X^2 is just another explanatory variable. Have you tried estimating this with fixed transitions first?
superper2008
Posts: 32
Joined: Tue Mar 27, 2012 12:48 pm

Re: TVTP Markov Regime switching model

Unread post by superper2008 »

Hello Tom:

Appreciate you very much for your help. Now I am using Fillaro replication to estimate time varying transition probability modelling (normal function), but I found that it is very complicated to apply the code into my model because in the model, it only uses cumulative normal function to establish the relationship between transition probability and one economic indicator. Could you please give more suggestions how to simplify Fillaro repliaction code because I don't need the mean switching model?

After I estimated these four coefficents (c1,c2,d1,d2) of the transition probability modelling, I could determinie state according to d1 and d2. It means that d1 leads to state 1 and d2 leads to state 2. And then I have to use d1 and d2 and put them into the linear regression. However, I have no a clear picture how to relate time varying coefficients to the linear regression. Can I use Fillaro replication code to estimate the linear regression or have to write another code to estimate alpha, beta and gamma in two states respectively?

Could you please give me more suggestions? Apprreciate you very much for your kindly assistance on the model.

Sincerely,
Feiyu
superper2008
Posts: 32
Joined: Tue Mar 27, 2012 12:48 pm

Re: TVTP Markov Regime switching model

Unread post by superper2008 »

Hello Tom:

I don't need to estimate the linear regression with fixed transitions first. However, I need to estimate the linear regresssion with time varying transition probability. Could you please give me more suggestion how to code them?

Appreciate you very much for your immediate reply and kindly help.

Best regards
Feiyu
superper2008
Posts: 32
Joined: Tue Mar 27, 2012 12:48 pm

Re: TVTP Markov Regime switching model

Unread post by superper2008 »

Hello Tom:

I have been trying my best to apply Filardo code to my model. However, it is hard for me to simplify them into normal function of time varying transition probability of my model to estimate the coefficients. I also need to estimate the linear regression with the time varying transition probability.

Appreciate you very much for your help.

Sincerely,
Feiyu
Attachments
mutual fund regime switching.pdf
the source of the model
(661.11 KiB) Downloaded 1151 times
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: TVTP Markov Regime switching model

Unread post by TomDoan »

superper2008 wrote:Hello Tom:

I don't need to estimate the linear regression with fixed transitions first.
Actually, you do, because that's how you do (good) empirical work. You don't start with the most complicated model that you might think of estimating. An example where the basic model is more similar to what you're doing than Filardo's (which again is a mean-switching Hamilton model, rather than a simple switching linear regression) is posted here:

http://www.estima.com/forum/viewtopic.php?f=8&t=1400
superper2008
Posts: 32
Joined: Tue Mar 27, 2012 12:48 pm

Re: TVTP Markov Regime switching model

Unread post by superper2008 »

Hello Tom:

Appreciate you very much for your suggestion about markov simple linear regression. Could you please give me one example about markov multivariate linear regression by using @mssysregression? Because in my model, I will estimate several coeffiicents of intercepts, betas and gammas with state-dependent variance.

Besides, when I am using Filardo's code to estimate the time varying probability transition modelling, it is a little difficult to write the code about P(1,1) and P (1,2) because Filardo uses logistic function,[p(1,1)=%(z=exp(%dot(%eqnxvector(p1eq,time),v1)),z/(1+z)),p(1,2)=%(z=exp(%dot(%eqnxvector(p2eq,time),v2)),1/(1+z))], but I will use cumulative normal function P=f(c1+c2(log(X,t-1))), q=f(d1+d2(log(x,t-1))), could you please help me to code the normal function?

Appreciate you very much for your kindly help.

Sincerely,
Feiyu
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: TVTP Markov Regime switching model

Unread post by TomDoan »

superper2008 wrote:Hello Tom:

Appreciate you very much for your suggestion about markov simple linear regression. Could you please give me one example about markov multivariate linear regression by using @mssysregression? Because in my model, I will estimate several coeffiicents of intercepts, betas and gammas with state-dependent variance.
See Ehrmann-Ellison-Valla(2003).
superper2008 wrote:Besides, when I am using Filardo's code to estimate the time varying probability transition modelling, it is a little difficult to write the code about P(1,1) and P (1,2) because Filardo uses logistic function,[p(1,1)=%(z=exp(%dot(%eqnxvector(p1eq,time),v1)),z/(1+z)),p(1,2)=%(z=exp(%dot(%eqnxvector(p2eq,time),v2)),1/(1+z))], but I will use cumulative normal function P=f(c1+c2(log(X,t-1))), q=f(d1+d2(log(x,t-1))), could you please help me to code the normal function?
The use of the %EQNXVECTOR allows for easier change from one set of explanatory variables to another. The whole %dot(.....) evaluates the "index" which in your case is c1+c2*log(X(time-1)) for evaluating p(1,1) and d1+d2*log(x(time-1)) for evaluating p(2,2). You can either stick with the direct coding, or you can use

Code: Select all

equation p1eq *
# constant logx{1}
equation p2eq *
# constant logx{1}
(logx being a generated series) to define the two sets of linear functions for the indexes. With your original coding, you would want

p(1,1)=z=c1+c2*log(X(time-1)),%cdf(z)
p(1,2)=z=d1+d2*log(X(time-1)),%cdf(-z)

(The minus sign in the second is because you have a model for p(2,2), not p(1,2)).
superper2008
Posts: 32
Joined: Tue Mar 27, 2012 12:48 pm

Re: TVTP Markov Regime switching model

Unread post by superper2008 »

Hello Tom:

Thanks for your help. I am waiting for my university's respond about recent version 8.1 of WinRats. At the same time, I have been working on the code of my model. I also have one question if filardo's time varying probability code can be applied into my model by using @msvarsetup which considers "mu" and "phi". Because in the markov multivariate linear regression with time varying probability, there is no lag coeefficients needed, all the coefficents (alpha, beta and gamma) are the swithcing current terms. I think that @mssysregression may be better for my model, is that right? If i am right, it means than I have to write the code with time varying probability in the multivariate regression instead of hamilton style mean- swithcing model with lag coefficients. Could you please give me more suggestions about that?

Besides, I have order the materials of breaks and swithcing model courses and wish that the material can help me a lot.

Appreciate you very much for your help and understanding.

Sincerely,
Feiyu
superper2008
Posts: 32
Joined: Tue Mar 27, 2012 12:48 pm

Re: TVTP Markov Regime switching model

Unread post by superper2008 »

Hello Tom:

I have been dealing with my model by means of code from yours. However I am meeting a big trouble to write the code about time varying transition probability. In Filardo' code. he used @msvarsetup to estimate time varying Hamilton style mean-switching model with four lags. However, in my model, there is only multivariate linear regression without any lags.

What should I do to apply the code into my multivariate regression (@mssysregression(state=2, switch=ch))?

Can I modify the time varying transition probability model as follows according to Filardo's code?

However, I have no clear picture to code Controlling routine for EM estimation of time-varying probabilities in red highlight part which contain mean and lag term.

Could you please give me more suggestions at your earliest convenience? Appreciate you very much for your help.



Time varying probability

dec equation p1eq p2eq
dec vector v1 v2
nonlin(parmset=tv) v1 v2
*********************************************************************
frml logltvtp = %MSVARPMat(t),log(%MSVarProb(t))
*********************************************************************
Define the logistic index for the transitions
*
equation p1eq *
# constant log{1}
equation p2eq *
# constant log{1}
*
* Standard guess values aiming to make state 1 the recession state.
*
compute v1=log(.7/.3)~~0.0
compute v2=log(.95/.05)~~0.0

@MSVARTVPEMEstimate(cvcrit=.0001) gstart gend
*
maximize(parmset=tv+common,start=(pstar=TVPInit()),$
method=bhhh,iters=20) logltvtp gstart gend

* This overrides the standard fixed definition
*
function %MSVARPmat time
type rect %MSVARPmat
type int time
*
local integer i j
local rect pexpand
local real z
*
compute p(1,1)=%(z=log(%dot(%eqnxvector(p1eq,time-1),v1)),%cdf(z)
compute p(1,2)=%(z=log(%dot(%eqnxvector(p2eq,time-1),v2)),%cdf(-z)

compute %MSVARInitTransition()
*
if nexpand==nstates {
dim pexpand(nstates,nstates-1)
ewise pexpand(i,j)=%if(i==nstates,-1.0,i==j)
compute %MSVARPmat=pexpand*p
ewise %MSVARPmat(i,j)=%if(i==nstates,1.0+%MSVARPmat(i,j),%MSVARPmat(i,j))
}
else {
dim %MSVARPmat(nexpand,nexpand)
ewise %MSVARPmat(i,j)=MSVARTransProbs(MSVARTransLookup(i,j))
}
end
*********************************************************************
*
* Initialize the probabilities using only the intercepts
*
function TVPInit
type vector TVPInit
*
local rect a
local integer i j
*
compute p=||%logistic(v1(1),1.0),1-%logistic(v2(1),1.0)||
compute TVPInit=%MSVARInit()
end
*********************************************************************
*
*Controlling routine for EM estimation of time-varying probabilities
*
procedure MSVARTVPEMEstimate start end
type integer start end
option integer iters 100
option real cvcrit 1.e-6
*
local integer emits time k
local series l11 l22 w11 w22
local vector baseparms testparms
local rect thisEntry
*
@msvartestvector(domu,dovar) baseparms
compute baseparms=baseparms~~v1~~v2
do emits=1,iters
compute %eqnsetcoeffs(p1eq,v1)
compute %eqnsetcoeffs(p2eq,v2)
@msvarestep start end
compute %emlogl=%logl
@msvarmstep(nodop) start end
*
* Compute the weights and dependent variable for the one-step
* correction on the logistics.
*
set l11 start end = 0.0
set l22 start end = 0.0
set w11 start end = 0.0
set w22 start end = 0.0
do time=start,end
compute %MSVARPMat(time)
compute thisEntry=%zeros(nstates,nstates)
do k=1,MSVARFilterSize
compute thisEntry(MSVARLagState(k,1),MSVARLagState(k,2))+=MSVARPTSM(time)(k)
end do k
compute w11(time)=p(1,1)*(1-p(1,1))*(thisEntry(1,1)+thisEntry(2,1))
compute w22(time)=p(1,2)*(1-p(1,2))*(thisEntry(2,2)+thisEntry(1,2))
compute l11(time)=(thisEntry(1,1)- p(1,1)*(thisEntry(1,1)+thisEntry(2,1)))/w11(time)
compute l22(time)=(thisEntry(2,2)-(1-p(1,2))*(thisEntry(2,2)+thisEntry(1,2)))/w22(time)
end do time
*
* Update the coefficients
*
linreg(noprint,weight=w11,equation=p1eq) l11 start end
compute v1=v1+%beta
linreg(noprint,weight=w22,equation=p2eq) l22 start end
compute v2=v2+%beta
*
* Check for convergence
*
@msvartestvector(domu,dovar) testparms
compute testparms=testparms~~v1~~v2
compute %cvcrit=%testdiff(baseparms,testparms)
if %cvcrit<cvcrit
break
compute baseparms=testparms
disp "Iteration" emits "Log Likelihood" %emlogl %cvcrit
end do emits
end MSVARTVPEMEstimate

*
*
[/color]
Post Reply