Markov-switching models are widely applied in the social sciences. For example, in economics, the growth rate of Gross Domestic Product is modeled as a switching process to capture the asymmetrical behavior observed over expansions and recessions (Hamilton 1989).
Other economic examples include modeling interest rates (Garcia and Perron 1996) and exchange rates (Engel and Hamilton 1990). In finance, Kim, Nelson, and Startz (1998) model monthly stock returns, while Guidolin (2011b, 2011a) provide many applications of these models to returns, portfolio choice, and asset pricing.
Markov-switching models are used for series that are believed to transition over a finite set of unobserved states, allowing the process to evolve differently in each state. The transitions occur according to a Markov process. The time of transition from one state to another and the duration between changes in state is random.
For example, these models can be used to understand the process that governs the time at which economic growth transitions between expansion and recession and the duration of each period.
#Turn the MSwM package on
library(MSwM)
## Loading required package: nlme
## Loading required package: parallel
#Import the data and attach
MSData <- read.csv("https://dl.dropboxusercontent.com/u/18255955/PhD-INCEIF/MSData.csv")
attach(MSData)
#Define dependent variables (1 variable for each equation)
yLVS=cbind(LVS)
yLGS=cbind(LGS)
#Define independent variables (4 variables for each equation)
x=cbind(LRY, LRC, INT, LRV)
Next, we run OLS regression and get results:
#OLS regression for Value Stocks
olsLVS=lm(yLVS~x)
#OLS regression for Growth Stocks
olsLGS=lm(yLGS~x)
#Obtain the results of both
summary(olsLVS)
##
## Call:
## lm(formula = yLVS ~ x)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.57390 -0.07711 -0.00725 0.07179 0.39578
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -9.151035 1.950114 -4.693 1.57e-05 ***
## xLRY 1.043820 0.200840 5.197 2.48e-06 ***
## xLRC 0.123601 0.210845 0.586 0.5599
## xINT 0.013357 0.020907 0.639 0.5253
## xLRV -0.012112 0.005686 -2.130 0.0372 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.1431 on 61 degrees of freedom
## Multiple R-squared: 0.8042, Adjusted R-squared: 0.7914
## F-statistic: 62.64 on 4 and 61 DF, p-value: < 2.2e-16
summary(olsLGS)
##
## Call:
## lm(formula = yLGS ~ x)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.62267 -0.11945 0.01245 0.07490 0.78002
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -7.711885 2.663863 -2.895 0.00525 **
## xLRY 0.827857 0.274348 3.018 0.00371 **
## xLRC 0.089680 0.288015 0.311 0.75658
## xINT 0.110447 0.028559 3.867 0.00027 ***
## xLRV -0.009277 0.007767 -1.194 0.23691
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.1954 on 61 degrees of freedom
## Multiple R-squared: 0.2924, Adjusted R-squared: 0.246
## F-statistic: 6.303 on 4 and 61 DF, p-value: 0.0002596
Next step is to run Markov-switching models and get results:
# MS for Value Stocks (k is number of regimes, 6 is for means of 5 variables
# + 1 for volatility)
msLVS = msmFit(olsLVS, k = 2, sw = rep(TRUE, 6))
# MS for Growth Stocks
msLGS = msmFit(olsLGS, k = 2, sw = rep(TRUE, 6))
# Obtain the results of both
summary(msLVS)
## Markov Switching Model
##
## Call: msmFit(object = olsLVS, k = 2, sw = rep(TRUE, 6))
##
## AIC BIC logLik
## -102.0478 -38.25474 61.02392
##
## Coefficients:
##
## Regime 1
## ---------
## Estimate Std. Error t value Pr(>|t|)
## (Intercept)(S) -10.7330 0.5460 -19.6575 < 2.2e-16 ***
## xLRY(S) 1.6984 0.0303 56.0528 < 2.2e-16 ***
## xLRC(S) -0.3478 0.0414 -8.4010 < 2.2e-16 ***
## xINT(S) 0.0411 0.0020 20.5500 < 2.2e-16 ***
## xLRV(S) -0.0139 0.0015 -9.2667 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.03610862
## Multiple R-squared: 0.9893
##
## Standardized Residuals:
## Min Q1 Med Q3 Max
## -8.340128e-02 -1.065220e-02 -3.682610e-16 1.117322e-02 7.650599e-02
##
## Regime 2
## ---------
## Estimate Std. Error t value Pr(>|t|)
## (Intercept)(S) 13.6836 2.1898 6.2488 4.136e-10 ***
## xLRY(S) 0.7522 0.1800 4.1789 2.929e-05 ***
## xLRC(S) -1.2801 0.1608 -7.9608 1.776e-15 ***
## xINT(S) -0.1005 0.0388 -2.5902 0.009592 **
## xLRV(S) 0.0487 0.0201 2.4229 0.015397 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.1515668
## Multiple R-squared: 0.5145
##
## Standardized Residuals:
## Min Q1 Med Q3 Max
## -0.48074613 -0.02481690 0.00113687 0.02751167 0.46264470
##
## Transition probabilities:
## Regime 1 Regime 2
## Regime 1 0.8255604 0.1692358
## Regime 2 0.1744396 0.8307642
summary(msLGS)
## Markov Switching Model
##
## Call: msmFit(object = olsLGS, k = 2, sw = rep(TRUE, 6))
##
## AIC BIC logLik
## -65.43317 -1.640072 42.71658
##
## Coefficients:
##
## Regime 1
## ---------
## Estimate Std. Error t value Pr(>|t|)
## (Intercept)(S) -8.5099 0.8361 -10.1781 < 2.2e-16 ***
## xLRY(S) 0.5287 0.0940 5.6245 1.860e-08 ***
## xLRC(S) 0.4282 0.0871 4.9162 8.824e-07 ***
## xINT(S) 0.0718 0.0100 7.1800 6.972e-13 ***
## xLRV(S) -0.0081 0.0029 -2.7931 0.005221 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.0676098
## Multiple R-squared: 0.803
##
## Standardized Residuals:
## Min Q1 Med Q3 Max
## -1.356430e-01 -2.402493e-02 6.076829e-06 3.124204e-02 1.493800e-01
##
## Regime 2
## ---------
## Estimate Std. Error t value Pr(>|t|)
## (Intercept)(S) 14.9726 4.1221 3.6323 0.0002809 ***
## xLRY(S) 1.4894 0.3053 4.8785 1.069e-06 ***
## xLRC(S) -2.1932 0.2741 -8.0015 1.332e-15 ***
## xINT(S) 0.1022 0.0651 1.5699 0.1164384
## xLRV(S) 0.0466 0.0309 1.5081 0.1315289
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.2376528
## Multiple R-squared: 0.4281
##
## Standardized Residuals:
## Min Q1 Med Q3 Max
## -0.573535743 -0.021589934 0.004829526 0.018767748 0.681347620
##
## Transition probabilities:
## Regime 1 Regime 2
## Regime 1 0.91482576 0.1190067
## Regime 2 0.08517424 0.8809933
Next, we get graphs with regime probabilities:
par(mar=c(3,3,3,3))
plotProb(msLVS, which=1)
plotProb(msLVS, which=2)
par(mar=c(3,3,3,3))
plotProb(msLGS, which=1)
plotProb(msLGS, which=2)
Finally, we get diagnostic tests:
par(mar=c(3,3,3,3))
plotDiag(msLVS, regime=1, which=1)
plotDiag(msLVS, regime=1, which=2)
plotDiag(msLVS, regime=1, which=3)
#Same is for regime=2
par(mar=c(3,3,3,3))
plotDiag(msLGS, regime=1, which=1)
plotDiag(msLGS, regime=1, which=2)
plotDiag(msLGS, regime=1, which=3)
#Same is for regime=2
The argument which has three values:
1: represents the plot of residuals against fitted values.
2: represents the Normal Q-Q plot.
3: represents the ACF/PACF of residuals and ACF/PACF of square residuals.
Notes:
The data file contains the following variables: LRY( log of Nominal GDP of MY), LRV (Volatility of Stock Market), LRC (log of Bank Credit), INT (Interest Rate), LVS (log of Value Stocks), and LGS (log of Growth Stocks).
Definitions of Growth and Value stocks: > Growth Stocks = growing stocks with potential for continued growth. (ROE, EPS, etc) > Value Stocks = under-priced stocks having the potential for an increase when the market corrects the price. (P/E, PEG<1, MV<BV, etc).