three state variance regime switching model
-
superper2008
- Posts: 32
- Joined: Tue Mar 27, 2012 12:48 pm
three state variance regime switching model
Hello Tom:
when I run the three state variance regime switching model according to your code from textbook about structure break and switching models, there are some errors shown below. First of all, I found that sample mean is zero, I don't know what happened.
Statistics on Series PRICE
Daily(5) Data From 1995:01:03 To 2011:12:30
Observations 4269 Skipped/Missing 165
Sample Mean 0.000000 Variance 840.566132
Standard Error 28.992519 SE of Sample Mean 0.443734
t-Statistic (Mean=0) 0.000000 Signif Level (Mean=0) 1.000000
Skewness 0.885384 Signif Level (Sk=0) 0.000000
Kurtosis (excess) -0.132453 Signif Level (Ku=0) 0.077551
Jarque-Bera 560.869114 Signif Level (JB=0) 0.000000
Secondly, when I maximize the regime switching model, The Error Occurred At Location 170, Line 13 of %MSINIT
Called From Location 127, Line 13 of MSFILTERINIT
## MAT14. Non-invertible Matrix. Using Generalized Inverse for SYMMETRIC.
## OP3. This Instruction Does Not Have An Option MAR
could you please help me figure that out?
Appreciate you very much for your help.
the whole code is also shown below.
cal(d) 1995:01:03
open data "crude_oil.xls"
data(format=xls,org=cols) 1995:01:03 2011:12:30 price
* Extract the mean from the returns.
*
diff(center) price
*
@MSSetup(states=3)
*
* Provide guess values for theta
*
input theta
4.0 0.0 -4.0
2.0 2.0 -2.0
*
dec vect sigmas(nstates)
stats price
compute sigmas(1)=0.2*%variance
compute sigmas(2)= %variance
compute sigmas(3)=5.0*%variance
Statistics on Series PRICE
Daily(5) Data From 1995:01:03 To 2011:12:30
Observations 4269 Skipped/Missing 165
Sample Mean 0.000000 Variance 840.566132
Standard Error 28.992519 SE of Sample Mean 0.443734
t-Statistic (Mean=0) 0.000000 Signif Level (Mean=0) 1.000000
Skewness 0.885384 Signif Level (Sk=0) 0.000000
Kurtosis (excess) -0.132453 Signif Level (Ku=0) 0.077551
Jarque-Bera 560.869114 Signif Level (JB=0) 0.000000
*
*********************************************************************
*
* RegimeF returns a vector of likelihoods for the various regimes at
* <<time>>. The likelihoods differ in the regimes based upon the
* values of sigmas.
*
function RegimeF time
type vector RegimeF
type integer time
*
local integer i
*
dim RegimeF(nstates)
do i=1,nstates
compute RegimeF(i)=exp(%logdensity(sigmas(i), price(time)))
end do i
end
*********************************************************************
nonlin(parmset=modelparms) sigmas
nonlin(parmset=msparms) theta
*
frml markov = f=RegimeF(t),fpt=%MSProb(t,f),log(fpt)
*
@MSFilterInit
maximize(start=%(p=%mslogisticp(theta),pstar=%MSInit()),$
parmset=msparms+modelparms,$
Markov Switching: Introduction 97
method=bfgs,iters=400,pmethod=simplex,piters=5) markov * 2011:12:30
The Error Occurred At Location 170, Line 13 of %MSINIT
Called From Location 127, Line 13 of MSFILTERINIT
## MAT14. Non-invertible Matrix. Using Generalized Inverse for SYMMETRIC.
## OP3. This Instruction Does Not Have An Option MAR
>>>>Markov <<<<
*
@MSSmoothed %regstart() %regend() psmooth
set p1 = psmooth(t)(1)
set p2 = psmooth(t)(2)
set p3 = psmooth(t)(3)
graph(style=stacked,maximum=1.0,picture="##.##",$
header="Smoothed Probabilities of Variance Regimes",key=below,$
klabels=||"Low Variance","Medium Variance","High Variance"||) 3
# p1
# p2
# p3
## MAT15. Subscripts Too Large or Non-Positive
The Error Occurred At Location 66, Line 9 of MSSMOOTHED
*
set variance = p1*sigmas(1)+p2*sigmas(2)+p3*sigmas(3)
graph(footer="Figure 4.10 Estimated variance of historical stock returns")
# variance
## SX11. Identifier P1 is Not Recognizable. Incorrect Option Field or Parameter Order?
>>>>set variance = p1*s<<<<
set stdu = pricesqrt(variance)
graph(footer="Figure 4.11a Plot of standardized stock returns")
# stdu
when I run the three state variance regime switching model according to your code from textbook about structure break and switching models, there are some errors shown below. First of all, I found that sample mean is zero, I don't know what happened.
Statistics on Series PRICE
Daily(5) Data From 1995:01:03 To 2011:12:30
Observations 4269 Skipped/Missing 165
Sample Mean 0.000000 Variance 840.566132
Standard Error 28.992519 SE of Sample Mean 0.443734
t-Statistic (Mean=0) 0.000000 Signif Level (Mean=0) 1.000000
Skewness 0.885384 Signif Level (Sk=0) 0.000000
Kurtosis (excess) -0.132453 Signif Level (Ku=0) 0.077551
Jarque-Bera 560.869114 Signif Level (JB=0) 0.000000
Secondly, when I maximize the regime switching model, The Error Occurred At Location 170, Line 13 of %MSINIT
Called From Location 127, Line 13 of MSFILTERINIT
## MAT14. Non-invertible Matrix. Using Generalized Inverse for SYMMETRIC.
## OP3. This Instruction Does Not Have An Option MAR
could you please help me figure that out?
Appreciate you very much for your help.
the whole code is also shown below.
cal(d) 1995:01:03
open data "crude_oil.xls"
data(format=xls,org=cols) 1995:01:03 2011:12:30 price
* Extract the mean from the returns.
*
diff(center) price
*
@MSSetup(states=3)
*
* Provide guess values for theta
*
input theta
4.0 0.0 -4.0
2.0 2.0 -2.0
*
dec vect sigmas(nstates)
stats price
compute sigmas(1)=0.2*%variance
compute sigmas(2)= %variance
compute sigmas(3)=5.0*%variance
Statistics on Series PRICE
Daily(5) Data From 1995:01:03 To 2011:12:30
Observations 4269 Skipped/Missing 165
Sample Mean 0.000000 Variance 840.566132
Standard Error 28.992519 SE of Sample Mean 0.443734
t-Statistic (Mean=0) 0.000000 Signif Level (Mean=0) 1.000000
Skewness 0.885384 Signif Level (Sk=0) 0.000000
Kurtosis (excess) -0.132453 Signif Level (Ku=0) 0.077551
Jarque-Bera 560.869114 Signif Level (JB=0) 0.000000
*
*********************************************************************
*
* RegimeF returns a vector of likelihoods for the various regimes at
* <<time>>. The likelihoods differ in the regimes based upon the
* values of sigmas.
*
function RegimeF time
type vector RegimeF
type integer time
*
local integer i
*
dim RegimeF(nstates)
do i=1,nstates
compute RegimeF(i)=exp(%logdensity(sigmas(i), price(time)))
end do i
end
*********************************************************************
nonlin(parmset=modelparms) sigmas
nonlin(parmset=msparms) theta
*
frml markov = f=RegimeF(t),fpt=%MSProb(t,f),log(fpt)
*
@MSFilterInit
maximize(start=%(p=%mslogisticp(theta),pstar=%MSInit()),$
parmset=msparms+modelparms,$
Markov Switching: Introduction 97
method=bfgs,iters=400,pmethod=simplex,piters=5) markov * 2011:12:30
The Error Occurred At Location 170, Line 13 of %MSINIT
Called From Location 127, Line 13 of MSFILTERINIT
## MAT14. Non-invertible Matrix. Using Generalized Inverse for SYMMETRIC.
## OP3. This Instruction Does Not Have An Option MAR
>>>>Markov <<<<
*
@MSSmoothed %regstart() %regend() psmooth
set p1 = psmooth(t)(1)
set p2 = psmooth(t)(2)
set p3 = psmooth(t)(3)
graph(style=stacked,maximum=1.0,picture="##.##",$
header="Smoothed Probabilities of Variance Regimes",key=below,$
klabels=||"Low Variance","Medium Variance","High Variance"||) 3
# p1
# p2
# p3
## MAT15. Subscripts Too Large or Non-Positive
The Error Occurred At Location 66, Line 9 of MSSMOOTHED
*
set variance = p1*sigmas(1)+p2*sigmas(2)+p3*sigmas(3)
graph(footer="Figure 4.10 Estimated variance of historical stock returns")
# variance
## SX11. Identifier P1 is Not Recognizable. Incorrect Option Field or Parameter Order?
>>>>set variance = p1*s<<<<
set stdu = pricesqrt(variance)
graph(footer="Figure 4.11a Plot of standardized stock returns")
# stdu
Re: three state variance regime switching model
The zero mean is obvious - you did a DIFF(CENTER), so you already extracted the mean.
You'll have to post the full program and data set for us to figure out what's up with the three state model.
You'll have to post the full program and data set for us to figure out what's up with the three state model.
-
superper2008
- Posts: 32
- Joined: Tue Mar 27, 2012 12:48 pm
Re: three state variance regime switching model
Hi Tom,
Thanks for your reply.
Basically, I want to estimate a two state variance regime switching model, one state with high volatility in crude oil prices and the other one with low volatility in crude oil prices.
The whole program is posted below but some errors occurred. I refered to a RAT textbook to write all the codes but i dont know how to modify the three states model into a two states model. For example, what value should i use to set up " input theta"? I attached my dataset in the attachment.
Thanks very much
Regards
cal(d) 1995:01:03
open data "crude_oil.xls"
data(format=xls,org=cols) 1995:01:03 2011:12:30 price
* Extract the mean from the returns.
*
diff(center) price
*
@MSSetup(states=3)
*
* Provide guess values for theta
*
input theta
4.0 0.0 -4.0
2.0 2.0 -2.0
*
dec vect sigmas(nstates)
stats price
compute sigmas(1)=0.2*%variance
compute sigmas(2)= %variance
compute sigmas(3)=5.0*%variance
Statistics on Series PRICE
Daily(5) Data From 1995:01:03 To 2011:12:30
Observations 4269 Skipped/Missing 165
Sample Mean 0.000000 Variance 840.566132
Standard Error 28.992519 SE of Sample Mean 0.443734
t-Statistic (Mean=0) 0.000000 Signif Level (Mean=0) 1.000000
Skewness 0.885384 Signif Level (Sk=0) 0.000000
Kurtosis (excess) -0.132453 Signif Level (Ku=0) 0.077551
Jarque-Bera 560.869114 Signif Level (JB=0) 0.000000
*
*********************************************************************
*
* RegimeF returns a vector of likelihoods for the various regimes at
* <<time>>. The likelihoods differ in the regimes based upon the
* values of sigmas.
*
function RegimeF time
type vector RegimeF
type integer time
*
local integer i
*
dim RegimeF(nstates)
do i=1,nstates
compute RegimeF(i)=exp(%logdensity(sigmas(i), price(time)))
end do i
end
*********************************************************************
nonlin(parmset=modelparms) sigmas
nonlin(parmset=msparms) theta
*
frml markov = f=RegimeF(t),fpt=%MSProb(t,f),log(fpt)
*
@MSFilterInit
maximize(start=%(p=%mslogisticp(theta),pstar=%MSInit()),$
parmset=msparms+modelparms,$
Markov Switching: Introduction 97
method=bfgs,iters=400,pmethod=simplex,piters=5) markov * 2011:12:30
The Error Occurred At Location 170, Line 13 of %MSINIT
Called From Location 127, Line 13 of MSFILTERINIT
## MAT14. Non-invertible Matrix. Using Generalized Inverse for SYMMETRIC.
## OP3. This Instruction Does Not Have An Option MAR
>>>>Markov <<<<
*
@MSSmoothed %regstart() %regend() psmooth
set p1 = psmooth(t)(1)
set p2 = psmooth(t)(2)
set p3 = psmooth(t)(3)
graph(style=stacked,maximum=1.0,picture="##.##",$
header="Smoothed Probabilities of Variance Regimes",key=below,$
klabels=||"Low Variance","Medium Variance","High Variance"||) 3
# p1
# p2
# p3
## MAT15. Subscripts Too Large or Non-Positive
The Error Occurred At Location 66, Line 9 of MSSMOOTHED
*
set variance = p1*sigmas(1)+p2*sigmas(2)+p3*sigmas(3)
graph(footer="Figure 4.10 Estimated variance of historical stock returns")
# variance
## SX11. Identifier P1 is Not Recognizable. Incorrect Option Field or Parameter Order?
>>>>set variance = p1*s<<<<
set stdu = pricesqrt(variance)
graph(footer="Figure 4.11a Plot of standardized stock returns")
# stdu
Thanks for your reply.
Basically, I want to estimate a two state variance regime switching model, one state with high volatility in crude oil prices and the other one with low volatility in crude oil prices.
The whole program is posted below but some errors occurred. I refered to a RAT textbook to write all the codes but i dont know how to modify the three states model into a two states model. For example, what value should i use to set up " input theta"? I attached my dataset in the attachment.
Thanks very much
Regards
cal(d) 1995:01:03
open data "crude_oil.xls"
data(format=xls,org=cols) 1995:01:03 2011:12:30 price
* Extract the mean from the returns.
*
diff(center) price
*
@MSSetup(states=3)
*
* Provide guess values for theta
*
input theta
4.0 0.0 -4.0
2.0 2.0 -2.0
*
dec vect sigmas(nstates)
stats price
compute sigmas(1)=0.2*%variance
compute sigmas(2)= %variance
compute sigmas(3)=5.0*%variance
Statistics on Series PRICE
Daily(5) Data From 1995:01:03 To 2011:12:30
Observations 4269 Skipped/Missing 165
Sample Mean 0.000000 Variance 840.566132
Standard Error 28.992519 SE of Sample Mean 0.443734
t-Statistic (Mean=0) 0.000000 Signif Level (Mean=0) 1.000000
Skewness 0.885384 Signif Level (Sk=0) 0.000000
Kurtosis (excess) -0.132453 Signif Level (Ku=0) 0.077551
Jarque-Bera 560.869114 Signif Level (JB=0) 0.000000
*
*********************************************************************
*
* RegimeF returns a vector of likelihoods for the various regimes at
* <<time>>. The likelihoods differ in the regimes based upon the
* values of sigmas.
*
function RegimeF time
type vector RegimeF
type integer time
*
local integer i
*
dim RegimeF(nstates)
do i=1,nstates
compute RegimeF(i)=exp(%logdensity(sigmas(i), price(time)))
end do i
end
*********************************************************************
nonlin(parmset=modelparms) sigmas
nonlin(parmset=msparms) theta
*
frml markov = f=RegimeF(t),fpt=%MSProb(t,f),log(fpt)
*
@MSFilterInit
maximize(start=%(p=%mslogisticp(theta),pstar=%MSInit()),$
parmset=msparms+modelparms,$
Markov Switching: Introduction 97
method=bfgs,iters=400,pmethod=simplex,piters=5) markov * 2011:12:30
The Error Occurred At Location 170, Line 13 of %MSINIT
Called From Location 127, Line 13 of MSFILTERINIT
## MAT14. Non-invertible Matrix. Using Generalized Inverse for SYMMETRIC.
## OP3. This Instruction Does Not Have An Option MAR
>>>>Markov <<<<
*
@MSSmoothed %regstart() %regend() psmooth
set p1 = psmooth(t)(1)
set p2 = psmooth(t)(2)
set p3 = psmooth(t)(3)
graph(style=stacked,maximum=1.0,picture="##.##",$
header="Smoothed Probabilities of Variance Regimes",key=below,$
klabels=||"Low Variance","Medium Variance","High Variance"||) 3
# p1
# p2
# p3
## MAT15. Subscripts Too Large or Non-Positive
The Error Occurred At Location 66, Line 9 of MSSMOOTHED
*
set variance = p1*sigmas(1)+p2*sigmas(2)+p3*sigmas(3)
graph(footer="Figure 4.10 Estimated variance of historical stock returns")
# variance
## SX11. Identifier P1 is Not Recognizable. Incorrect Option Field or Parameter Order?
>>>>set variance = p1*s<<<<
set stdu = pricesqrt(variance)
graph(footer="Figure 4.11a Plot of standardized stock returns")
# stdu
- Attachments
-
- crude_oil.xls
- (213 KiB) Downloaded 1019 times
Re: three state variance regime switching model
What's your data series? You are analyzing it as if they are returns, but they look like market prices instead. Also, you have missing values, which have to be either patched over or squeezed out of the data set.
-
superper2008
- Posts: 32
- Joined: Tue Mar 27, 2012 12:48 pm
Re: three state variance regime switching model
Hello Tom:
I used return instead of price to run the codes again but the same errors occurred as well. Also, i deleted all the missing values. I attached my codes below. Could you check it for me please? Also, I would like to estimate a two states variance regime switching model rather than three states. but i don't know how to revise the codes for two states... My dataset is in the attachment. Thanks very much. I am looking forward to your reply..
regards
cal(d) 1995:01:03
open data "crude_oil.xls"
data(format=xls,org=cols) 1995:01:03 2011:12:30 return
sample(smpl=%valid(return)) return / return_nomissing
* Extract the mean from the returns.
*
diff(center) return_nomissing
*
@MSSetup(states=3)
*
* Provide guess values for theta
*
input theta
4.0 0.0 -4.0
2.0 2.0 -2.0
*
dec vect sigmas(nstates)
stats return_nomissing
compute sigmas(1)=0.2*%variance
compute sigmas(2)= %variance
compute sigmas(3)=5.0*%variance
Statistics on Series RETURN_NOMISSING
Daily(5) Data From 1995:01:04 To 2011:05:13
Observations 4268
Sample Mean 0.000000 Variance 0.000645
Standard Error 0.025389 SE of Sample Mean 0.000389
t-Statistic (Mean=0) 0.000000 Signif Level (Mean=0) 1.000000
Skewness 0.053979 Signif Level (Sk=0) 0.150102
Kurtosis (excess) 4.664352 Signif Level (Ku=0) 0.000000
Jarque-Bera 3871.046787 Signif Level (JB=0) 0.000000
*
*********************************************************************
*
* RegimeF returns a vector of likelihoods for the various regimes at
* <<time>>. The likelihoods differ in the regimes based upon the
* values of sigmas.
*
function RegimeF time
type vector RegimeF
type integer time
*
local integer i
*
dim RegimeF(nstates)
do i=1,nstates
compute RegimeF(i)=exp(%logdensity(sigmas(i), return_nomissing(time)))
end do i
end
*********************************************************************
nonlin(parmset=modelparms) sigmas
nonlin(parmset=msparms) theta
*
frml markov = f=RegimeF(t),fpt=%MSProb(t,f),log(fpt)
*
@MSFilterInit
maximize(start=%(p=%mslogisticp(theta),pstar=%MSInit()),$
parmset=msparms+modelparms,$
Markov Switching: Introduction 97
method=bfgs,iters=400,pmethod=simplex,piters=5) markov * 2011:12:30
The Error Occurred At Location 170, Line 13 of %MSINIT
Called From Location 127, Line 13 of MSFILTERINIT
## MAT14. Non-invertible Matrix. Using Generalized Inverse for SYMMETRIC.
## OP3. This Instruction Does Not Have An Option MAR
>>>>Markov <<<<
>>>>Markov <<<<
>>>>Markov <<<<
*
@MSSmoothed %regstart() %regend() psmooth
set p1 = psmooth(t)(1)
set p2 = psmooth(t)(2)
set p3 = psmooth(t)(3)
graph(style=stacked,maximum=1.0,picture="##.##",$
header="Smoothed Probabilities of Variance Regimes",key=below,$
klabels=||"Low Variance","Medium Variance","High Variance"||) 3
# p1
# p2
# p3
*
set variance = p1*sigmas(1)+p2*sigmas(2)+p3*sigmas(3)
graph(footer="Figure 4.10 Estimated variance of historical stock returns")
# variance
set stdu = pricesqrt(variance)
graph(footer="Figure 4.11a Plot of standardized stock returns")
# stdu
I used return instead of price to run the codes again but the same errors occurred as well. Also, i deleted all the missing values. I attached my codes below. Could you check it for me please? Also, I would like to estimate a two states variance regime switching model rather than three states. but i don't know how to revise the codes for two states... My dataset is in the attachment. Thanks very much. I am looking forward to your reply..
regards
cal(d) 1995:01:03
open data "crude_oil.xls"
data(format=xls,org=cols) 1995:01:03 2011:12:30 return
sample(smpl=%valid(return)) return / return_nomissing
* Extract the mean from the returns.
*
diff(center) return_nomissing
*
@MSSetup(states=3)
*
* Provide guess values for theta
*
input theta
4.0 0.0 -4.0
2.0 2.0 -2.0
*
dec vect sigmas(nstates)
stats return_nomissing
compute sigmas(1)=0.2*%variance
compute sigmas(2)= %variance
compute sigmas(3)=5.0*%variance
Statistics on Series RETURN_NOMISSING
Daily(5) Data From 1995:01:04 To 2011:05:13
Observations 4268
Sample Mean 0.000000 Variance 0.000645
Standard Error 0.025389 SE of Sample Mean 0.000389
t-Statistic (Mean=0) 0.000000 Signif Level (Mean=0) 1.000000
Skewness 0.053979 Signif Level (Sk=0) 0.150102
Kurtosis (excess) 4.664352 Signif Level (Ku=0) 0.000000
Jarque-Bera 3871.046787 Signif Level (JB=0) 0.000000
*
*********************************************************************
*
* RegimeF returns a vector of likelihoods for the various regimes at
* <<time>>. The likelihoods differ in the regimes based upon the
* values of sigmas.
*
function RegimeF time
type vector RegimeF
type integer time
*
local integer i
*
dim RegimeF(nstates)
do i=1,nstates
compute RegimeF(i)=exp(%logdensity(sigmas(i), return_nomissing(time)))
end do i
end
*********************************************************************
nonlin(parmset=modelparms) sigmas
nonlin(parmset=msparms) theta
*
frml markov = f=RegimeF(t),fpt=%MSProb(t,f),log(fpt)
*
@MSFilterInit
maximize(start=%(p=%mslogisticp(theta),pstar=%MSInit()),$
parmset=msparms+modelparms,$
Markov Switching: Introduction 97
method=bfgs,iters=400,pmethod=simplex,piters=5) markov * 2011:12:30
The Error Occurred At Location 170, Line 13 of %MSINIT
Called From Location 127, Line 13 of MSFILTERINIT
## MAT14. Non-invertible Matrix. Using Generalized Inverse for SYMMETRIC.
## OP3. This Instruction Does Not Have An Option MAR
>>>>Markov <<<<
>>>>Markov <<<<
>>>>Markov <<<<
*
@MSSmoothed %regstart() %regend() psmooth
set p1 = psmooth(t)(1)
set p2 = psmooth(t)(2)
set p3 = psmooth(t)(3)
graph(style=stacked,maximum=1.0,picture="##.##",$
header="Smoothed Probabilities of Variance Regimes",key=below,$
klabels=||"Low Variance","Medium Variance","High Variance"||) 3
# p1
# p2
# p3
*
set variance = p1*sigmas(1)+p2*sigmas(2)+p3*sigmas(3)
graph(footer="Figure 4.10 Estimated variance of historical stock returns")
# variance
set stdu = pricesqrt(variance)
graph(footer="Figure 4.11a Plot of standardized stock returns")
# stdu
- Attachments
-
- crude_oil.xls
- (249 KiB) Downloaded 970 times
Re: three state variance regime switching model
Part of your problem is that you're trying to copy this out of the PDF, but when you do that, you're getting the page headers. Use the separate .RPF files as the base.
When you do the SAMPLE instruction, you no longer have data through 2011:12:30 in the daily CALENDAR. Instead, save the number of observations (here into GEND) and reset the ALLOCATE length:
sample(smpl=%valid(return)) return / return_nomissing
compute gend=%nobs
allocate gend
etc.
To change to 2 states, change to STATES=2, change the input theta to a 2 x 1 rather than 3 x 2 (4.0 -4.0 is probably a good starting value), change the guess values of the SIGMAS.
When you do the SAMPLE instruction, you no longer have data through 2011:12:30 in the daily CALENDAR. Instead, save the number of observations (here into GEND) and reset the ALLOCATE length:
sample(smpl=%valid(return)) return / return_nomissing
compute gend=%nobs
allocate gend
etc.
To change to 2 states, change to STATES=2, change the input theta to a 2 x 1 rather than 3 x 2 (4.0 -4.0 is probably a good starting value), change the guess values of the SIGMAS.
-
superper2008
- Posts: 32
- Joined: Tue Mar 27, 2012 12:48 pm
Re: three state variance regime switching model
Hi Tom,
I revised the code according to your suggestion but the same error still occurred. I attached my code below and uploaded my dataset in the attachment.
How can i solve the problem? I didn't do the two states model because this three states one didn't work out yet. Thanks very much. I am looking forward to your reply..
Regards
cal(d) 1995:01:03
open data "crude_oil.xls"
data(format=xls,org=cols) 1995:01:03 2011:12:30 return
sample(smpl=%valid(return)) return / return_nomissing
compute gend=%nobs
allocate gend
* Extract the mean from the returns.
*
diff(center) return_nomissing
*
@MSSetup(states=3)
*
* Provide guess values for theta
*
input theta
4.0 0.0 -4.0
2.0 2.0 -2.0
*
dec vect sigmas(nstates)
stats return_nomissing
compute sigmas(1)=0.2*%variance
compute sigmas(2)= %variance
compute sigmas(3)=5.0*%variance
Statistics on Series RETURN_NOMISSING
Daily(5) Data From 1995:01:04 To 2011:05:13
Observations 4268
Sample Mean 0.000000 Variance 0.000645
Standard Error 0.025389 SE of Sample Mean 0.000389
t-Statistic (Mean=0) 0.000000 Signif Level (Mean=0) 1.000000
Skewness 0.053979 Signif Level (Sk=0) 0.150102
Kurtosis (excess) 4.664352 Signif Level (Ku=0) 0.000000
Jarque-Bera 3871.046787 Signif Level (JB=0) 0.000000
*
*********************************************************************
*
* RegimeF returns a vector of likelihoods for the various regimes at
* <<time>>. The likelihoods differ in the regimes based upon the
* values of sigmas.
*
function RegimeF time
type vector RegimeF
type integer time
*
local integer i
*
dim RegimeF(nstates)
do i=1,nstates
compute RegimeF(i)=exp(%logdensity(sigmas(i), return_nomissing(time)))
end do i
end
*********************************************************************
nonlin(parmset=modelparms) sigmas
nonlin(parmset=msparms) theta
*
frml markov = f=RegimeF(t),fpt=%MSProb(t,f),log(fpt)
*
@MSFilterInit
maximize(start=%(p=%mslogisticp(theta),pstar=%MSInit()),$
parmset=msparms+modelparms,$
Markov Switching: Introduction 97
method=bfgs,iters=400,pmethod=simplex,piters=5) markov * 2011:12:30
The Error Occurred At Location 170, Line 13 of %MSINIT
Called From Location 127, Line 13 of MSFILTERINIT
## MAT14. Non-invertible Matrix. Using Generalized Inverse for SYMMETRIC.
## OP3. This Instruction Does Not Have An Option MAR
>>>>Markov <<<<
>>>>Markov <<<<
>>>>Markov <<<<
>>>>Markov <<<<
>>>>Markov <<<<
*
@MSSmoothed %regstart() %regend() psmooth
set p1 = psmooth(t)(1)
set p2 = psmooth(t)(2)
set p3 = psmooth(t)(3)
graph(style=stacked,maximum=1.0,picture="##.##",$
header="Smoothed Probabilities of Variance Regimes",key=below,$
klabels=||"Low Variance","Medium Variance","High Variance"||) 3
# p1
# p2
# p3
*
set variance = p1*sigmas(1)+p2*sigmas(2)+p3*sigmas(3)
graph(footer="Figure 4.10 Estimated variance of historical stock returns")
# variance
set stdu = pricesqrt(variance)
graph(footer="Figure 4.11a Plot of standardized stock returns")
# stdu
I revised the code according to your suggestion but the same error still occurred. I attached my code below and uploaded my dataset in the attachment.
How can i solve the problem? I didn't do the two states model because this three states one didn't work out yet. Thanks very much. I am looking forward to your reply..
Regards
cal(d) 1995:01:03
open data "crude_oil.xls"
data(format=xls,org=cols) 1995:01:03 2011:12:30 return
sample(smpl=%valid(return)) return / return_nomissing
compute gend=%nobs
allocate gend
* Extract the mean from the returns.
*
diff(center) return_nomissing
*
@MSSetup(states=3)
*
* Provide guess values for theta
*
input theta
4.0 0.0 -4.0
2.0 2.0 -2.0
*
dec vect sigmas(nstates)
stats return_nomissing
compute sigmas(1)=0.2*%variance
compute sigmas(2)= %variance
compute sigmas(3)=5.0*%variance
Statistics on Series RETURN_NOMISSING
Daily(5) Data From 1995:01:04 To 2011:05:13
Observations 4268
Sample Mean 0.000000 Variance 0.000645
Standard Error 0.025389 SE of Sample Mean 0.000389
t-Statistic (Mean=0) 0.000000 Signif Level (Mean=0) 1.000000
Skewness 0.053979 Signif Level (Sk=0) 0.150102
Kurtosis (excess) 4.664352 Signif Level (Ku=0) 0.000000
Jarque-Bera 3871.046787 Signif Level (JB=0) 0.000000
*
*********************************************************************
*
* RegimeF returns a vector of likelihoods for the various regimes at
* <<time>>. The likelihoods differ in the regimes based upon the
* values of sigmas.
*
function RegimeF time
type vector RegimeF
type integer time
*
local integer i
*
dim RegimeF(nstates)
do i=1,nstates
compute RegimeF(i)=exp(%logdensity(sigmas(i), return_nomissing(time)))
end do i
end
*********************************************************************
nonlin(parmset=modelparms) sigmas
nonlin(parmset=msparms) theta
*
frml markov = f=RegimeF(t),fpt=%MSProb(t,f),log(fpt)
*
@MSFilterInit
maximize(start=%(p=%mslogisticp(theta),pstar=%MSInit()),$
parmset=msparms+modelparms,$
Markov Switching: Introduction 97
method=bfgs,iters=400,pmethod=simplex,piters=5) markov * 2011:12:30
The Error Occurred At Location 170, Line 13 of %MSINIT
Called From Location 127, Line 13 of MSFILTERINIT
## MAT14. Non-invertible Matrix. Using Generalized Inverse for SYMMETRIC.
## OP3. This Instruction Does Not Have An Option MAR
>>>>Markov <<<<
>>>>Markov <<<<
>>>>Markov <<<<
>>>>Markov <<<<
>>>>Markov <<<<
*
@MSSmoothed %regstart() %regend() psmooth
set p1 = psmooth(t)(1)
set p2 = psmooth(t)(2)
set p3 = psmooth(t)(3)
graph(style=stacked,maximum=1.0,picture="##.##",$
header="Smoothed Probabilities of Variance Regimes",key=below,$
klabels=||"Low Variance","Medium Variance","High Variance"||) 3
# p1
# p2
# p3
*
set variance = p1*sigmas(1)+p2*sigmas(2)+p3*sigmas(3)
graph(footer="Figure 4.10 Estimated variance of historical stock returns")
# variance
set stdu = pricesqrt(variance)
graph(footer="Figure 4.11a Plot of standardized stock returns")
# stdu
- Attachments
-
- crude_oil.xls
- (249.5 KiB) Downloaded 1045 times
Re: three state variance regime switching model
This line is out of a page header - get rid of it
Markov Switching: Introduction 97
Markov Switching: Introduction 97
-
superper2008
- Posts: 32
- Joined: Tue Mar 27, 2012 12:48 pm
Re: three state variance regime switching model
Hi Tom,
I got rid of the textbook header but the errors still occurred. I attached my codes below. Please give me a hint on how to solve the problem. Thanks very much.
Regards
cal(d) 1995:01:03
open data "crude_oil.xls"
data(format=xls,org=cols) 1995:01:03 2011:12:30 return
sample(smpl=%valid(return)) return / return_nomissing
compute gend=%nobs
allocate gend
* Extract the mean from the returns.
*
diff(center) return_nomissing
*
@MSSetup(states=3)
*
* Provide guess values for theta
*
input theta
4.0 0.0 -4.0
2.0 2.0 -2.0
*
dec vect sigmas(nstates)
stats return_nomissing
compute sigmas(1)=0.2*%variance
compute sigmas(2)= %variance
compute sigmas(3)=5.0*%variance
Statistics on Series RETURN_NOMISSING
Daily(5) Data From 1995:01:04 To 2011:05:13
Observations 4268
Sample Mean 0.000000 Variance 0.000645
Standard Error 0.025389 SE of Sample Mean 0.000389
t-Statistic (Mean=0) 0.000000 Signif Level (Mean=0) 1.000000
Skewness 0.053979 Signif Level (Sk=0) 0.150102
Kurtosis (excess) 4.664352 Signif Level (Ku=0) 0.000000
Jarque-Bera 3871.046787 Signif Level (JB=0) 0.000000
*
*********************************************************************
*
* RegimeF returns a vector of likelihoods for the various regimes at
* <<time>>. The likelihoods differ in the regimes based upon the
* values of sigmas.
*
function RegimeF time
type vector RegimeF
type integer time
*
local integer i
*
dim RegimeF(nstates)
do i=1,nstates
compute RegimeF(i)=exp(%logdensity(sigmas(i), return_nomissing(time)))
end do i
end
*********************************************************************
nonlin(parmset=modelparms) sigmas
nonlin(parmset=msparms) theta
*
frml markov = f=RegimeF(t),fpt=%MSProb(t,f),log(fpt)
*
@MSFilterInit
maximize(start=%(p=%mslogisticp(theta),pstar=%MSInit()),$
parmset=msparms+modelparms,$
The Error Occurred At Location 170, Line 13 of %MSINIT
Called From Location 127, Line 13 of MSFILTERINIT
## MAT14. Non-invertible Matrix. Using Generalized Inverse for SYMMETRIC.method=bfgs,iters=400,pmethod=simplex,piters=5) markov * 2011:12:30
## MAT15. Subscripts Too Large or Non-Positive
The Error Occurred At Location 196, Line 19 of %MSPROB>>>><<<<
>>>>Markov <<<<
>>>>Markov <<<<
>>>>Markov <<<<
>>>>Markov <<<<
>>>>Markov <<<<
*
@MSSmoothed %regstart() %regend() psmooth
set p1 = psmooth(t)(1)
set p2 = psmooth(t)(2)
set p3 = psmooth(t)(3)
graph(style=stacked,maximum=1.0,picture="##.##",$
header="Smoothed Probabilities of Variance Regimes",key=below,$
klabels=||"Low Variance","Medium Variance","High Variance"||) 3
# p1
# p2
# p3
*
set variance = p1*sigmas(1)+p2*sigmas(2)+p3*sigmas(3)
graph(footer="Figure 4.10 Estimated variance of historical stock returns")
# variance
set stdu = pricesqrt(variance)
graph(footer="Figure 4.11a Plot of standardized stock returns")
# stdu
I got rid of the textbook header but the errors still occurred. I attached my codes below. Please give me a hint on how to solve the problem. Thanks very much.
Regards
cal(d) 1995:01:03
open data "crude_oil.xls"
data(format=xls,org=cols) 1995:01:03 2011:12:30 return
sample(smpl=%valid(return)) return / return_nomissing
compute gend=%nobs
allocate gend
* Extract the mean from the returns.
*
diff(center) return_nomissing
*
@MSSetup(states=3)
*
* Provide guess values for theta
*
input theta
4.0 0.0 -4.0
2.0 2.0 -2.0
*
dec vect sigmas(nstates)
stats return_nomissing
compute sigmas(1)=0.2*%variance
compute sigmas(2)= %variance
compute sigmas(3)=5.0*%variance
Statistics on Series RETURN_NOMISSING
Daily(5) Data From 1995:01:04 To 2011:05:13
Observations 4268
Sample Mean 0.000000 Variance 0.000645
Standard Error 0.025389 SE of Sample Mean 0.000389
t-Statistic (Mean=0) 0.000000 Signif Level (Mean=0) 1.000000
Skewness 0.053979 Signif Level (Sk=0) 0.150102
Kurtosis (excess) 4.664352 Signif Level (Ku=0) 0.000000
Jarque-Bera 3871.046787 Signif Level (JB=0) 0.000000
*
*********************************************************************
*
* RegimeF returns a vector of likelihoods for the various regimes at
* <<time>>. The likelihoods differ in the regimes based upon the
* values of sigmas.
*
function RegimeF time
type vector RegimeF
type integer time
*
local integer i
*
dim RegimeF(nstates)
do i=1,nstates
compute RegimeF(i)=exp(%logdensity(sigmas(i), return_nomissing(time)))
end do i
end
*********************************************************************
nonlin(parmset=modelparms) sigmas
nonlin(parmset=msparms) theta
*
frml markov = f=RegimeF(t),fpt=%MSProb(t,f),log(fpt)
*
@MSFilterInit
maximize(start=%(p=%mslogisticp(theta),pstar=%MSInit()),$
parmset=msparms+modelparms,$
The Error Occurred At Location 170, Line 13 of %MSINIT
Called From Location 127, Line 13 of MSFILTERINIT
## MAT14. Non-invertible Matrix. Using Generalized Inverse for SYMMETRIC.method=bfgs,iters=400,pmethod=simplex,piters=5) markov * 2011:12:30
## MAT15. Subscripts Too Large or Non-Positive
The Error Occurred At Location 196, Line 19 of %MSPROB>>>><<<<
>>>>Markov <<<<
>>>>Markov <<<<
>>>>Markov <<<<
>>>>Markov <<<<
>>>>Markov <<<<
*
@MSSmoothed %regstart() %regend() psmooth
set p1 = psmooth(t)(1)
set p2 = psmooth(t)(2)
set p3 = psmooth(t)(3)
graph(style=stacked,maximum=1.0,picture="##.##",$
header="Smoothed Probabilities of Variance Regimes",key=below,$
klabels=||"Low Variance","Medium Variance","High Variance"||) 3
# p1
# p2
# p3
*
set variance = p1*sigmas(1)+p2*sigmas(2)+p3*sigmas(3)
graph(footer="Figure 4.10 Estimated variance of historical stock returns")
# variance
set stdu = pricesqrt(variance)
graph(footer="Figure 4.11a Plot of standardized stock returns")
# stdu
- Attachments
-
- crude_oil.xls
- (249.5 KiB) Downloaded 1000 times
Re: three state variance regime switching model
That isn't code. It's a combination of program and output. You should learn how to use split input/output windows so you don't get things tangled up like that.
You were still using the 2011:12:30 end date on the MAXIMIZE. This looks like it works.
You were still using the 2011:12:30 end date on the MAXIMIZE. This looks like it works.
Code: Select all
cal(d) 1995:01:03
open data "crude_oil.xls"
data(format=xls,org=cols) 1995:01:03 2011:12:30 return
sample(smpl=%valid(return)) return / return_nomissing
compute gend=%nobs
allocate gend
* Extract the mean from the returns.
*
diff(center) return_nomissing
*
@MSSetup(states=3)
*
* Provide guess values for theta
*
input theta
4.0 0.0 -4.0
2.0 2.0 -2.0
*
dec vect sigmas(nstates)
stats return_nomissing
compute sigmas(1)=0.2*%variance
compute sigmas(2)= %variance
compute sigmas(3)=5.0*%variance
*
*********************************************************************
*
* RegimeF returns a vector of likelihoods for the various regimes at
* <<time>>. The likelihoods differ in the regimes based upon the
* values of sigmas.
*
function RegimeF time
type vector RegimeF
type integer time
*
local integer i
*
dim RegimeF(nstates)
do i=1,nstates
compute RegimeF(i)=exp(%logdensity(sigmas(i), return_nomissing(time)))
end do i
end
*********************************************************************
nonlin(parmset=modelparms) sigmas
nonlin(parmset=msparms) theta
*
frml markov = f=RegimeF(t),fpt=%MSProb(t,f),log(fpt)
*
@MSFilterInit
maximize(start=%(p=%mslogisticp(theta),pstar=%MSInit()),$
parmset=msparms+modelparms,$
method=bfgs,iters=400,pmethod=simplex,piters=5) markov
*
@MSSmoothed %regstart() %regend() psmooth
set p1 = psmooth(t)(1)
set p2 = psmooth(t)(2)
set p3 = psmooth(t)(3)
graph(style=stacked,maximum=1.0,picture="##.##",$
header="Smoothed Probabilities of Variance Regimes",key=below,$
klabels=||"Low Variance","Medium Variance","High Variance"||) 3
# p1
# p2
# p3
*
set variance = p1*sigmas(1)+p2*sigmas(2)+p3*sigmas(3)
graph(footer="Figure 4.10 Estimated variance of historical stock returns")
# variance
set stdu = pricesqrt(variance)
graph(footer="Figure 4.11a Plot of standardized stock returns")
# stdu-
superper2008
- Posts: 32
- Joined: Tue Mar 27, 2012 12:48 pm
Re: three state variance regime switching model
Hi Tom,
Thanks very much for your code. It works and I got the graph with high volatility state and low volatility state. But I have to obtain the exact dates of each state to perform the future analysis . For example, when does that high volatility state begin and when does it end? Can I get like a table which shows the dates of each state? Thanks very much
Regards
Thanks very much for your code. It works and I got the graph with high volatility state and low volatility state. But I have to obtain the exact dates of each state to perform the future analysis . For example, when does that high volatility state begin and when does it end? Can I get like a table which shows the dates of each state? Thanks very much
Regards
Re: three state variance regime switching model
You don't seem to be understanding how a MS model works. The model doesn't tell you what regime the system is in---instead, it gives a probability distribution across them at each point in time. The background shading on probability graphs in many papers on MS models are from external sources, like the NBER recession dummies.superper2008 wrote:Hi Tom,
Thanks very much for your code. It works and I got the graph with high volatility state and low volatility state. But I have to obtain the exact dates of each state to perform the future analysis . For example, when does that high volatility state begin and when does it end? Can I get like a table which shows the dates of each state? Thanks very much
Regards
-
superper2008
- Posts: 32
- Joined: Tue Mar 27, 2012 12:48 pm
Re: three state variance regime switching model
Hi Tom,
I am wondering whether it is possible to pick up the dates with over 0.5 probability if i set up 0.5 as the standard to differentiate high volatility from low volatility..I am looking forward to your reply..Thanks very much
I am wondering whether it is possible to pick up the dates with over 0.5 probability if i set up 0.5 as the standard to differentiate high volatility from low volatility..I am looking forward to your reply..Thanks very much
Re: three state variance regime switching model
You have p1, p2 and p3 so that would just be some logical operation applied to those, for instancesuperper2008 wrote:Hi Tom,
I am wondering whether it is possible to pick up the dates with over 0.5 probability if i set up 0.5 as the standard to differentiate high volatility from low volatility..I am looking forward to your reply..Thanks very much
set highvar = p3>.5
-
superper2008
- Posts: 32
- Joined: Tue Mar 27, 2012 12:48 pm
Re: three state variance regime switching model
Hi Tom,
I tried to set p2>0.5 to select the dates with high volatility but the same results showed as before. I attached the code below. Could you please give me some hints on how i should fix the problem and how i can select the dates with high volatility out. Thanks very much
Regards
I tried to set p2>0.5 to select the dates with high volatility but the same results showed as before. I attached the code below. Could you please give me some hints on how i should fix the problem and how i can select the dates with high volatility out. Thanks very much
Regards
Code: Select all
cal(d) 1995:01:03
open data "crude_oil.xls"
data(format=xls,org=cols) 1995:01:03 2011:12:30 return
sample(smpl=%valid(return)) return / return_nomissing
compute gend=%nobs
allocate gend
* Extract the mean from the returns.
*
diff(center) return_nomissing
*
@MSSetup(states=2)
*
* Provide guess values for theta
*
input theta
4.0 -4.0
*
dec vect sigmas(nstates)
stats return_nomissing
compute sigmas(1)=0.2*%variance
compute sigmas(2)=5.0*%variance
*
*********************************************************************
*
* RegimeF returns a vector of likelihoods for the various regimes at
* <<time>>. The likelihoods differ in the regimes based upon the
* values of sigmas.
*
function RegimeF time
type vector RegimeF
type integer time
*
local integer i
*
dim RegimeF(nstates)
do i=1,nstates
compute RegimeF(i)=exp(%logdensity(sigmas(i), return_nomissing(time)))
end do i
end
*********************************************************************
nonlin(parmset=modelparms) sigmas
nonlin(parmset=msparms) theta
*
frml markov = f=RegimeF(t),fpt=%MSProb(t,f),log(fpt)
*
@MSFilterInit
maximize(start=%(p=%mslogisticp(theta),pstar=%MSInit()),$
parmset=msparms+modelparms,$
method=bfgs,iters=400,pmethod=simplex,piters=5) markov
*
@MSSmoothed %regstart() %regend() psmooth
set p1 = psmooth(t)(1)
set p2 = psmooth(t)(2)
set highvar = p2>0.5
graph(style=stacked,maximum=1.0,picture="##.##",$
header="Smoothed Probabilities of Variance Regimes",key=below,$
klabels=||"Low Variance","High Variance"||) 2
# p1
# p2
*
set variance = p1*sigmas(1)+p2*sigmas(2)
graph(footer="Figure 4.10 Estimated variance of historical stock returns")
# variance
set stdu = pricesqrt(variance)
graph(footer="Figure 4.11a Plot of standardized stock returns")
# stdu