23 views

Uploaded by silvio di sanzo

Markov Regime-Switching

save

- Internship Report Format Etc Feb20 2011
- State Feedback
- Sol9.pdf
- Non-Linear Moving Target Tracking: A Particle Filter Approach
- National Science Foundation: chap1
- Thesis
- Q Parameterization
- 313
- Control using State Feedback and State Augmentation
- 978-3-642-30976-2_37
- Predictive Analysis on Electric-power Supply and Demand in China
- Multivariable Control-Oriented Modeling of a Direct
- S15-2010-Adaptive Kalman Filtering in Networked Systems With Random Sensor Delays, Multiple Packet Dropouts and Missing Measurements
- Clasede Control
- Control Tutorials for MATLAB and Simulink - Cruise Control_ System Modeling
- w7103
- Exercises
- What is a demand forecast
- Page 2008
- Traffic Project Details
- Robust Scheduler Fuzzy Controller.pdf
- A Survey on Approaches for Object Tracking
- A Kalman Filter Based Transient State Estimation Method Applicable to Whole or Specific Region of Power Systems Having Known and Unknow Loads
- Deformation in indonesia.docx
- 3.Mathematical Modelling
- 01 Introduction
- CMA Additive and Multiplicative
- ch16MarkovAnalysis
- Demand Forecasting
- Filetype PDF Nonstationary Inventory Model With Several Demand Classes
- Chameleon
- Paper_20_04_2017
- chameleon.docx
- The-Complete-Book-of-Drum-Fills.pdf
- Markov Regime-Switching (and some State Space) Models in Energy Markets.pdf

You are on page 1of 56

)

Models in Energy Markets

Matthew Brigida, Ph.D.

Department of Finance

College of Business Administration

Clarion University of Pennsylvania

Clarion, PA 16214

mbrigida@clarion.edu

June 2015

Introduction

**Time series often exhibit distinct changes in regime. Thus we must
**

allow for switches in model parameters and standard errors. For

example events which may cause a distinct shift are:

recession or economic expansion (any economic variable or

relationship).

central bank currency intervention (currency volatility).

the introduction of hydrofracking (the relationship between

natural gas and crude oil prices).

a weather event or plant outage (power price volatility, average

returns, autocorrelation).

However, we usually don’t know exactly when the event occurred, so

we cannot use introduce indicator variables. Moreover, it is preferable

to have a probability law over the entire data generating process

(because a priori the timing of the regime switch is uncertain).

Dr. Matt Brigida, mbrigida@clarion.edu Markov Regime-Switching in Energy Markets

Introduction

**Regime-switching may also explain deviations from normality often
**

seen in time series.

Do stock returns really have fat tails (motivating a Cauchy type

distribution)? Or rather are returns normal, but generated by

multiple regimes?

Skewness may be explained similarly.

Dr. Matt Brigida, mbrigida@clarion.edu Markov Regime-Switching in Energy Markets

An Example: Electricity Prices

**rt = µSt + eSt , eSt ∼ N (0, σS2t )
**

Low volatility regime: µL = -0.34%, σL = 13.5%

High volatility regime: µH = 0.2%, σH = 19.8%

Empirical: µ = -0.12%, σ = 16.3%, skewness = 0.354, kurtosis = 4.8

The transition matrix for the Markov process is:

Low High

Low 63% 34%

High 58% 41%

Dr. Matt Brigida, mbrigida@clarion.edu Markov Regime-Switching in Energy Markets

Introduction

**Ultimately, we will allow the time series to follow n distinct density
**

functions, and switch between these density functions according to an

unobserved Markov process. Thus, we need to make inference about

the parameters of the density functions, as well as the Markov process

(transition probabilities and filtered (or smoothed) regime probabilities

P(St = i|ϕt−1 ))1 .

1

where ϕt−1 is the information available through time t − 1.

Dr. Matt Brigida, mbrigida@clarion.edu Markov Regime-Switching in Energy Markets

