Markov switching model

Discussion of models with structural breaks or endogenous switching.
rbelhach95
Posts: 115
Joined: Sat Feb 09, 2013 9:30 am

Markov switching model

Unread post by rbelhach95 »

Dear Tom,
Please see the code below; I get unassigned error at the end of the Maximize instruction, something is missing but I can't figure out what is, could be my choice of starting values probabilities, please advise
Thanks

Code: Select all

source "C:\ Desktop\ markov.src"
OPEN DATA "C: \ Desktop\ returns_100.txt"
ALL  23005
DATA(FORMAT=free,ORG=COL) 1 23005 x
compute n=2
dec rect p(n-1,n)
dec vect f(n) pstar(n)
nonlin(parmset=markovparms) p
nonlin(parmset=mixparms) mux muT sigmax1 sigmaT1 sigmaTx1 sigmax2 sigmaT2  sigmaTx2
frml markov  =  $
             k1 = sqrt(sigmaT1^2-sigmax1^(-2)*sigmaTx1^2), $
             k2 = sqrt(sigmaT2^2-sigmax2^(-2)*sigmaTx2^2), $
             q1 = sqrt(sigmaT1^2+sigmax1^2-2*sigmaTx1), $
             q2 =  sqrt(sigmaT2^2+sigmax2^2-2*sigmaTx2), $
             g1  = (1.0/sigmax1)*%density((x{0}-mux)/sigmax1), $
             g11 = -(1-sigmax1^(-2)*sigmaTx1)*(x{0}-mux)/k1, $
             g12 = -(muT-mux)/k1, $
             m1 = 1.0/%cdf(-(muT-mux)/q1), $
             g2  = m1*g1*%cdf(g11+g12),$
             h2  = (1.0/sigmax2)*%density((x{0}-mux)/sigmax2), $
             h21 = (1-sigmax2^(-2)*sigmaTx2)*(x{0}-mux)/k2, $
             h22 = (muT-mux)/k2, $
             m2 = 1.0/%cdf((muT-mux)/q2), $
             h2  = m2*h2*%cdf(h21+h22), $
             (f = || g2, h2 ||) ,$
             pstar=%msupdate(f,%mcstate(p,pstar),fpt), log(fpt)
            compute p = ||.70,.80||, mux=2.792523,  muT =0.0, sigmax1 =107.042328, sigmaT1 =100.0 , sigmaTx1 =0.0, sigmax2 =100.0, sigmaT2 =100.0, sigmaTx2 =0.0
             maximize(parmset=markovparms+mixparms, startup = %(pstar=%mcergodic(p)), pmethod=simplex, piters=5, iters = 5000, method=bfgs, cvcrit=0.000001) markov 


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

Re: Markov switching model

Unread post by TomDoan »

First of all, you need to figure out why you're not getting actual error messages. RATSERRS.MSG should be in the same directory as the executable. If it's not, you need to re-install the software.

I generated some random data for X and it executed fine, so you might want to check your data.
rbelhach95
Posts: 115
Joined: Sat Feb 09, 2013 9:30 am

Re: Markov switching model

Unread post by rbelhach95 »

Many thanks Tom. I have changed my data file to xls format and it worked fine.
Post Reply