by superper2008 » Mon Apr 16, 2012 1:43 pm
Hello Tom:
Now I am writing code for time-varying multivariate linear regression without no lag coefficients. The code is post as follows, but the mistake occurred in the bottom line. Just what I mentioned in the previous reply, I still didn't understand how to apply @msversteup (nonlin(parmset=common) mu phi sigma)
)into @msregression (nonlin(parmset=common) betas sigsqv)
)
I am trying my best to combine them, but the results can't be showns.I am not sure if I need the code such as @msvartestvector(domu,dovar) baseparms, do k=1,MSVARFilterSize
compute thisEntry(MSVARLagState(k,1),MSVARLagState(k,2))+=MSVARPTSM(time)(k), because in my tested model, there are no lag terms and state-dependent means. Moreover, without the codes above, is it possible to run one result?
Could you please give me more suggestions about that to modify the Filado's code?
Appreciate you very much for your help. Look forward to hearing from you .
cal(d) 2006:03:24
open data "D:\Documents and Settings\f_huan\My Documents\mutual fund thesisone_sample.xls"
data(format=xls,org=cols) 2006:03:24 2012:03:05 apexcess aprm aprmsq logvix
sample(smpl=%valid(apexcess)) apexcess / apexcess_nomissing
sample(smpl=%valid(aprm)) aprm / aprm_nomissing
sample(smpl=%valid(aprmsq)) aprmsq / aprmsq_nomissing
sample(smpl=%valid(logvix)) logvix / logvix_nomissing
calendar(irregular)
compute gstart=1,gend=%nobs
@msregression(states=2,switch=ch) apexcess_nomissing
# constant aprm_nomissing aprmsq_nomissing
source msvarsetup.src
nonlin(parmset=common) betas sigsqv
* Define the logistic index for the transitions
*
equation p1eq *
# constant logvix{1}
equation p2eq *
# constant logvix{1}
*
dec equation p1eq p2eq
dec vector v1 v2
nonlin(parmset=tv) v1 v2
function %MSVARPmat time
type rect %MSVARPmat
type int time
*
local integer i j
local rect pexpand
local real z
*
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))
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
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) baseparmscompute 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
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
frml logltvtp = %MSVARPMat(t),log(%MSVarProb(t))
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
## MAT15. Subscripts Too Large or Non-Positive
[color=#FF0000]The Error Occurred At Location 213, Line 16 of MSVARTESTVECTOR
Called From Location 59, Line 10 of MSVARTVPEMESTIMA[/color]
A millions thanks for your kindly help.
Sincerely,
Feiyu