Dr.Gregory and Hansen (1996) Test for Regime-Shifts in a Cointegrating Relationship Prior to using a Markov-switching model it is useful to test for regime switching.rep(1.edu Markov Regime-Switching in Energy Markets .i).0 for(i in 1:length(oil)){ adf.log(data$oil) gas <.log(data$ng) ind <. Matt Brigida.i] <. The critical values were found via simulation.m2) You then compare the minimum ADF statistic to approximate asymptotic critical values supplied in Gregory and Hansen (1996).m2 <.i]+oil)$resid)$statistic} min(adf. Code oil <. nrow=length(oil).matrix(0.m2[i] <.adf.test(lm(gas˜ind[. ncol=length(oil)) for(i in 1:length(oil)){ ind[.c(rep(0. mbrigida@clarion.(length(oil)-i)))} adf.

i. In the non-switching case we may simply maximize the log-likelihood L(θ) = T P t=1 ln(f (yt )) where f (•) denotes the normal distribution. 1} (in the case of 2 regimes). Let θ denote the vector of parameters (here θ = (β σ 2 )0 ). where et ∼ i. Dr.Background Say we have yt = xt β + et .edu Markov Regime-Switching in Energy Markets . If there is switching. and the regime at each time (St ) is known a priori then we have L(θ) = T t=1 ln(f (yt |St )) where the St are P indicator variables in βSt = β1 (1 − St ) + β2 St and σS2t = σ12 (1 − St ) + σ22 St where St ∈ {0. mbrigida@clarion.d. Matt Brigida. and xt is a k vector of exogenous variables. σ 2 ).N (0.

St |ϕt−1 ) = f (yt |St .edu Markov Regime-Switching in Energy Markets . yt )f (St |ϕt−1 ) where ϕt−1 denotes the information set though time t − 1. Dr. then we’ll need the joint density f (yt . however. mbrigida@clarion. ϕt )f (St |ϕt−1 ) P PT We then have L(θ) = t=1 ln(f (yt |ϕt−1 )). We then maximize this wrt θ = (βS1 βS2 σS21 σS22 )0 and whatever parameters govern the regime switching process. In the case of two regimes: f (yt |ϕt−1 ) = 2St =1 f (yt |St .Background: Unobserved Regimes If the regime states are unobserved. We may then obtain the marginal f (yt |ϕt−1 ) by summing over all possible regimes. Matt Brigida.

2 the variables must be conditionally uncorrelated with the regime of the Markov process (Filardo (1998)) Dr. Matt Brigida.edu Markov Regime-Switching in Energy Markets . We may consider: Switching which is independent of prior regimes (can be dependent on exogenous variables). Markov-switching with constant transition probabilities (dependent on the prior or lagged regime). f (St |ϕt−1 )). Markov-switching with time-varying transition probabilities (the regime is a function of other variables2 ).The Regime Switching Process Now we must consider the process governing regime-switching (i.e. mbrigida@clarion.

edu Markov Regime-Switching in Energy Markets .t−1 and maximize wrt p0 . Matt Brigida. σS22 You could also replace p with a function of exogenous variables (zt−1 ): say. mbrigida@clarion. This formulation is often implausible from an economic standpoint.t−1 + p2 z2. σS21 . Dr. p2 . βS2 . p1 . and the parameters governing f (yt |St . there is a greater probability of a recession tomorrow). That is the parameters governing f (St |ϕt−1 ) which is p.Independent Switching In the case of independent switching f (St |ϕt−1 ) may have the law: ep P[St = 1] = 1+e p ep P[St = 2] = 1 − 1+e p where L is maximized (unconstrained) wrt θ = (βS1 βS2 σS21 σS22 p)0 . replace p with p0 + p1 z1. ϕt ) which are βS1 . Usually the present regime is dependent on the prior regime (if we are in a recession today.

ϕt−1 . xt . For the inference note: P(yt . ϕt−1 . ϕt−1 . θ) P(St = j|xt . of the regime at each t (this is where the Hamilton filter comes in). 2}. θ] and P[St = j|ϕt . θ) P(St = j|ϕt . That is. ϕt−1 .Markov Regime-Switching: Constant Transition Probabilities Continuing with 2 regimes. θ) Dr. Matt Brigida. ϕt−1 . xt . 1 − p11 p22 We’ll need to make an optimal forecast. St = j|xt . θ) = f (yt |xt . ϕt−1 . we’ll need P[St = j|ϕt−1 .edu Markov Regime-Switching in Energy Markets . θ) = P2 j=1 P(St = j|xt . mbrigida@clarion. ϕt−1 . θ)f (yt |St = j. and optimal inference. θ) = P(St = j|yt . we’ll allow the regimes to evolve according to a first-order " Markov process # with constant transition probabilities: p11 1 − p22 P= . θ)f (yt |St = j. xt . θ] where j ∈ {1.

xt .Continued. θ) be a [2x1] vector. 2} into a [2x1] vector ξˆt|t . Similarly let ηt = f (yt |St = j. θ) for j ∈ {1. Then we may rewrite the optimal inference in vector notation as (using Hamilton’s notation): ξˆt|t−1 . Collect P(St = j|ϕt ... ϕt−1 .

ηt ξˆt|t = where .

denotes element-by-element (1 1)(ξˆt|t−1 .

θ) = = Pξˆt|t p12 p22 P(St = 2|ϕt . θ) = = p12 P(St = 1|ϕt . Then " # P(St+1 = 1|ϕt . θ) + p22 P(St = 2|ϕt . θ) " #" # p11 p21 P(St = 1|ϕt . Matt Brigida. θ) " # p11 P(St = 1|ϕt . From here we use ξˆt+1|t to get ξˆt+1|t+1 and the filter proceeds. θ) and so ξˆt+1|t = Pξˆt|t is the optimal forecast.edu Markov Regime-Switching in Energy Markets .ηt ) multiplication. mbrigida@clarion. θ) + p21 P(St = 2|ϕt . θ) ξˆt+1|t = = P(St+1 = 2|ϕt . Dr.

The Log Likelihood The above filter provides the log likelihood by: T T log((1 1)(ξˆt|t−1 .

ϕt−1 .edu Markov Regime-Switching in Energy Markets . θ)) t=1 t=1 which can be maximized wrt θ = (βS1 βS2 σS21 σS22 p11 p22 )0 . ηt )) = X X L(θ) = log(f (yt |xt . mbrigida@clarion. Dr. Matt Brigida.

Estimating Regime Probability Once you have the estimated parameters (θ) you may use the data and parameters to estimate the probability of each regime at each t. Dr.edu Markov Regime-Switching in Energy Markets . Matt Brigida. You use the same filtering algorithm. mbrigida@clarion.

2 0 50 100 150 200 Month Filtered Probability of Being in State 3 0.Flowchart of the Markov Regime Switching Model Filtered Probability of Being in State 1 0.4 0.0 0 50 100 150 200 Month From this we get Regime Prob. Matt Brigida.6 0.4 0.edu Markov Regime-Switching in Energy Markets . the Likelihood ˆ P[St = j|ϕt .8 Probability 0. θ] Run through max θ L (θ) Hamilton Fil- ter again with θˆ θˆ and Stan- dard Errors Dr.0 Run through 0 50 100 150 200 Month Filtered Probability of Being in State 2 Hamilton Filter Probability 0.8 Probability 0. mbrigida@clarion.

mbrigida@clarion. and political such as NG deregulation) which cause distinct structural breaks in the cointegrating relationship. 3 revise and resubmit at Energy Economics Dr.edu Markov Regime-Switching in Energy Markets . These breaks may be modeled as switches between regimes. Matt Brigida. They are produced together and often sold in contracts which price NG as a fraction of crude oil. while others find structural breaks in the relative pricing relationship (prompting claims of ‘decoupling’). prior analyses have found conflicting results. They are possible substitutes. However. Some find evidence for cointegration. My paper3 claims there are events (technological such as fracking and CCCT.Markov-Switching with Constant Transition Probabilities: An Example There is are theoretical justification for cointegration between natural gas and crude oil prices.

2. 2...M .2 S2t + .M SMt β1.. + β0.2 S2t + . Markov-Switching PHH = β0..1 S1t + β0.. if St = m ⇒ Smt = 1..1 S1t + σ0.St = β0. M .St + β1. + σ0.. ∀j ∈ 1.St = σ0. et ∼ N 0..Markov-Switching with Constant Transition Probabilities: An Example NG and crude oil cointegrating equation: First-Order. . and Smt = 0 else Dr. mbrigida@clarion. M-Regime. Matt Brigida..St PWTI + et .St = β1. and pij = 1 j=1 β0..1 S1t + β1. .M SMt where for m ∈ 1.edu Markov Regime-Switching in Energy Markets . + β1.2 S2t + ..M SMt σ0. σS2t M X P(St = j|St−1 = i) = pij .

edu Markov Regime-Switching in Energy Markets . 4 see Hamilton (1998).Estimation Construction of the likelihood function for the above Markov Switching cointegrating equation was done using the Hamilton filter4 . E-step is simply the smoothed probabilities of the unobserved regime. P(St = j|ϕT ). Matt Brigida. mbrigida@clarion. Dr. Closed-form solutions for parameters means no optimization required in M-step. Alternativelly. This method is robust with respect to the initial starting values of the model parameters. maximization can be done using the EM algorithm. Minimization of the negative log-likelihood was done using the optim function in the R.

Matt Brigida. nrow=(length(lnoil)).theta[4] alpha5 <.ncol=2) xi. 1 / (1 + exp(-theta[8])) dist.2*length(lnoil)) xi.(1/(alpha6*sqrt(2*pi)))*exp((-(lnng-alpha2-alpha4*lnoil)ˆ2)/(2*alpha6ˆ2)) dist <. nrow=2. p22).matrix(c(p11.theta[1] alpha2 <. dist.b <.edu Markov Regime-Switching in Energy Markets .R Code Log-Likelihood Function lik <. 1.p22.2 <.2 <.rep(0.v <.a <.theta[6] p11 <. ncol=2) xi. lnoil.c(1.theta[5] alpha6 <.0 dist. length(lnoil)) Dr.2*length(lnoil)) xi.rep(0.b <.matrix(xi.theta[2] alpha3 <. lnng){ alpha1 <.lik <.1) P <.0 dist. nrow=(length(lnoil)).1 <.a.2) o.(1/(alpha5*sqrt(2*pi)))*exp((-(lnng-alpha1-alpha3*lnoil)ˆ2)/(2*alpha5ˆ2)) dist.theta[3] alpha4 <.matrix(xi.a.function(theta.1 <. mbrigida@clarion. 1-p11.a <.cbind(dist.1.ncol=2) model. 1 / (1 + exp(-theta[7])) p22 <.rep(0.

optim$par/se pval <.lik.v%*%(xi.lik[2:length(model.R Code Log-Likelihood Function: Continued xi.5) max.lik.]) } logl <.lik)])) return(-logl) } Minimization: optim theta.])) model. Matt Brigida.])) ## Here is the Hamilton filter for (i in 1:(length(lnoil)-1)){ xi.b[i+1.(xi.p22)*dist[1.sum(log(model.optim$hessian) se <. hessian=T) OI <.1.lik.2.a[i.optim <.01.sqrt(diag(OI)) t <. .5.])/(o.05.solve(max. nrow(data)-2)) Dr.a[i+1. . lnoil=lnoil.]*dist[i+1.start <.start.v%*%(c(p11.optim(theta. . .b[i+1.edu Markov Regime-Switching in Energy Markets .4. .2*(1-pt(abs(t).lik[i+1] <.b[i+1.a[1.])/(o.o.c(-. . mbrigida@clarion.] <.P%*%xi.]*dist[i+1. .]*dist[i+1.2. lik.max. lnng=lnng.] <.p22)*dist[1.] <.] xi.v%*%(xi.b[i+1.(c(p11.

optim$par[8])))) ## [.a.hat[i+1.hat[i+1.])) model.hat <.lik.hat[i+1] <.] <.hat%*%xi.2].o.c(( 1 / (1 + exp(-max. Estimating Regime Probabilities alpha.] for (i in 1:(length(lnoil)-1)){ xi. max.hat[i+1.lik.]*dist.optim$par[5].b.hat[i+1.hat <.v%*%(xi.]*dist.more code similar to above.] xi..hat[i+1.P.hat[i+1.]*dist. we rerun the filter with these estimates to get filtered regime probabilities.optim$par[3].v%*%(xi.b.lik..] <.]) } plot(xi.optim$par[6]) p. type=’l’.optim$par[1].c(max.optim$par[2]. mbrigida@clarion.Getting regime probabilities Once we have found maximum likelihood estimates of the parameters..hat[. max.lik.edu Markov Regime-Switching in Energy Markets .hat[i+1. ylab=’Probability’.lik. ( 1 / (1 + exp(-max.optim$par[4].lik.b.lik.b.a.0. Matt Brigida. max.hat[i+1..lik.optim$par[7]))). max.a.(xi. max. xlab=’Month’. main=’Filtered Probability of Being in Regime 2’) Dr.hat[i.])/(o.lik.

shinyapps.edu Markov Regime-Switching in Energy Markets .io/MSCP Code for app (GitHub): ‘Matt-Brigida/R-Finance-2015-MSCP’ Dr. Matt Brigida.Online app and code Shinyapp: https://mattbrigida. mbrigida@clarion.

Regime-Weighted Residuals Given estimated model parameters and transition probabilities. Note this also affords the expected duration of each regime: P∞ 1 E(Dm ) = j=1 j(P[Dm = j]) = 1−pmm 5 as opposed to smoothed probabilities P (St = i|ϕT ) Dr.edu Markov Regime-Switching in Energy Markets . I calculate the filtered5 regime probability P (St = i|ϕt−1 ) where ϕt−1 denotes the information set at time t − 1. Matt Brigida. mbrigida@clarion.

edu Markov Regime-Switching in Energy Markets .36 AIC 0. and *** denote significance at the 10%. Residuals in the two-state model are weighted by the filtered state probability.01)*** Dr.0287 0.9168 -4.6910 -0. Matt Brigida.062 -46.1537 0.2889 0.3949 (<1e-10)*** (<1e-10)*** (1. 5%.6109) (0.2017 0.2068) ?1 0.4297 Fuller Test (0. One-State Model Two-State Model State 1 1 2 ?0 -0.59 -8.5434) (<0.4e-8)*** ?2 0.2634 (<1e-10)*** (<1e-10)*** (<1e-10)*** ?(?? = 1|??−1 = 1) 0.7518) (0. and 1% levels respectively. **.2419 (0. The alternative hypothesis in the augmented Dickey-Fuller and Phillips-Perron tests is to conclude the residual series is stationary.Results: 2 regimes & monthly prices Table 1. p-values are below the coefficient in parentheses.5608 0.9821 -ln(Likelihood) 108.9919 -0.3351 (5e-6)*** (0. mbrigida@clarion. *. Results of Estimating Cointegrating Equation Regressions (equations 1-5) with Monthly Prices There are 225 monthly observations for natural gas and oil prices.01)*** Phillips-Perron Test -10. The one-state model has 222 degrees- of-freedom.9880 ?(?? = 2|??−1 = 2) 0. and the two-state model has 217.0032 Augmented Dickey. -1.

2116 0.01)*** Dr.2025 (<1e-10)*** (<1e-10)*** (<1e-10)*** ?(?? = 1|??−1 = 1) 0.3214 0. Residuals in the two-state model are weighted by the filtered state probability.2024 -110.1350 0. **.7543 (0. mbrigida@clarion. One-State Model Two-State Model State 1 1 2 ?0 -0.0043)*** ?1 0.0100)*** Phillips-Perron Test -14.2500 Fuller Test (0.1566 0. -2. p-values are below the coefficient in parentheses. Results of Estimating Cointegrating Equation Regressions (equations 1-5) with Weekly Prices There are 978 weekly observations for natural gas and oil prices. and 1% levels respectively.4074 (<1e-10)*** (<1e-10)*** (<1e-10)*** ?2 0.2806 (<1e-10)*** (0.4312) (0.9910 -ln(Likelihood) 481. Matt Brigida.0050)*** (0. The one-state model has 975 degrees-of- freedom.5591 0.9902 -0.2849) (<0.7862 -75.9938 ?(?? = 2|??−1 = 2) 0. The alternative hypothesis in the augmented Dickey-Fuller and Phillips-Perron tests is to conclude the residual series is stationary.Results: 2 regimes & weekly prices Table 2.1142 AIC 0.2086 Augmented Dickey.edu Markov Regime-Switching in Energy Markets .6867 -0.3475 -5. 5%. and *** denote significance at the 10%. *. and the two-state model has 970.

edu Markov Regime-Switching in Energy Markets . Monthly Natural Gas and Crude Oil Prices with the Probability of State 2 Natural Gas Oil 1 0 P(State=2) 1995 2000 2005 2010 Time Dr. mbrigida@clarion. Matt Brigida.

mbrigida@clarion. Matt Brigida. Weekly Natural Gas and Crude Oil Prices with the Probability of State 2 Natural Gas Oil 1 0 P(State=2) 1995 2000 2005 2010 Time Dr.edu Markov Regime-Switching in Energy Markets .

Matt Brigida.6 0.4 0. monthly prices Filtered Probability of Being in State 1 0.0 0 50 100 150 200 Month Filtered Probability of Being in State 2 Probability 0.4 0.2 0 50 100 150 200 Month Filtered Probability of Being in State 3 0.8 Probability 0.0 0 50 100 150 200 Dr.Regime Probabilities: Allowing 3 Regimes.8 Probability 0. mbrigida@clarion.edu Markov Regime-Switching in Energy Markets Month .

0 1995 2000 2005 2010 Time Filtered Probability of Being in State 2 0.0 1995 2000 2005 2010 Time Dr.edu Markov Regime-Switching in Energy Markets .4 0.8 Probability 0.0 1995 2000 2005 2010 Time Filtered Probability of Being in State 3 0.4 0. Matt Brigida.4 0.Regime Probabilities: Allowing 3 Regimes. mbrigida@clarion.8 Probability 0.8 Probability 0. weekly prices Filtered Probability of Being in State 1 0.

mbrigida@clarion. Matt Brigida.Time-Varying Transition Probabilities (TVTP) We may also wish to allow the transition probabilities to vary according to a set of explanatory variables. I’ll show weather and natural gas storage quantities affect the relative pricing of crude oil and natural gas. Dr. The probability of transitioning to an electricity price spike regime is likely dependent on reserve capacity and the weather.edu Markov Regime-Switching in Energy Markets .

St = β1.St + β1. σS2t ) exp φij. Dr. The cointegrating equation with first-order.edu Markov Regime-Switching in Energy Markets .1 P2 ∀i. two-regime. j ∈ 1.TVTP: NG and Oil Cointegrating Equation Let Xt−1 be a vector of variables which affect the likelihood of switches between regimes.0 + X0t−1 φij. 2 and j=1 pij =1 β0.St = β0.2 S2t β1.t = P(St = j|St−1 = i.1 S1t + β0. if St = m. then Smt = 1. et ∼ N (0.1 pij. mbrigida@clarion. and Smt = 0 otherwise.1 S1t + σ0.2 S2t where for m ∈ 1.St = σ0.0 + X0t−1 φij.2 S2t σ0. Matt Brigida. 1 + exp φij.1 S1t + β1. Xt−1 ) = .St PWTI + et . endogenous Markov switching parameters with time-varying transition probabilities may be written as: PHH = β0. 2.

Matt Brigida. Dr.TVTP Example The variables governing the transition probabilities are: the deviation of the number of heating degree days form the long term norm. mbrigida@clarion. the logged difference of natural gas working gas in storage from its 5-year average.edu Markov Regime-Switching in Energy Markets . An Indicator for Enron’s collpase.

b[i+1.v%*%(xi.1]+ (pnorm(-(g2+g3*VAR1+g4*VAR2)))[i]*xi.(xi.TVTP: Estimation Hamilton Filter: TVTP xi.] <. Matt Brigida.] <.a[i.a[i.matrix(c((pnorm(-(g1+g3*VAR1+g4*VAR2))[i]*xi.(initial.]) } } We can also maximize the likelihood using the EM algorithm (see Deibold.regime.]*dist[j.prob*dist[1. ncol=1) for (j in 2:length(lnoil)){ xi.a[i.a[j. Dr.2])).]*dist[j. ((1-pnorm(-(g1+g3*VAR1+g4*VAR2)))[i]*xi.] <.])/(o.])) model.b[j.1]+ (1-pnorm(-(g2+g3*VAR1+g4*VAR2)))[i]*xi. nrow=2.v%*%(initial.]*dist[j.v%*%(xi.b[j.])/(o.edu Markov Regime-Switching in Energy Markets . Lee.o. and Weinbach (1994)).])) for (i in 1:(length(lnoil)-1)){ xi.prob*dist[1.2]). mbrigida@clarion.b[j.regime.a[i.a[1.lik[j] <.

Matt Brigida.4 0.0 0.2 0. mbrigida@clarion.6 Probability 0.8 0.TVTP Example: Filtered Regime Probabilities Filtered Probability of Being in State 2 1.0 2000 2005 2010 Dr.edu Markov Regime-Switching in Energy Markets Time .

06572 0. mbrigida@clarion.46665 (8. Cointegrating Equation S1 S2 β0 -0.edu Markov Regime-Switching in Energy Markets .320e-03)*** Neg Log Likelihood: -40.07525 (6.St PWTI + eSt where St ∈ {1. 2} and the transition probabilities are time-varying functions of the deviation of the amount of working gas in storage from its 5-year average (STOR) and the deviation of the cumulative number of monthly HDD from its long-term norm (HDD DEV).TVTP Example: Parameter Estimates Table: Parameter estimates of PHH = β0.45712 (3.34383 0. P-values are below the coefficients in parentheses.752e-01) β1 0.000e+00)*** (0.St + β1.656e-02)* HDD DEV 0.02312 (2. Matt Brigida.529e-11)*** σ 0.53150 (8.18495 (0.000e+00)*** Transition Probabilities intercept -0.452e-10)*** NG STOR 1.37859 Dr.969e-01) (7.322e-13)*** (1.758e-04)*** (7.31294 0.90138 -0.

St PWTI + eSt where St ∈ {1.5313 (0.0000)*** (0.3736 (0. mbrigida@clarion.1813 0.0000)*** Transition Probabilities intercept -1.0000)*** σ 0.0000)*** (0.3716 0.3881 (3.7485 (0. Cointegrating Equation S1 S2 β0 -0.6087 Dr. 2} and the transition probabilities are time-varying functions of the deviation of the amount of working gas in storage from its 5-year average (STOR).1027) ENRN 1.1945 (0.513e-05)*** β1 0. Matt Brigida.St + β1.4220 (0. the deviation of the cumulative number of monthly HDD from its long-term norm (HDD DEV).0000)*** (0.0000)*** HDD DEV 0.498e-08)*** (8.0000)*** NG STOR 0.6204 -1.2929 0.0317 (0. P-values are below the coefficients in parentheses.0000)*** Neg Log Likelihood: -12.TVTP Example: Parameter Estimates with ENRN Indicator Table: Parameter estimates of PHH = β0. and an indicator for the 6 months after the collapse of Enron (ENRN).edu Markov Regime-Switching in Energy Markets .

Cai (2006) Janczura. Weron (2010) among others Dr. Some relevant research is: Mount.edu Markov Regime-Switching in Energy Markets . mbrigida@clarion. Ning. Matt Brigida.TVTP: Electricity Price Spikes This methodology has recently been found useful for modeling power prices and predicting price spikes.

Dr. Matt Brigida.edu Markov Regime-Switching in Energy Markets .a person’s uncertainty about the future arises not simply because of future random terms but also because of uncertainty about current parameter values and of the model’s ability to link the present to the future. mbrigida@clarion.Incorporating Parameter Uncertainty We may wish to allow for parameter uncertainty within the model: .. 208] This can be done by writing the model in state-space form6 and applying the Kalman filter. 6 For an introduction to state-space models see Harvey (1989). pg.. [Harrison and Stevens (1976).

The model is formulated in terms of unobservable components. The varying state vector is the set of time-varying parameters. In dealing with parameter uncertainty we first build a structural model of the time series. Dr.Regime Uncertainty versus Parameter Uncertainty In the Markov regime-switching models the regime is the unobservable variable. Matt Brigida. We make inference about the state using the Kalman filter.edu Markov Regime-Switching in Energy Markets . 7 The term ‘state’ here is different from ‘state’ when used in a regime-switching model. where the unobservable component is the state7 vector which evolves according to the state transition equation. We then write the model in state space form (measurement and state transition equations). which nonetheless have a direct interpretation. mbrigida@clarion.

Testing for Parameter Stability The Brown. Durbin. Test statistic follows an F distribution. Matt Brigida.edu Markov Regime-Switching in Energy Markets . Sample period is divided into n non-overlapping intervals. Dr. mbrigida@clarion. and Evans (1975) ‘homogeneity test’. Null hypothesis: coefficients are equal at all points in time. Ratio of ’between groups over within groups’ mean sum of squares is the test statistic.

rep(NA. mbrigida@clarion..test)[1]-(k)*p)/((k)*p-(k)))*((rss.vector(data$hdd.test[.2:4])%*%t(data.test[.sam-sum(rss))/sum(rss)) ## under Ho distrubuted as F(kp-k.full.spl[.i] <.((dim(data.spl <.i])%*%t(data.test.p)) for (i in 1:p){ data.Code ## Brown Durban Evans (1975) ’Homogeneity test’ ---- n <.vector(data$cdd.t(data.spl[.stat <.test.test[.test)[2].1])%*%data.T-kp) ## p-value 1-pf(test.yr).1.test.i] %*%solve(t(data.1] ## test statistic k <.cbind(as.test.vector(data$ng.test[.i])%*%data.test[.as.dim=c(n.dev).dim(data.1]-t(data. Matt Brigida.2:4]%*% solve(t(data.1.test.vector(data$stor.1.spl[.floor(dim(data.2:4])%*%data.i])%*%data.dim(data. as.spl[.sam <.i])%*% data.i] } ## get the full sample rss rss.edu Markov Regime-Switching in Energy Markets .test[(1+(i-1)*n):(i*n).spl[.]} ## get the residual sum of sqaures for each interval rss <.as.test[.array(NA.t(data.test.2:4])%*%data.spl[.ret).test <.test)[2]-1 test.test. dim(data.p) for (i in 1:p){ rss[i] <.stat.test.spl[.1.data.test)[1]-k*p) Dr.2:4.test[.full.2:4.spl[.test)[1]/n) data.1])%*%data.50 data.i]-t(data.test. k*p-k.2.2:4.i])%*%data.spl[.test.dev)) p <.test[.2:4.

mbrigida@clarion. creating a likelihood via prediction error decomposition was introduced. the model parameters may be estimated using prediction error decomposition. Because of this.Kalman Filter Example The Kalman Filter is often used in finance to estimate time-varying β coefficient in a CAPM type equation8 . Later. 8 The Kalman filter was created by engineers working on control systems. in the first applications of the Kalman filter the parameters were assumed to be known (often by the physics of the situation).edu Markov Regime-Switching in Energy Markets . Early applications of the filter were to such things as tracking a missile with a time-series of noisy observations of its location. Dr. Through the Kalman filter. Matt Brigida. There are many implementation of the Kalman filter in R and other languages (though you must take care to note what parameters a particular implementation will estimate).

edu Markov Regime-Switching in Energy Markets . et ∼ i. rs.i.t + et . νt ∼ i. I have set α = 0.d. Q) You can easily allow α to vary with time also.t = α + βt rm.CAPM: Time-Varying β Below is an implementation of the CAPM with a time-varying β coefficient.i.N (0. R) βt+1 = µ + F βt + νt . Below however.N (0.d. mbrigida@clarion. Dr. Matt Brigida.

edu Markov Regime-Switching in Energy Markets .market[i]*Ptt_1[i]*market[i]+Rˆ2 ## Updating ---- beta_tt[i] <.(summary(lm(stock˜market))$coef[4])ˆ2 for(i in 2:length(market)){ ## Prediction ---- beta_tt_1[i] <.theta[4] beta_tt <.rep(0.Kalman Filter Example Kalman Filtered Beta Code lik <. length(market)) Ptt_1 <.rep(0.rm=T) return(-logl) } Dr. stock){ ## R and Q transformed below (squared) -.theta[2] F <.so they are standard deviations R <.5*sum(eta*eta*(1/f).rep(0.beta_tt_1[i]-Ptt_1[i]*market[i]*(1/f[i])*eta[i] Ptt[i] <.stock[i]-market[i]*beta_tt_1[i] f[i] <.Ptt_1[i]-Ptt_1[i]*market[i]*(1/f[i])*market[i]*Ptt_1[i] } logl <.rep(0.mu + F*beta_tt[i-1] Ptt_1[i] <.5*sum(log((((2*pi)ˆlength(market))*abs(f))[-1]))-.F*Ptt[i-1]*F+Qˆ2 eta[i] <. length(market)) Ptt <.theta[1] Q <.-0.na.lm(stock˜market)$coef[2] Ptt[1] <.rep(0.rep(0. length(market)) f <.theta[3] mu <. length(market)) beta_tt_1 <.function(theta. length(market)) eta <. Matt Brigida. length(market)) ## start at unconditional estimate beta_tt[1] <. mbrigida@clarion. market.

rep(0.hat*Ptt[i-1]*F.lik.lik.beta_tt_1[i]-Ptt_1[i]*market[i]*(1/f[i])*eta[i] Ptt[i] <. Matt Brigida.max.mu.optim(theta. length(market)) eta <. length(market)) Ptt_1 <.hat <.01. hessian=T) ## Run though filter to get tv coefficients ---- R.lik.Ptt_1[i]-Ptt_1[i]*market[i]*(1/f[i])*market[i]*Ptt_1[i] } logl <.optim$par[1] Q.hat + F.market[i]*Ptt_1[i]*market[i]+R.F.optim$par[4] beta_tt <.max. stock=stock. length(market)) beta_tt_1 <.01. lik.max.lm(stock˜market)$coef[2] Ptt[1] <.5*sum(log((((2*pi)ˆlength(market))*abs(f))[-1]))-.lik.start <.max.5*sum(eta*eta*(1/f).Kalman Filter Example Kalman Filtered Beta Code Continued theta.optim <.rm=T) Dr. length(market)) f <.start.hat+Q.rep(0. market=market. 0.rep(0. 0.hat <.1. mbrigida@clarion. length(market)) Ptt <.1) max.hatˆ2 eta[i] <.lik.hat <.-0.hatˆ2 ## Updating ---- beta_tt[i] <.hat*beta_tt[i-1] Ptt_1[i] <. length(market)) beta_tt[1] <.rep(0.rep(0.na.0.c(0.rep(0.optim$par[2] F.(summary(lm(stock˜market))$coef[4])ˆ2 for(i in 2:length(market)){ ## Prediction ---- beta_tt_1[i] <.edu Markov Regime-Switching in Energy Markets .optim$par[3] mu.hat <.stock[i]-market[i]*beta_tt_1[i] f[i] <.

Time-varying and Unconditional β: BP BP Time−varying and Unconditional Betas (market model) Kalman Filtered Beta Unconditional Beta 4 3 Beta 2 1 0 2000 2005 2010 2015 Dr. Matt Brigida.edu Markov Regime-Switching in Energy Markets Time . mbrigida@clarion.

4 0.6 0.edu Markov Regime-Switching in Energy Markets Time .5 Beta 0.2 2000 2005 2010 Dr. Matt Brigida.Time-varying β in NG and Oil Cointegrating Equation Beta from Natural Gas and Crude Oil Cointegrating Equation 0.3 0. mbrigida@clarion.

edu Markov Regime-Switching in Energy Markets . here: https://mattbrigida. and see a time series of the Kalman filtered beta coefficient. mbrigida@clarion.io/kalman_filtered_beta Note the app is too slow at this point—I hope to speed it up with Rcpp.shinyapps.Shiny App and Code I have put a shiny app where you can input a stock’s ticker and time interval. The code is on GitHub here: ‘Matt-Brigida/R-Finance-2015-Kalman_beta’ Dr. Matt Brigida.

At this point you can combine the Hamilton filter with the Kalman Filter (Kim (1994)). This recognizes the uncertainty in current and future parameter values.edu Markov Regime-Switching in Energy Markets . R) et ∼ N (0. mbrigida@clarion.Regime-Switching in State-Space Models It is straight-forward to include time-varying parameters in a regime-switching model by putting it in state-space form. σS2t ) Dr. For example: Does the sensitivity of electricity prices to outages change in an uncertain fashion? ∆Pt = Xt−1 βt + et βt = βt−1 + ηt η ∼ N (0. Matt Brigida.

2. then Smt = 1.2 S2t β1. Matt Brigida.t. mbrigida@clarion. we can write the equation as: PHH = β0.t−1.St PWTI + et .t.St−1 + GSt vST 2 X P(St = j|St−1 = i) = pij .t. Dr.1 S1t + β0. 2. and Smt = 0 otherwise.edu Markov Regime-Switching in Energy Markets .St = β1.t. σS2t ) β1. et ∼ N (0.2 S2t σ0.St = µSt + FSt β1.2 S2t where for m ∈ 1.St = β0. if St = m. ∀j ∈ 1.State Space Model with Markov Switching: NG & Oil To incorporate parameter uncertainty into our two-state Markov regime-switching model of the natural gas and crude oil cointegrating equation.t. and pij = 1 j=1 β0.1 S1t + β1.St = σ0.St + β1.1 S1t + σ0.

edu Markov Regime-Switching in Energy Markets .Overview of Kim (1994) Algorithm Initial Parameters L (θ) = PT Kalman Filter t=1 ln (f (yt |ϕt−1 )) Smoothed Regime t−1=t Hamilton Filter Probabilities Smoothed Time Approximations Varying Coefficients Dr. Matt Brigida. mbrigida@clarion.

Overview of Kim (1994) Algorithm We then take the estimated parameters θˆ and use them in the smoothing algorithm. Matt Brigida. The smoothing algorithm will give us: Smoothed regime probabilities: ∀t. mbrigida@clarion. j.edu Markov Regime-Switching in Energy Markets . P[St = j|ϕT ] Smoothed estimates of the time-varying coefficients: βt|T Dr.

45 0. mbrigida@clarion.State Space Model with Markov Switching: NG & Oil 0.60 Smoothed Beta 0.8 Prob State 2 0.edu Markov Regime-Switching in Energy Markets Time .4 0.30 1995 2000 2005 2010 Time 0.0 1995 2000 2005 2010 Dr. Matt Brigida.

Matt Brigida.com/Matt-Brigida Twitter: @mattbrigida Dr.edu Markov Regime-Switching in Energy Markets .com Github: github.Contact Info work: mbrigida@clarion.edu website: http://complete-markets. mbrigida@clarion.

Weinbach (1994). In ‘Nonstationary Time Series Analysis and Cointegration’. Filardo. Diebold. Dr. Techniques for testing the constancy of regression relationships over time.E. mbrigida@clarion. Evans (1975). Regime switching with time varying transition probabilities. F. A. (1998). Matt Brigida. M.W.References Brown. Residual-based tests for cointegration in models with regime shifts. Durbin. J. 99–126.. Choosing information variables for transition probabilities in a time-varying transition probability Markov switching model. R. and B. Journal of Econometrics 70. and G. Lee. Oxford University press.. Federal Reserve Bank of Kansas City research paper.X. A. J. 149–192. Journal of the Royal Statistical Society B37.edu Markov Regime-Switching in Energy Markets .C. Hansen (1996). L. Gregory. and J.J.H.

F. Series B. 205–247. J.D. Dynamic linear models with Markov-switching. Forecasting structural time series models and the Kalman filter. C. Econometrica 57. Matt Brigida. (1989). (1989). A new approach to the economic analysis of nonstationary time series and the business cycle.C. and C. Stevens (1976). A. (1994). Journal of Econometrics 60. Journal of the Royal Statistical Society. Cambridge: Cambridge University Press. Dr.References Hamilton. Harrison. 357-384. mbrigida@clarion. Bayesian forecasting. Harvey. Kim.J. 1-22. P.J.edu Markov Regime-Switching in Energy Markets . 38.

- Internship Report Format Etc Feb20 2011Uploaded bysunny467318
- State FeedbackUploaded byvamsi253
- Sol9.pdfUploaded byMimo Molio
- Non-Linear Moving Target Tracking: A Particle Filter ApproachUploaded byInternational Journal of Computer and Communication System Engineering
- National Science Foundation: chap1Uploaded byNSF
- ThesisUploaded byGuruxyz
- Q ParameterizationUploaded byTRAN
- 313Uploaded bysaifuliu
- Control using State Feedback and State AugmentationUploaded bydigiblood
- 978-3-642-30976-2_37Uploaded byCristhian CR
- Predictive Analysis on Electric-power Supply and Demand in ChinaUploaded byPatricio Leonardo
- Multivariable Control-Oriented Modeling of a DirectUploaded byEva Viskadouraki
- S15-2010-Adaptive Kalman Filtering in Networked Systems With Random Sensor Delays, Multiple Packet Dropouts and Missing MeasurementsUploaded byDalix Pavlova Sanchez Conde
- Clasede ControlUploaded byAlan
- Control Tutorials for MATLAB and Simulink - Cruise Control_ System ModelingUploaded bydialauchenna
- w7103Uploaded byAmbaejo96
- ExercisesUploaded byJimmy Granja
- What is a demand forecastUploaded byTamaghna Mukherjee
- Page 2008Uploaded byGraciele Gregorio
- Traffic Project DetailsUploaded byShekhar Imvu
- Robust Scheduler Fuzzy Controller.pdfUploaded byMona Valikhani
- A Survey on Approaches for Object TrackingUploaded byjournal
- A Kalman Filter Based Transient State Estimation Method Applicable to Whole or Specific Region of Power Systems Having Known and Unknow LoadsUploaded byJesus Ortiz L
- Deformation in indonesia.docxUploaded byAnung 'Hidayat Panuntun'
- 3.Mathematical ModellingUploaded byHasif Mustapa
- 01 IntroductionUploaded bymbede
- CMA Additive and MultiplicativeUploaded byShweta Niru
- ch16MarkovAnalysisUploaded byRia Rahma Puspita
- Demand ForecastingUploaded bysanowareceku
- Filetype PDF Nonstationary Inventory Model With Several Demand ClassesUploaded byNathan