This action might not be possible to undo. Are you sure you want to continue?

Welcome to Scribd! Start your free trial and access books, documents and more.Find out more

**energy markets with MCMC
**

method

by

Jeroen De Maeseneire

Advisor

Professor Christiane Lemieux

A research paper

presented to the University of Waterloo

in partial fulﬁllment of the

requirements for the degree of

Master of Mathematics

in

Computational Mathematics

Waterloo, Ontario, Canada, 2010

I hereby declare that I am the sole author of this paper. This is a true copy of the

paper, including any required ﬁnal revisions, as accepted by my examiners.

I understand that my paper may be made electronically available to the public.

ii

Abstract

In this essay, modeling of natural gas price forward curves is discussed. A

two-factor, regime switching model is proposed to model forward price dynamics.

The model is a Markov Switching model: the parameters, found in the respective

volatility functions take diﬀerent values for diﬀerent states of the world. Further,

the state transitions are driven by a ﬁnite state Markov Chain. A Markov Chain

Monte Carlo (MCMC) technique is used for estimation of the parameter set and the

transition probability matrix. A study is performed for a number of 2 states using

data from NBP. Compared to a previous study it is found that, while the volatility

and attenuation parameters are similar, the Markov Chain stays in regime 2 more

often. That is, over the span of the data period, more time is spent in a high-

volatility regime. Although, for the better part of the time horizon the Markov

Chain still settles in regime 1. A higher volatile environment for natural gas could

be explained by the global ﬁnancial crisis which unfolded during the period of

observation.

iii

Contents

List of Tables vi

List of Figures vii

1 Introduction 1

1.1 Stylized facts of energy forward price dynamics . . . . . . . . . . . 2

1.2 Literature review . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

2 Forward price curve model 13

2.1 Multi-factor single-commodity model . . . . . . . . . . . . . . . . . 13

2.2 Spot - forward price relationship . . . . . . . . . . . . . . . . . . . . 18

2.3 Seasonality adjustment . . . . . . . . . . . . . . . . . . . . . . . . . 18

2.4 Multi-factor multi-commodity model . . . . . . . . . . . . . . . . . 19

2.5 Two-factor regime switching forward price curve model . . . . . . . 20

3 Estimation 22

3.1 Data transformation . . . . . . . . . . . . . . . . . . . . . . . . . . 22

3.2 Bayesian estimation for a Markov switching model . . . . . . . . . . 23

3.3 Prior distributions . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

3.4 Gibbs sampler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

3.4.1 Full conditional posterior distributions . . . . . . . . . . . . 25

3.4.2 Sample the transition matrix . . . . . . . . . . . . . . . . . . 26

3.4.3 Sample the model parameters . . . . . . . . . . . . . . . . . 27

3.4.4 Markov Chain state simulation . . . . . . . . . . . . . . . . 29

4 Implementation 32

4.1 Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

4.2 Choosing the prior . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

4.3 Running the Gibbs sampler . . . . . . . . . . . . . . . . . . . . . . 33

4.3.1 One-factor model . . . . . . . . . . . . . . . . . . . . . . . . 34

4.3.2 Two-factor model . . . . . . . . . . . . . . . . . . . . . . . . 35

iv

4.4 Numerical Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36

4.4.1 One-factor model . . . . . . . . . . . . . . . . . . . . . . . . 36

4.4.2 Two-factor model . . . . . . . . . . . . . . . . . . . . . . . . 38

4.4.3 Historical NBP forward data . . . . . . . . . . . . . . . . . . 45

5 Conclusion 47

A nbp 1fac.m 48

B mcmc.m 50

C nbp 2fac.m 54

D mcmc.m 56

E mcmc.m 60

Bibliography 65

v

List of Tables

vi

List of Figures

1.1 Forward price curves from Oct-2007 to Mar-09, F(t, T) . . . . . . . 5

1.2 Log diﬀerences of forward prices y

T

. . . . . . . . . . . . . . . . . . 6

1.3 Diﬀerent forward price curves, F(t, T) . . . . . . . . . . . . . . . . 8

2.1 Annualized covariance surface for NBP data F(t, T) . . . . . . . . . 16

2.2 First three volatility functions for NBP data F(t, T) . . . . . . . . 17

4.1 Generated forward price dynamics, y

T

. . . . . . . . . . . . . . . . 34

4.2 Path of parameter estimates for σ

1j

and α

1j

, (j = 1, 2) . . . . . . . 37

4.3 Generated forward price dynamics, y

T

. . . . . . . . . . . . . . . . 38

4.4 Path of parameter estimates for σ

ij

, (i, j = 1, 2) . . . . . . . . . . . 40

4.5 Path of parameter estimates for α

ij

, (i, j = 1, 2) . . . . . . . . . . . 41

4.6 Path of parameter estimates for σ

ij

, (i, j = 1, 2) . . . . . . . . . . . 43

4.7 Path of parameter estimates for α

ij

, (i, j = 1, 2) . . . . . . . . . . . 44

vii

Chapter 1

Introduction

This paper considers the problem of modeling and estimating the forward price

curve in natural gas markets. A common modeling framework is provided that

is consistent not only with the forward curve prices observed in the market but

also the volatilities and correlations of forward price returns. The model discussed

and implemented is a two-factor regime switching model suggested by Chiarella et

al. [4] where the parameters of the volatility functions are allowed to take diﬀerent

values in diﬀerent states of the world. The respective states are then governed by

a Markov Chain. The dynamics of the two volatility functions are thus driven by

shifts in the Markov Chain.

The paper is built as follows. First, in Chapter 1, the properties of energy

forward prices are discussed. Energy markets diﬀer from non-physical, ﬁnancial

markets. It is then important to incorporate those diﬀerences in the model to

better explain the forward price dynamics of energy assets. Also, a brief overview

of theoretical and practical work by other authors is provided. Next, in Chapter 2

the general multi-factor multi-commodity model by Breslin et al. [2] is introduced

after which a two-factor regime switching model for the natural gas forward price

curve is described. The model was initially proposed by Chiarella et al. [4].

The parameter estimation procedure is then explained in Chapter 3. A Bayesian

approach is taken by means of a Markov Chain Monte Carlo (MCMC) method

provided by Fr¨ uhwirth-Schnatter [14] and Hahn et al. [18]. The algorithms imple-

mented are extensively discussed and code of the respective routines is supplied.

In a following chapter, Chapter 4, a number of numerical examples and calibration

results from simulated data are considered. Subsequently, the estimation proce-

dure is applied to real market data. Here, the analysis by Chiarella et al. [4] is

replicated with updated natural gas forward price data. Finally, in Chapter 5

conclusions are drawn and suggestions for further research are discussed.

1

1.1 Stylized facts of energy forward price dynamics

Energy markets, to which the market for natural gas belongs, diﬀer from non-

physical markets such as the markets of interest rates and equities. Most of these

diﬀerences can be traced back to supply and demand fundamentals, dynamics

of production, consumption and storage. All drivers which are not found in the

traditional markets. A comprehensive overview of the various supply and demand

drivers of energy markets and their impacts on the prices and volatilities of the

respective markets can be found in Pilipovic [25]. Below, the main features of

energy forward price dynamics are presented. These market characteristics should

be captured to model eﬃciently the evolution of natural gas forward curves.

• Seasonality

One of the major fundamental price drivers in energy markets is weather.

On the demand side, there are considerable seasonality eﬀects of residential

users. Natural gas is consumed mostly during the winter. Therefore, one

expects natural gas prices to peak during winter and drop to lows in summer

period. Further, the magnitude of these peaks and troughs, or the degree

of seasonality, will vary according to the region. The heating demand in

the state of Massachusetts is expected to surpass the heating demand for

Florida. These seasonality eﬀects are recurring and, hence, incorporated in

observed forward prices (Pilipovic [25]).

• Mean reversion

Mean reversion is the process of a market returning to its equilibrium price

level. This is witnessed in most ﬁnancial and physical markets where the

equilibrium level, called mean level, could be a return on equity, a commodity

price or a historical interest rate. In ﬁnancial markets the actual rate of mean

reversion is rather weak and tied to economic cycles. On the other hand,

in energy markets mean reversion is much stronger and related to various,

diﬀerent drivers. In the case of energy commodities mean-reversion depends

on how fast the market supply side responds to certain events. Or, also, how

fast events go away (Pilipovic [25]).

Events that produce supply-demand imbalances could be wars, hurricanes or

other headline-grabbing events. In 2005, for example, the hurricanes Katrina

and Rita damaged a number of natural gas processing facilities on the US

Gulf Coast. The loss has delayed the recovery of natural gas production

in the area. As a result, price spikes occurred in the spot and short-term

forward markets, but longer-term contracts did not move dramatically. The

2

mean reversion, as revealed by the forward prices, thus depended on how

fast the production side could restore the supply imbalance (Pilipovic [25]).

• High volatility

Production and storage are two supply drivers which are nonexistent in ﬁnan-

cial markets. Expectations of market production and costs in the long run

will be expressed in the levels and yields of long-term forward prices. Like-

wise, overcapacity in natural gas markets will result in distressed prices and

its impact will depend on how long the overcapacity is expected to last. This

so-called storage limitation problem is causing day-to-day volatility which is

high compared to ﬁnancial markets. Especially spot and short forwards ex-

hibit high levels of volatility. For example, when there is no natural gas to

go around, prices will easily reach very elevated levels (Pilipovic [25]).

• Decreasing term structure of forward curve volatility Storage limita-

tion is thus a major volatility driver. Although spot prices show extremely

high volatility, the volatilities of forward prices decrease signiﬁcantly with

increasing maturities. It can be expected that in the long run supply and

demand will be balanced and, hence, long-term forward prices reveal a rather

stable equilibrium price level. As a result, the short- and long-term portions

of the energy forward price curves tend to be driven by diﬀerent market

factors with usually very little or no relationship (Pilipovic [25]).

The latter two characteristics demonstrate that the issue of storage causes

energy prices to display a split personality. Where short-term forward prices are the

result of energy in storage, and long-term forward prices reﬂect behavior of future

potential energy. So while energy markets share some properties with traditional

ﬁnancial markets, they have unique and challenging workings. And these should be

taken into account when modeling natural gas forward dynamics (Pilipovic [25]).

The natural gas prices modeled are forward prices for the National Balanc-

ing Point (NBP), which is the British virtual trading location operated by TSO

National Grid, covering all entry and exit points in mainland Britain. It is the

most liquid gas trading point in Europe. Natural gas at NBP trades on a forward

month, forward quarter, forward season or year forward basis and prices are ex-

pressed in pence (GBp) per therm. For parameter estimation of the chosen model,

daily observations for the forward prices were obtained with maturities T ranging

from July 2009 to September 2012. The observations span over a year with prices

at times t from 23/10/2007 to 12/03/2009. This data is represented by F(t, T).

Further, in order to obtain the forward dynamics y

t,T

for every maturity T, the log

diﬀerence transform is applied to the original data F(t, T). Throughout the essay,

3

the notation y

T

is used to represent the forward dynamics y

t,T

for each maturity

T along all points in time t.

4

Figures 1.1 and 1.2 below show the behavior of F(t, T) and y

T

respectively.

Figure 1.1: Forward price curves from Oct-2007 to Mar-09, F(t, T)

5

Figure 1.2: Log diﬀerences of forward prices y

T

6

At every point in time t a seasonal pattern can be distinguished with higher

prices for forward deliveries in Winter compared to deliveries in Summer. Also, the

forward curves spike during a certain period, after which things turn back to normal

and a more stable price pattern emerges. It is therefore easy to see that a regime

switching model could be suited to approximate this behavior. Finally, natural gas

for delivery further out in time is usually more expensive than delivery in the near

time. The diﬀerence is explained by the carry, that is expenses incurred for storage

and ﬁnancing when the commodity is bought at the spot price and delivered at a

later point in time. Such an increasing price curve is called contango. Although

diﬀerent shapes could occur such as a decreasing path for the forward curve which

is called backwardation. Or any combination of contango and backwardation could

occur along the forward price curve.

7

Figure 1.3 depicts some of the forward price curves observed.

Figure 1.3: Diﬀerent forward price curves, F(t, T)

8

1.2 Literature review

In order to model the gas forward curve, a regime switching model is proposed.

It is considered a useful approach because many economic time series are known

to exhibit dramatic breaks in their behavior. Therefore, when modeling, diﬀerent

behavior is assumed in one subsample or regime to another. Since the prevailing

regime is not directly observable, a process that governs the transition has to be

deﬁned. For example, a process where the current state depends only on the state

before, is called a Markov process. A regime switching model where the transitions

are governed by a Markov process is called a Markov Switching model.

There has been an enormous amount of theoretical and practical work on regime

switching models. In a seminal paper, Goldfeld and Quandt [17] propose a regres-

sion system of demand and supply functions thought to be switching between the

two equations or regimes. An unobserved Markov process is assumed to govern the

regime. This set-up is applied to a model for a housing market in disequilibrium.

Two regimes are distinguished: if there is excess demand, the observed point lies

on the supply function and if there is an excess demand, it lies on the demand

function. Hamilton [19] and [20] extends the approach to asset prices.

In Hamilton [19] the approach by Goldfeld and Quandt [17] is used to de-

scribe exchange rate dynamics. Episodes of dollar appreciation relative to other

currencies are followed by episodes of dollar depreciation. Therefore, in a regime

switching model the dollar rate is allowed to switch, with a certain probability, be-

tween an appreciation and depreciation regime. Changes in asset prices are driven

by speciﬁc identiﬁable events. Further, major exogenous economic events such as

OPEC oil shocks aﬀect ﬁnancial time series. They also could be regarded as events

of a certain duration in which the dynamics of ﬁnancial time series might behave

diﬀerently from what is seen outside these periods.

In Hamilton [20] a vector autoregression model is put forward subject to occa-

sional discrete shifts, where a discrete-valued Markov process governs the shifts.

Next, one has to ﬁnd out when the shifts occurred and estimate parameters char-

acterizing the diﬀerent regimes and the probabilities for the transition between

regimes. For maximum likelihood estimates of the respective parameters, an EM

algorithm is applied. Applications of Markov regime switching processes to asset

price volatility modeling can be found in contributions by Naik [24] and Di Masi

et al. [11].

9

The volatility of risky assets is aﬀected by random and discontinuous shifts

over time. Those jumps are driven by various unsystematic and systematic events.

Examples are mergers and acquisitions, shifts in corporate strategy and changes

in economic policy. In order to hedge claims contingent on risky assets, a volatil-

ity model that captures the outcomes of such events is proposed. For example,

Di Masi et al. [11] consider the problem of hedging an European call option for

a diﬀusion model where drift and volatility are functions of a Markov jump process.

Fixed income models have been an important source for applications to en-

ergy price modeling. The energy forward price curve exhibit features similar to

forward interest rate dynamics, especially the Heath-Jarrow-Morton (HJM) model

by Heath et al. [22]. One could take two approaches for stochastic modeling of

ﬁxed income markets. First, one starts out with a stochastic model for the spot

interest rate and derives bond prices from this short rate based on no-arbitrage

principles. Alternatively, one could specify the complete yield curve dynamics di-

rectly which is suggested by the HJM approach. It means that forward rates are

modeled directly. Since commodities trade both in spot and forward markets, these

modeling approaches for ﬁxed income markets could be applied to energy markets.

Markov Chain models for the instantaneous short-term interest rate were in-

troduced by, amongst others, Hansen and Poulsen [21] and Elliott and Wilson [13].

In the ﬁrst paper, only the drift rate of the short rate was modeled by a contin-

uous Markov chain. Whereas Elliott and Wilson [13] extended this approach to

the case when both the drift rate and the volatility of the short rate are driven

by a common Markov Chain. The work of Valchev [29] builds on that of Elliott

and Wilson [13], but a Markov Chain stochastic volatility HJM model is intro-

duced. Also, the evolution of the whole term structure of volatilities is explored,

not merely the volatility of the short rate, which is only one point of the volatility

curve.

The Markov Chain speciﬁcation allows for jump discontinuities and captures

the various shapes of the term structure of volatilities as well. The model is an

extension of the class of deterministic volatility HJM models to the wider class

of HJM models with piecewise-deterministic volatility. The class of piecewise-

deterministic processes, introduced by Davis [8], provides a suitable framework

for modeling the dynamics of the volatility term structure. In between jumps the

volatility follows an almost deterministic process, that is the volatility function is

non-stochastic. The volatility modeled is stochastic only through its dependence

10

on the Markov Chain. A process in the class of piecewise-deterministic processes

is the continuous-time homogeneous Markov Chain with a ﬁnite number of jump

times. This process only approaches the actual jumps with jumps over a ﬁnite set

of values but permits the use of stochastic calculus for continuous Markov chains

Elliot et al. [12].

In energy markets modeling, most of existing literature focuses on developing

realistic spot price markets. Based on a stochastic model for the time evolution of

the spot price, forward dynamics are derived calling arbitrage theory. Therefore,

various regime-switching models are calibrated to electricity spot prices (see, for

example, Deng [10] and de Jong & Huisman [9]). The approach taken in this

essay, based on the framework provided by Chiarella et al. [4], is in the spirit

of Davis [8], Elliot et al. [12] and Valchev [29]. The result is a stochastic model

that speciﬁes directly the dynamics of the forward contracts traded in the natu-

ral gas markets. The class of piecewise deterministic processes is retained where

the volatility functions are speciﬁed explicitly and the coeﬃcients switch values

dependent on the Markov Chain. Both the volatility functional form and Markov

switching were introduced for electricity markets by Benth & Koekebakker [1]

where various diﬀerent volatility dynamics of forward curve models were speciﬁed

based on the HJM approach.

Finally, for the estimation of the parameters of the proposed volatility functions

a Bayesian solution is proposed. The Bayesian way to tackle the inference problem

is to come up with the distribution of parameters and latent variables conditional

on observed data. Next, MCMC techniques are used to explore these distributions.

There has been a fair amount of theoretical and practical work on regime-switching

models using MCMC methods. There were early contributions by Carlin and

Polson [3] and Chib [5] & [6]. Johannes & Polson [23] provide a general algorithm

based on the work by Scott [27]. A forward ﬁltering backward sampling (FFBS)

algorithm is applied to the case of regime-switching models. Fr¨ uhwirth-Schnatter

[14] and Fr¨ uhwirth-Schnatter & Sass [18] further extend the approach and found

that the MCMC framework outperformed the corresponding EM algorithm.

An application to energy markets was ﬁrst found in Rambharat et al. [26]

which estimates a discrete time model for electricity prices using a Markov Chain

Monte Carlo (MCMC) approach. Also Seifert & Uhrig-Homburg [28] follow a sim-

ilar approach to model European electricity spot prices. In this essay, the MCMC

set-up and respective algorithms suggested by Fr¨ uhwirth-Schnatter [14] and Hahn,

Fr¨ uhwirth-Schnatter & Sass [18] are implemented to estimate the parameters of the

11

model including the transition probabilities of the Markov Chain from all available

forward curves on the market. This is also the framework adopted by Chiarella

et al. [4] for the estimation of natural gas forward prices which is explained thor-

oughly and deployed in this essay.

12

Chapter 2

Forward price curve model

In this chapter a general multi-factor, multi-commodity (MFMC) model is intro-

duced. Subsequently, in the next section the process of parameter estimation from

historical data is explained.

2.1 Multi-factor single-commodity model

From the stylized facts detailed above in Section 1.1 it is clear that forward prices

of diﬀerent maturities are not perfectly correlated. Although the separate price

curves usually move up and down together, the front end of the curve displays

much more volatility than the end of the curve. Further, both parts of curve

change shape in diﬀerent ways (see Breslin et al. [2]). Therefore, a single factor,

as incorporated in (2.1), is not suﬃcient to explain the behavior witnessed in the

markets.

dF(t, T)

F(t, T)

= σ(t, T)dz(t) (2.1)

Here, the term F(t, T) stands for the forward price at time t with expiry T. And,

z(t) is an independent Brownian motion. It is the sole source of uncertainty and

is associated with a volatility function σ(t, T). The volatility function could be

interpreted as the the time t volatility of the T maturity forward price return. It

determines the magnitude and direction of the single random shock that drives

changes in the forward curve. However, more than one single factor of uncertainty

needs to be introduced to capture forward curve changes other than parallel moves

along the curve. This can be done by adding independent Brownian motions

(Breslin et al. [2]).

13

The stochastic diﬀerential equation (SDE) below represents a general multi-

factor model of the forward curve:

dF(t, T)

F(t, T)

=

n

¸

i=1

σ

i

(t, T)dz

i

(t) (2.2)

The evolution of the forward price is now driven by n independent Brownian

motions, dz

i

(t). For every source of risk there is a correspondent volatility function

σ

i

(t, T). The respective volatility functions now deﬁne the magnitude and direction

of multiple shocks that trigger changes along all points on the forward curve. As

a result, (2.2) will represent changes in shapes where diﬀerent parts of the forward

curve will move in diﬀerent ways (Breslin et al. [2]).

A typical example of a multi-factor model is a model with three risk factors.

Three independent Brownians, dz

1

(t), dz

2

(t) and dz

3

(t) correspond to the functions

σ

1

(t, T),σ

2

(t, T) and σ

3

(t, T) which respectively act to shift, tilt and bend the

forward curve. The ﬁrst function is positive for all maturities which implies that

a positive shock to the system causes all prices to shift up. The second most

important factor is a tilt factor which causes the short and long ends of the curve

to move in opposite directions. Finally, the third factors is a bending factor which

causes the long and short ends to move opposite to the middle. In practice, it is

found that a number of three factors is usually adequate to capture the forward

price dynamics (Breslin et al. [2]).

In our data sample, represented by F(t, T), 12 diﬀerent contracts are included.

Therefore, there are 12 factors that can explain the variance of the evolution of the

curve. However, only a few of these will be signiﬁcant for explaining the variation

in the forward curve. The respective volatility functions can easily be obtained

from time series analysis. One method that can be applied is principal components

analysis (PCA) or eigenvector decomposition of the covariance matrix of the for-

ward returns. Sample covariance values between pairs of forward price returns are

calculated. Then the eigenvectors of the covariance matrix yield approximate the

factors governing changes in the forward curve (Breslin et al. [2]).

In order to start estimating the volatility functions, Equation (2.2) for a single

commodity with n factors is rewritten. Ito’s lemma is applied to (2.2), which

renders the following forward curve dynamics:

∆log F(t, t + τ

j

) = −

1

2

n

¸

i=1

σ

i

(t, t + τ

j

)

2

∆t +

n

¸

i=1

σ

i

(t, t + τ

j

)∆z

i

(2.3)

14

Therefore, the diﬀerence of the log of forward prices with respective maturities τ

j

for j = 1, . . . , m are jointly normally distributed with mean −

1

2

¸

n

i=1

σ

i

(t, t+τ

j

)

2

∆t

and standard deviation

¸

n

i=1

σ

i

(t, t + τ

j

)

2

∆t.

Next, the annualized sample covariance matrix of these forward prices F(t, T)

is calculated and the eigen-decomposition is computed:

Σ = ΓΛΓ

T

(2.4)

where

Γ =

ν

11

ν

12

. . . ν

1n

ν

21

ν

22

. . . ν

2n

. . . . . . . . . . . .

ν

n1

ν

n2

. . . ν

nn

¸

¸

¸

¸

(2.5)

and

Λ =

λ

1

0 0 0

0 λ

2

0 0

0 0 . . . 0

0 0 0 λ

n

¸

¸

¸

¸

(2.6)

. The eigenvectors are found in the columns of Γ. Then the variances of the factors

that govern the points on the forward curve are the eigenvalues weighed by the

corresponding eigenvectors (Breslin et al. [2]). The discrete volatility functions

become thus,

σ

i

(t, t + τ

j

) = ν

ji

λ

i

(2.7)

15

Figure 2.1 shows the covariance surface of the data F(t, T).

Figure 2.1: Annualized covariance surface for NBP data F(t, T)

One observes that higher covariance values are found at the short end of the

forward curve. For longer-dated contracts the surface will decay. The surface is

not smooth due to illiquidity in longer-dated contracts and changes in market dy-

namics. However, another important source of noise is seasonality. It is therefore

advised to repeat the PCA analysis for the diﬀerent seasons deﬁned (Breslin et

al. [2]).

16

Next, from the covariance matrix the form of the volatility functions is obtained

as described by (2.7). Figure 2.2 plots the ﬁrst three volatility functions σ

1

(t, T),

σ

2

(t, T) and σ

3

(t, T) which respectively shift, tilt and bend the forward curve.

Figure 2.2: First three volatility functions for NBP data F(t, T)

17

2.2 Spot - forward price relationship

The dynamics of the forward curve are related to spot price dynamics. The spot

price is the price quoted at which a particular commodity can be bought or sold

for immediate delivery. In the case of natural gas the delivery will take place the

next day. This is called day-ahead delivery. Hence, the spot price is essentially the

front end of the forward curve. Since the forward curve and spot dynamics are

related, an equation for the evolution of the spot price can be written down which

is consistent with forward price dynamics.

At the front end of the curve the maturity date is equal to the current date t.

Further, (2.2) is integrated. Following a further diﬀerentiation, an SDE is obtained

which describes the spot price dynamics. The spot price is given by, F(t, t) = S(t)

(see Breslin et al. [2]).

dS(t)

S(t)

=

¸

∂lnF(0, t)

∂t

−

n

¸

i=1

t

0

σ

i

(u, t)

∂σ

i

(u, t)

∂t

du +

t

0

∂σ

i

(u, t)

∂t

dz

i

(u)

¸

dt

+

n

¸

i=1

σ

i

(t, t)dz

i

(t) (2.8)

The drift term of (2.8) is found between square brackets. It contains integrals over

the Brownian motions from time zero to time t. That is, all random shocks from

the start of the process up till the current date are incorporated in the spot price.

The spot price process described is thus non-Markovian.

2.3 Seasonality adjustment

Further, as mentioned in Section 1.1, an important stylized fact of energy markets

is seasonality in the forward price volatilities. Therefore, seasonality should be

taken into account when modeling evolution of the forward curve. One could es-

timate a diﬀerent volatility function for each season, where seasons are obtained by

splitting the data. Examples are summer/winter and summer/autumn/winter/spring.

Alternatively, the functions of (2.2) could be rewritten as a product of a time-

dependent spot volatility function and maturity-dependent volatility functions

(Breslin et al. [2]). (2.2) thus becomes:

18

dF(t, T)

F(t, T)

= σ

s

(t)

n

¸

i=1

σ

i

(T − t)dz

i

(t) (2.9)

where the spot price volatility at time t is described by σ

s

(t) and σ

i

(T − t), i =

1, . . . , n who respresent the n maturity-dependent volatility functions.

2.4 Multi-factor multi-commodity model

Equation (2.2) could be further generalized to incorporate multiple commodities.

Practitioners in energy risk management often have to deal with joint modeling of

diﬀerent commodities. For example, the spark spread is the spread between the

power price and the price for natural gas used to produce the electricity. Spark

spread modeling is critical in order to value power plants. Then, (2.10) describes

the joint forward curve dynamics of multiple commodities as:

dF

c

(t, T)

F

c

(t, T)

=

n

c

¸

i=1

σ

c,i

(t, T)dz

c,i

(t) (2.10)

where c = 1, . . . , m stands for the diﬀerent commodities and i = 1, . . . , n

c

points

out the particular volatility function that corresponds to each commodity. The cor-

relation between the diﬀerent commodities is ﬁxed by a correlation matrix for the

Brownian motions. Obviously, the correlations between the Brownians governing a

commodity, dz

i

(t) for a given commodity c, are still zero. But now the correlations

between the Brownian motions driving diﬀerent commodities c, dz

c,i

(t), represent

the inter-commodity correlations (Breslin et al. [2]).

Equivalent to the approach taken for a single commodity, as described by equa-

tion (2.9), the discrete-time evolution of the forward curve can be written in terms

of the estimated volatility functions. This results in the following matrix repre-

sentation:

¯ x(t) = ¯ µ(t) +

˜

Σ¯ ε (2.11)

where

• ¯ x(t) is the vector of changes in the natural logarithms of the forward prices

for each maturity at the speciﬁed time step;

• ¯ µ(t) is the vector of drift terms over the time step;

19

•

˜

Σ is the matrix of discrete volatility function terms;

• ¯ ε is the unknown vector of standard normally distributed random shocks.

2.5 Two-factor regime switching forward price curve model

Building on the general framework for commodity forward price curves introduced

in Section 2.1, the following two-factor regime switching model for the natural gas

forward curve is proposed (see Chiarella et al. [4]). As indicated in Section 1.2 it is

modeling a process in the class of piecewise-deterministic processes which provides

a suitable framework for modeling the dynamics of the volatility term structure.

In between two random jump times an almost deterministic process is followed by

the volatility. Further, Markov Switching of the coeﬃcients is imposed. Therefore,

the model belongs to the class of Markov Switching models (Chiarella et al. [4]).

dF(t, T)

F(t, T)

= σ

1

(t, T)dz

1

(t) + σ

2

(t, T)dz

2

(t) (2.12)

where

• the natural gas forward price at time t with maturity T is denoted by F(t, T).

• both volatility functions, that is for i = 1, 2, have diﬀerent volatility and

attenuation parameters depending on the state of the Markov Chain X

t

.

That is,

σ

i

= (σ

i1

, σ

i2

, . . . , σ

iN

), α

i

= (α

i1

, α

i2

, . . . , α

iN

),

• further, the notation ·, · is introduced and stands for the scalar product in

R

N

if u = (u

1

, . . . , u

N

) then

u, X

t

=

N

¸

i=1

u

i

I

(X

t

=e

i

)

where the indicator function is represented by I

(X

t

=e

i

)

:

I

(X

t

=e

i

)

=

1 ifX

t

= e

i

0 otherwise.

20

σ

1

(t, T) = σ

1

, X

t

c(t) (e

−α

1

,X

t

(T−t)

(1 − σ

l1

) + σ

l1

)

σ

2

(t, T) = σ

2

, X

t

c(t) (σ

l2

− e

−α

2

,X

t

(T−t)

)

c(t) = c +

J

¸

j=1

(d

j

(1 + sin(f

j

+ 2πjt)))

(2.13)

where

• switching between parameter values is governed by a ﬁnite state Markov

Chain X

t

, with the state space deﬁned by X = {e

1

, e

2

, . . . , e

N

},

with e

i

a vector of length N that has a value of 1 at the i-th position and 0

elsewhere, that is

e

i

= (0, . . . , 0, 1, 0, . . . , 0)

T

∈ R

N

.

• the transition probability matrix of the Markov Chain X

t

is deﬁned by ξ =

(ξ

ij

)

NxN

. Where ξ

ij

is the conditional probability that the Markov Chain

X

t

switches from state e

i

at time t to state e

j

at time t + 1, for all i =

1, . . . , N, j = 1, . . . , N, that is

ξ

ij

= π(X

t+1

= e

j

|X

t

= e

i

)

• c(t) represents the seasonal part which is modeled as a truncated Fourier

series

Therefore seasonality is introduced into the model by making the parameters

periodic functions of time, with a periodicity of one year. For the application

below, the Fourier series will consist of only one series, that is J = 1. The

parameters c, d

1

and f

1

are then estimated.

• z

1

(t) and z

2

(t) are independent Brownian motions.

• since the long term volatility behaves diﬀerently from short term behavior,

parameters σ

l1

and σ

l2

are deﬁned to describe long run volatility.

21

Chapter 3

Estimation

In this chapter a Bayesian approach is presented to estimate the parameters of the

forward curve model described by (2.12) and (2.13). The model is a Markov

Switching model: the parameters, found in the respective volatility functions

σ

1

(t, T) and σ

2

(t, T), take diﬀerent values for diﬀerent states of the world. Fur-

ther, the state transitions are driven by a ﬁnite state Markov Chain, X. The set

of parameters is deﬁned as θ:

θ = {σ

i

, α

i

, σ

li

(i = 1, 2), c, d

j

, f

j

, (j = 1, 2, . . . , J)} (3.1)

The elements of the transition probability matrix ξ are also unknown and have to

be inferred from the historical data as well.

For the econometric estimation of the states for drift and volatility, θ, and the

transition probability matrix of the underlying Markov Chain, ξ, a Markov Chain

Monte Carlo (MCMC) method is suggested and implemented. In particular, a

discrete-time Gibbs sampler is developed to estimate θ and ξ given the forward

prices at ﬁxed observation times ∆t, 2∆t, . . . , M∆t = t, where t is the present

time. It is thus assumed that the state process can jump only at the discrete

observation times (Chiarella et al. [4]).

3.1 Data transformation

So, for the diﬀerent maturities the forward prices F(k∆t, T), k = 1, . . . , M are

observed. Then in discrete-time the forward dynamics of (2.12) can be rewritten

as

22

y

t,T

= log F(t∆t, T) − log F(t, T)

= −

1

2

2

¸

i=1

σ

i

(t, T)

2

∆t +

2

¸

i=1

σ

i

(t, T)∆z

i

(t). (3.2)

One can see that diﬀerence of the log of forward price, y

t,T

is normally distributed

with mean

µ(t, T) = −

1

2

2

¸

i=1

σ

i

(t, T)

2

∆t (3.3)

and standard deviation

2

¸

i=1

σ

i

(t, T)

2

∆t. (3.4)

The notation for the forward dynamics y

t,T

is abbreviated to y

T

.

3.2 Bayesian estimation for a Markov switching model

In the Bayesian estimation for a Markov switching model, the latent Markov Chain

X is introduced as missing data and samples for θ and X are generated given y

T

for parameter estimation. The technique of constructing sampling algorithms via

the introduction of latent variables is called data augmentation. The sampling

distribution is the posterior distribution, π(X

t

, θ|y

T

), and the sampler applied

here is a Gibbs sampler (Fr¨ uhwirth-Schnatter [14]).

The posterior distribution π(X, θ|y

T

) is proportional to the complete-data like-

lihood distribution π(y

T

|X, θ) which expresses the forward dynamics y

T

given the

states of the Markov Chain X and parameter values θ. Further, the conditional

distribution π(X|θ) indicates that realizations of X are dependent on the param-

eter values θ, and initial knowledge about the model parameters is expressed by

deﬁning a prior distribution for θ, pr(θ).

π(X, θ|y

T

) ∝ π(y

T

|X, θ)π(X|θ)pr(θ) (3.5)

Before drawing from this augmented complete-data likelihood distribution the

prior distributions have to be chosen (Chiarella et al. [4]).

23

3.3 Prior distributions

Prior distributions are chosen for θ and X

0

, the state of the Markov Chain at t = 0.

Under the assumption that the set of parameters θ given by (3.1), ξ and X

0

are

independent, the priors can be written as follows

π(θ, ξ, X

0

) = pr(ξ)

2

¸

i=1

(pr(σ

i

) · pr(α

i

) · pr(σ

li

))pr(c)

J

¸

j=1

(pr(d

j

)pr(f

j

))pr(X

0

).

Where the following distributions are assumed for the priors:

• The priors of volatility and attenuation parameters are σ

il

∼ U(a

σ

il

, b

σ

il

), and

α

il

∼ U(a

α

il

, b

α

il

) where a

σ

il

and a

α

il

are discrete values which deﬁne the param-

eters of the uniform distribution. As a result, the volatility and attenuation

parameters are bounded which eases convergence.

• The priors of the long run volatility parameters, σ

li

, are uniformly distributed

as well, σ

li

∼ U(0, 1)

• The rows ξ

l

of the transition probability matrix ξ, are assumed to be inde-

pendent and to follow a Dirichlet distribution ξ

l

∼ D(g

l1

, . . . , g

lN

)

where the vector g

l.

equals the prior expectation of xi

l.

times a constant that

determines the variance. If ξ

0

denotes our prior expectation of ξ, we may

set g

l.

= ξ

0

l.

c

p

. Then c

p

can be interpreted as the number of observations of

jumps out of state l in the prior distribution. If the number of states, N, is

restricted to 2, the Dirichlet distribution simpliﬁes to a Beta distribution.

• The priors for the parameters of the seasonal part, c, d, f, are uniformly

distributed c, d, f ∼ U(a

c

, b

c

)

• The prior of the initial state of the Markov Chain is following a discrete

uniform distribution, X

0

∼ U({1, . . . , N}) where N is equal to the number

of states deﬁned for the Markov Chain.

All parameters g

l1

, . . . , g

lN

, a

σ

il

, b

σ

il

, a

α

il

, b

α

il

, a

c

, b

c

in the prior distributions are de-

ﬁned before running the Gibbs sampler (Chiarella et al. [4]).

24

3.4 Gibbs sampler

Starting from the prior distributions speciﬁed in Section 3.2, the unknowns are

partitioned into three blocks θ, ξ and X. Next, a three-step MCMC sampler is

used to sample from the augmented posterior distribution π(θ, ξ, X|y

T

) given the

observed data y

T

where each part is drawn from the proper conditional density

(Chiarella et al. [4]).

The particular scheme is explained in Algorithm 1 below. Conditional on

knowing the state of the ﬁnite Markov Chain X, θ is sampled and X is sampled

conditional on knowing θ (Fr¨ uhwirth-Schnatter [14]).

Algorithm 1: Unconstrained MCMC for a Markov Switching Model

Start with some state process X

(0)

and repeat the following steps for k =

1, . . . , K

0

, . . . , K + K

0

. The notation K

0

represents the number of iterations for

the burn-in. These samples are thrown away for the calculation of the estimators.

Clearly, the length of burn-in depends on the initial state of the Markov Chain

state, X

0

, and the rate of convergence.

1. Parameter simulation conditional on the states X

(k−1)

(a) Sample the transition matrix ξ

(k)

from the complete-data posterior dis-

tribution π(·|X

(k−1)

).

(b) Sample the model parameters θ

(k)

from the complete-data posterior

π(θ|y

T

, X

(k−1)

). Store the actual values of all parameters θ

(k)

and ξ

(k)

.

2. State simulation conditional on knowing θ

(k)

by sampling a path X of

the hidden Markov Chain from the conditional posterior π(X|θ

(k)

, y

T

) using

Algorithm 3, which will be discussed below.

3.4.1 Full conditional posterior distributions

Next, the full conditional posteriors required for the three sampling steps are

derived. The complete-data likelihood function is a product of normal densities,

described by φ(y

T

, µ, σ) with the with mean µ

k∆t,T

and standard deviation σ

k∆t,T

,

given by the moments of ( 3.5 ) (Chiarella et al. [4]).

π(y

T

|θ, ξ, X) =

M

¸

k=1

φ(y

k∆t,T

, µ

k∆t,T

, σ

k∆t,T

) (3.6)

25

Further the full conditional of θ, the conditional joint distribution of the parameters

associated with drift and volatility is given by

π(θ|y

T

, ξ, X) ∝ π(y

T

|θ, X)pr(θ) (3.7)

Finally, the full conditional posterior of the state process

X

l∆

t

, l = 1, 2, . . . , M, is

π(X|y

T

, θ, ξ) ∝ π(y

T

|θ, X)π(X|ξ) (3.8)

where the prior distribution π(X|ξ) is not dependent on θ but rather speciﬁed by

the distribution of X

0

and the transition matrix ξ. The conditional probability

π(X|ξ) in ( 3.8 ) is provided by

π(X|ξ) = π(X

0

|ξ)

M

¸

k=1

π(X

k

|X

k−1

, ξ) = π(X

0

|ξ)

N

¸

l,q=1

ξ

N

lq

lq

(3.9)

where the notation N

lq

stands for the number of transitions from state l to q, that

is N

lq

=

¸

M

k=1

I

(X

k−1

=l,X

k

=q)

(Chiarella et al. [4]).

3.4.2 Sample the transition matrix

The MCMC routine Algorithm 1 was introduced in Section 3.4 to infer the param-

eters of the volatility functions. In the next sections the several steps involved will

be explained in more detail. First, from the complete-data posterior distribution

π(ξ|X

(k−1)

), the transition matrix ξ

(k)

is sampled (Fr¨ uhwirth-Schnatter [14]).

Given the transition matrix ξ

(k)

of the hidden Markov Chain, each row is an un-

known probability distribution that has to be estimated from the data. Therefore,

complete-data estimation is carried out for a given path X.

The complete-data likelihood π(X|ξ) is given by,

π(X|ξ) =

2

¸

j=1

2

¸

k=1

ξ

N

K

jk

(X)

jk

(3.10)

where 2 states are deﬁned for the Markov Chain and N

jk

counts the number of

transitions from j to k (Fr¨ uhwirth-Schnatter [14]).

In order to determine the particular algorithm, assumptions regarding the dis-

tribution π

0

of the initial value X

0

have to be made. In this essay the initial

26

distribution π

0

is assumed to be independent of ξ. Now a classical Bayesian in-

ference problem, Gibbs sampling from the conditional posterior π(ξ|X) can be

applied. The rows ξ

j·

of ξ, independent a posteriori, are drawn from the following

Dirichlet distribution (Fr¨ uhwirth-Schnatter [14]).

ξ

j·

∼ D(e

j1

+ N

j1

(X), . . . , e

jK

(X) + N

jK

(X))j = 1, . . . , N (3.11)

where N

jk

(X) = #{X

t−1

= j, X

t

= k} counts the numbers of transitions from j

to k for the actual draw of X.

Since only two distinct states are deﬁned for the transition matrix ξ, that

is N = 2, the persistence probabilities ξ

11

and ξ

22

, both independent, are each

following a Beta distribution.

ξ

11

∼ B(e

11

+ N

11

(X), e

12

+ N

12

(X))ξ

22

∼ B(e

21

+ N

21

(X), e

22

+ N

22

(X)) (3.12)

These densities generalize to the Dirichlet distribution for the case N > 2 (Fr¨ uhwirth-

Schnatter [14]).

3.4.3 Sample the model parameters

A single-component Metropolis-Hastings algorithm is set up in order to update the

parameter set θ. The candidate θ

∗

is generated by a so-called candidate generating

density q(θ, θ

∗

). Here, a normal random walk is used to draw θ

∗

.

θ

∗

= θ + r

θ

ψ (3.13)

where ψ is a vector of independent standard normal random variables and r

θ

is a

scalar which represents a ﬁxed value for the step width.

Further, instead of updating the elements of θ all at once, it is more straightfor-

ward and computationally eﬃcient to split θ into its components {θ

1

, θ

2

, . . . , θ

d

},

with d the number of parameters, and update one by one, that is sequentially.

27

Algorithm 2: single-component Metropolis-Hastings

1. Initialize vector θ

0

at some values for its components.

Diﬀerent starting values could be chosen. One could, for example, look at

parameter values found in previous research.

2. Let θ

(k)

i

denote the value of θ

i

at end of iteration k. For step i of iteration

k + 1, θ

i

is updated.

The candidate is generated from proposal distribution q

i

(θ

i

|θ

(k)

i

, θ

(k)

−i

)

where θ

(k)

−i

denotes the value of θ

−i

after completing step i − 1 of iteration

k + 1: θ

(k)

−i

= {θ

(k+1)

1

, θ

(k+1)

2

, . . . , θ

(k+1)

i−1

, θ

(k)

i+1

, . . . , θ

(k)

h

}

where components 1, 2, . . . , i −1 have already been updated. So, only for the

i-th component of θ a candidate is generated and this candidate is dependent

on the current values of the other elements of θ.

3. Next, the candidate is accepted with probability α(θ

(k)

−i

, θ

(k)

i

, θ

∗

i

) where

α(θ

−i

, θ

i

, θ

∗

i

) = min

¸

1,

π(θ

∗

i

|θ

−i

)q

i

(θ

i

|θ

∗

i

, θ

−i

)

π(θ

i

|θ

−i

)q

i

(θ

∗

i

|θ

i

, θ

−i

)

(3.14)

where the full conditional distribution for θ

i

under π(·) is denoted by π(θ

i

|θ

−i

).

4. Generate a random number ∼ U(0, 1).

If this random number is less than α(θ

−i

, θ

i

, θ

∗

i

) then the move is accepted.

Otherwise, the random number is greater than the acceptance probability,

thus the proposed move for component i of parameter set θ is rejected. So,

if θ

∗

i

is accepted, θ

(m+1)

i

= θ

∗

i

; otherwise θ

(m+1)

i

= θ

(m)

i

. At this step θ

(m)

−i

is

left untouched.

Notice that q

i

(θ

i

|θ

∗

i

, θ

−i

) = q

i

(θ

∗

i

|θ

i

, θ

−i

) by the symmetry of the normal distri-

bution. Therefore, the factor

q

i

(θ

(k)

i

|θ

∗

i

, θ

(k)

−i

)

q

i

(θ

∗

i

|θ

(k)

i

, θ

(k)

−i

)

drops out of the Metropolis probability calculation (3.14). This greatly simpliﬁes

the calculation of α. This special case of the Metropolis-Hastings algorithm is often

referred to as the random-walk Metropolis-Hastings (Fr¨ uhwirth-Schnatter [14]).

28

When the random-walk Metropolis algorithm is used as candidate generating

density q(·, ·), the standard deviation of the normal random variable is the step

size r

θ

. If that step size is too high, candidate draws θ

∗

i

will be very far away from

the current draw, and in a region of the parameter space that has low probability.

This would lead to a high rejection rate, and a Markov Chain that doesn’t move

very often. Whereas, when r

θ

is chosen to be too low, then candidate draws

will be very close to the current draw. Hence, the algorithm accepts frequently,

but the chain will move slowly around the parameter space. So, it is a good

idea to experiment with diﬀerent values for step size. And, in general, it is wise

to run multiple chains from disperse starting values, to help assess convergence

(Fr¨ uhwirth-Schnatter [14]).

Finally, the updating order for the elements of θ in above Algorithm 2 is as-

sumed to be ﬁxed. But random permutations of the updating order are acceptable

as well.

3.4.4 Markov Chain state simulation

In a ﬁnal step of the Gibbs sampler, as described by Algorithm 1, a path X of

the hidden Markov Chain from the conditional posterior π(X|(θ

(k)

, ξ

(k)

), y

T

) is

sampled conditional on (θ

(k)

, ξ

(k)

). In this section this sampling method for the

hidden Markov Chain X = (X

0

, . . . , X

T

), is worked out in great detail.

Sampling Posterior Paths of the Hidden Markov Chain

A resourceful way to sample is called multi-move sampling where the states of

the whole path X are jointly sampled from the conditional posterior distribution

π(X|y

T

, θ). First, the joint posterior π(X|y

T

, θ) is written as follows

π(X|y, θ) =

¸

T−1

¸

t=0

π(X

t

|X

t+1

, . . . , X

T

, θ, y

T

)

¸

π(X

T

|y

T

, θ) (3.15)

where the ﬁltered probability distribution at t = T is denoted by π(X

T

|y

T

, θ).

Further,

π(X

t

|X

t+1

, . . . , X

T

, θ, y

T

) ∝ ξ

X

t

,X

t+1

π(X

T

|y

t

T

, θ) (3.16)

where π(X

T

|y

t

T

, θ) is the ﬁltered probability distribution at time t. Here, the

assumption is taken that the Markov Chain X

t

is homogeneous. As a consequence,

π(X

t+1

|X

t

, θ, y

t

T

) is simpliﬁed to ξ

X

t

,X

t+1

.

29

Given the above-mentioned distributions it is now possible to implement a

forward-ﬁltering-backward-sampling algorithm.

Algorithm 3: Multi-Move Sampling of the States

Given ﬁxed values for parameter set θ, execute the following steps to sample a

path X

k

of the hidden Markov Chain.

1. Obtain Filtered state probabilities

First, conditional on θ, run the ﬁlter described in Algorithm 3.1. The re-

sulting ﬁltered state probability distribution π(X

t

= j|y

t

, θ) j = 1, 2 for

t = 1, . . . , T is then stored.

For a state space model, the ﬁltering problem implies statistical inference

about the state variable conditional on observations from the beginning up

till time t. The complete ﬁltering distribution is obtained by the discreteness

of the support of the state variable X

t

. π(X

t

= l|y

t

T

, θ) for all possible

realizations l ∈ {1, 2} of X

t

.

Algorithm 3.1: Filtering the States

For t = 1, 2, . . . , T, the following steps are executed sequentially.

(a) One-step ahead prediction of X

t

:

π(X

t

= l|y

t−1

, θ) =

2

¸

k=1

ξ

kl

π(X

t−1

= k|y

t−1

T

, θ) (3.17)

for l = 1, 2 where π(X

t

= l|X

t−1

= k, y

t−1

T

, θ) simpliﬁes to the transition

probability ξ

kl

for homogeneous Markov Chains.

(b) Filtering for X

t

:

π(X

t

= l|y

t

, θ) =

π(y

t

|X

t

= l, y

t−1

T

, θ)π(X

t

= l|y

t−1

T

, θ)

π(y

t

|y

t−1

T

, θ)

(3.18)

where

π(y

t

T

|y

t−1

T

, θ) =

2

¸

k=1

π(y

t

T

|X

t

= k, y

t−1

T

, θ)π(X

t

= k|y

t−1

T

, θ) (3.19)

At t = 1, the ﬁlter is started with the initial distribution π(X

0

= k|ξ).

So, π(X

1

= l|y

0

T

, θ) =

¸

2

k=1

ξ

kl

π(X

0

= k|ξ).

30

As is typical for any ﬁlter, the discrete ﬁlter described in Algorithm 3 is an

adaptive inference tool. At time t − 1, the ﬁltered probabilities π(X

t−1

=

l|y

t−1

T

, θ) summarize, for a ﬁxed value of θ, all information the observations

y

1

, . . . , y

t−1

T

contain about X

t−1

. To obtain inference about X

t

at time t

in terms of the posterior distribution π(X

t

= l|y

t

T

, θ), knowledge of the

posterior distribution π(X

t−1

= l|y

t−1

T

, θ) at time t − 1 and only the actual

value of y

t

T

are suﬃcient.

2. Sample X

(k)

T

from the ﬁltered state probability distribution π(X

t

=

j|y

t

T

, θ)

3. For t = T −1, T −2, . . . , 0 sample S

(k)

t

from the conditional distribution

π(X

t

= j|X

(k)

t+1

, y

t

, θ) given by

π(X

t

= j|X

(k)

t+1

, y

t

T

, θ) =

ξ

j,l

m

π(X

t

= j|y

t

T

, θ)

¸

K

k=1

ξ

k,l

m

π(X

t

= k|y

t

T

, θ)

where l

m

is equal to the state of S

t+1

and π(X

t+1

= l

m

|X

t

= j, θ, y

t

T

) reduces

to ξ

j,l

m

since the Markov Chain X

t

is homogeneous.

For each t, π(X

t

|X

m

t+1

, y

t

T

, θ) needs to be evaluated for all j = 1, . . . , K.. This

requires knowledge of the ﬁltered state probabilities π(X

t

= j|y

t

T

, θ), which

were stored in step 1 of Algorithm 3.

31

Chapter 4

Implementation

In this chapter, the details of the implementation are laid out and the numerical

results for the routines are provided. Before applying the chosen methodology

to historical gas forward prices, the algorithms are tested with simulated data.

Further, estimators are given for both a one-factor model and the two-factor model

described in Section 2.5.

4.1 Data

The natural gas prices modeled are forward prices for the National Balancing Point

(NBP), which is the British virtual trading location operated by TSO National

Grid, covering all entry and exit points in mainland Britain. It is the most liquid

gas trading point in Europe. Natural gas at NBP trades on a forward month,

forward quarter, forward season or year forward basis and prices are expressed

in pence (GBp) per therm. For parameter estimation of the chosen model, daily

observations for the forward prices were obtained with maturities ranging from

July 2009 to September 2012. The observations span over a year with prices at

times t from 23/10/2007 to 12/03/2009. This data is represented by F(t, T).

Further, in order to obtain the forward dynamics y

T

for every maturity T, the log

diﬀerence transform is applied to the original data F(t, T).

4.2 Choosing the prior

The complete-data likelihood and the full conditionals introduced in Chapter 3

contain prior knowledge about the parameter set θ, and X

0

. There is some degree

of freedom in the choice of prior distribution but the prior distribution should be

32

independent of the data and the posterior distribution. The following priors are

used in the implementation (Chiarella et al. [4]):

• For the transition matrix ξ the vector g

l.

equals the prior expectation of

xi

l.

times a constant that determines the variance. If ξ

0

denotes the prior

expectation of ξ, one may set g

l.

= ξ

0

l.

c

p

. Then c

p

can be interpreted as

the number of observations of jumps out of state l in the prior distribution.

Hence, the matrix of parameters for the Dirichlet distribution is set to

g =

¸

0.64 0.36

0.16 0.84

¸

(4.1)

• The priors of σs and αs, (i, l = 1, 2) are σ

il

∼ U(0, 1.5), and α

il

∼ U(0, 5)

• The priors of σ

l

i

are σ

l

i

∼ U(0, 1), (i = 1, 2)

• The priors of c, d, f(J = 1) are c, d

1

, f

1

∼ U(0, 1)

• The prior of the initial state of the Markov chain is X

0

∼ U({1, 2})

4.3 Running the Gibbs sampler

A randomized algorithm is used to calculate the complete-date likelihood function.

This way, all observations along the forward price curve at each time t are taken

into account. Before estimation a string λ is selected, λ = (λ

1

, λ

2

, . . . , λ

N

) with

λ

k

∼ U({1, 2, . . . , 12}), k = 1, . . . , N where λ

k

ranges from 1 to 12 to label 12

diﬀerent maturities. At each time k · ∆t in the data series, the data y

t,T

corre-

sponding to the maturity T

j

is picked if λ

k

= j. The complete-data likelihood

function thus becomes

π(y

T

λ

|θ, ξ, X) =

N

¸

k=1

φ(y

k∆t,T

λ

k

, µ

k∆t,T

λ

k

, σ

k∆t,T

λ

k

) (4.2)

where φ, µ and σ deﬁned as in Section 3.1 (Chiarella et al. [4]).

Finally, to implement the Metropolis-Hastings algorithm, the scaling factors r

θ

have to be chosen. Fixing r

θ

around 2% to 5% seemed to work well (Chiarella et

al. [4]).

33

4.3.1 One-factor model

First, the second volatility function, σ

2

(t, T) is omitted in (2.12) such that one is

left with a one-factor model. Then the parameters for the ﬁrst volatility function

σ

1

(t, T) are deﬁned as in Section 2.5.

dF(t, T)

F(t, T)

= σ

1

(t, T)dz

1

(t) (4.3)

Next, the implementation of the Gibbs sampler is veriﬁed by means of simulated

forward data. The code in Appendix A (p.) generates forward price dynamics, y

T

following formula (3.2). After which the model parameters are inferred with the

Gibbs sampler.

Figure 4.1 below shows the forward price dynamics y

T

of a one-factor regime

switching model. The transition probabilities ξ were equal to

ξ =

¸

0.9 0.1

0.7 0.3

¸

and, the parameter set θ

θ = {σ

1

1 = 0.5, σ

12

= 1, α

11

= 2, α

12

= 1.75, σ

l1

= 0.6, c = 0.8, d = 0.08, f = 0.31}

Figure 4.1: Generated forward price dynamics, y

T

34

Next, parameter estimation is carried out with the Gibbs sampler. For this

very ﬁrst stage of the implementation, the parameters for the seasonality function

c(t) are not estimated. The respective parameters c, d and f are ﬁxed at their true

values 0.8, 0.08 and 0.31.

In Appendix B (p.) one can ﬁnd the routine for the Gibbs sampler which is

applied to the generated forward price dynamics, y

T

.

4.3.2 Two-factor model

Forward price dynamics are simulated to check the implementation of the Gibbs

sampler for the two-factor model as expressed by (2.12). The dynamics y

T

are

generated calling the routine nbp 2fac.m, which is found in Appendix C (p.)

Also in the case of the two-factor model, the parameters of the seasonality

function, c(t) are initially ﬁxed. Below one can ﬁnd the routine for the Gibbs

sampler which is applied to the generated forward price dynamics, y

T

. The code

for this discrete-time sampler is provided in Appendix D (p.)

35

4.4 Numerical Results

4.4.1 One-factor model

For a two-state regime, one-factor model, about 100,000 steps were run with sim-

ulated data. A rate of 20% is chosen for the burnin which means that the ﬁrst

20% of the output is thrown away and does not contribute to the estimated values.

At this stage of the implementation, the values for the seasonality function

c(t) are kept ﬁxed. That is, the parameters c, d and f are not included in the

parameter set θ. Parameters are respectively c = 0.81, d = 0.08, f = 0.31,

which are seasonality parameters obtained from previous estimations by Chiarella

et al. [4].

Below one can ﬁnd the estimates of the transition probability matrix ξ and the

parameter set θ.

• Number of states = 2

• Transition probability matrix ξ

Simulated data

Actual Estimated

1 2 1 2

1 0.9 0.1 0.88 0.12

2 0.7 0.3 0.72 0.28

• Regime-switching parameters σ

1j

and α

1j

, (j = 1, 2)

Simulated data

Actual Estimated

j 1 2 1 2

σ

1j

0.5 1 0.47 1.01

α

1j

2 1.75 2.06 1.78

36

Figure 4.2 below shows the parameter estimates throughout the runs. Con-

vergence is reached fast for the volatility parameters σ

1j

, (j = 1, 2), but also

the values for the attenuation parameters α

1j

reach the actual values of the

underlying forward dynamics y

T

.

Figure 4.2: Path of parameter estimates for σ

1j

and α

1j

, (j = 1, 2)

• estimator for σ

l1

, σ

l1

= 0.62, with an actual value of 0.6

37

4.4.2 Two-factor model

For a two-state regime, two-factor model, about 100,000 steps were run with sim-

ulated data. Any parameters that lie within the boundaries set by the prior dis-

tributions could be chosen for the simulated forward dynamics. Here the following

parameter values were used to generate y

T

.

The transition probabilities ξ were equal to

ξ =

¸

0.8 0.2

0.6 0.4

¸

and, the parameter set θ

θ =

{σ

11

= 0.3, σ

12

= 0.8, α

11

= 1.5, α

12

= 2, σ

l1

= 0.5,

σ

21

= 0.6, σ

22

= 1.2, α

21

= 1, α

22

= 3, σ

l2

= 0.9, c = 0.8, d = 0.08, f = 0.31}

Figure 4.3 below shows the forward price dynamics y

T

of a two-factor regime

switching model.

Figure 4.3: Generated forward price dynamics, y

T

38

Next, the Gibbs sampler implemented for the two-factor regime should be able

to retrieve those values. As previously stated, a rate of 20% is chosen for the

burnin which means that the ﬁrst 20% of the output is thrown away and does not

contribute to the estimated values.

Below one can ﬁnd the estimates of the transition probability matrix ξ and the

parameter set θ.

1. With ﬁxed seasonality function c(t) Parameters are respectively c = 0.81,

d = 0.08, f = 0.31 Those seasonality parameters were obtained from previous

estimations by Chiarella et al. [4].

• Number of states = 2

• Transition probability matrix ξ

Simulated data

Actual Estimated

1 2 1 2

1 0.8 0.2 0.83 0.17

2 0.6 0.4 0.63 0.37

• Regime-switching parameters σ

1j

and α

1j

, (j = 1, 2)

Simulated data

Actual Estimated

j 1 2 1 2

σ

1j

0.3 0.8 0.37 0.78

σ

2j

0.6 1.2 0.67 1.31

α

1j

1.5 2 1.67 2.69

α

2j

1 3 1.01 3.59

39

Figures 4.4 and 4.5 below show the parameter estimates throughout

the runs. Convergence is reached fast for the volatility parameters σ

ij

,

(i, j = 1, 2). The values for the attenuation parameters α

ij

are near

the actual values of the underlying forward dynamics y

T

. One could

increase the number of runs.

Figure 4.4: Path of parameter estimates for σ

ij

, (i, j = 1, 2)

40

Figure 4.5: Path of parameter estimates for α

ij

, (i, j = 1, 2)

• estimator for σ

l1

, σ

l1

= 0.66, with an actual value of 0.6 estimator for

σ

l2

, σ

l2

= 0.83, with an actual value of 0.9

The same exercise is repeated, but now the parameters for the seasonality

function c(t) are inferred as well from the simulated forward data. The

number of runs is increased to 200,000.

2. With varying seasonality function c(t)

Now, the seasonality parameters c, d and f are included in the parameter

set θ

• Number of states = 2

41

• Transition probability matrix ξ

Simulated data

Actual Estimated

1 2 1 2

1 0.8 0.2 0.79 0.21

2 0.6 0.4 0.62 0.38

• Regime-switching parameters σ

1j

and α

1j

, (j = 1, 2)

Simulated data

Actual Estimated

j 1 2 1 2

σ

1j

0.3 0.8 0.26 0.73

σ

2j

0.6 1.2 0.53 1.19

α

1j

1.5 2 1.83 1.61

α

2j

1 3 0.94 3.30

42

Figures 4.4 and 4.5 below show the parameter estimates throughout

the runs. Convergence is reached fast for the volatility parameters σ

ij

,

(i, j = 1, 2). The values for the attenuation parameters α

ij

are near

the actual values of the underlying forward dynamics y

T

. One could

increase the number of runs.

Figure 4.6: Path of parameter estimates for σ

ij

, (i, j = 1, 2)

43

Figure 4.7: Path of parameter estimates for α

ij

, (i, j = 1, 2)

• estimator for σ

l1

, σ

l1

= 0.53, with an actual value of 0.6 estimator for

σ

l2

, σ

l2

= 0.93, with an actual value of 0.9

• estimators for seasonality function are respectively, c = 0.92, d = 0.04

and f = 0.35 with actual values of c = 0.8, d = 0.08 and f = 0.31

44

4.4.3 Historical NBP forward data

Now all pieces have been put together and tested. Finally, the Gibbs sampler for

the two-factor regime switching model is applied to historical forward NBP data.

The data sample was introduced in Section 4.1. In Appendix E (p.) one can ﬁnd

the routine for the Gibbs sampler which is applied to the sample.

A number of MCMC estimation procedures were run with diﬀerent initial values

for the respective parameters, with rather similar results. The burnin rate is

20%. About 200,000 steps were run and the following are the estimates of the

parameters. The estimates for the transition probability matrix ξ show that with

high probability the Markov Chain will stay in regime 1 for the better part of the

time horizon. Sporadically, a jump from regime 1 to regime 2 is witnessed.

• Number of states = 2

• Transition probability matrix ξ

Historical data

Estimated

1 2

1 0.8185 0.185

2 0.4327 0.5673

• Regime-switching parameters σ

1j

and α

1j

, (j = 1, 2)

Historical data

Estimated

j 1 2

σ

1j

0.3777 0.6207

σ

2j

0.5020 1.0885

α

1j

1.2080 2.0948

α

2j

1.4115 2.9067

• estimator for σ

l1

is 0.3654 estimator for σ

l2

, is 0.7833

45

• estimators for seasonality function are respectively, c = 0.6922, d = 0.3362

and f = 0.2791

These estimates can be compared to the estimates provided by Chiarella et

al. [4] for NBP forward price data that spanned from 29/09/2006 to 19/02/2008.

One could see that less time is spent in regime 2 here, which indicates that the

environment is less volatile. It could be argued that volatility levels for natural

gas have exceeded normal levels in 2008 as a result of the global ﬁnancial crisis.

• Number of states = 2

• Transition probability matrix ξ

Historical data

Estimated

1 2

1 0.8516 0.1484

2 0.7080 0.2920

• Regime-switching parameters σ

1j

and α

1j

, (j = 1, 2)

Historical data

Estimated

j 1 2

σ

1j

0.3057 0.8429

σ

2j

0.4762 1.0292

α

1j

2.0464 1.8932

α

2j

1.1533 3.2536

• estimator for σ

l1

is 0.4869 estimator for σ

l2

, is 0.6203

• estimators for seasonality function are respectively, c = 0.8121, d = 0.0781

and f = 0.3070

46

Chapter 5

Conclusion

In this essay a two-factor regime switching model for the forward price curve in

the natural gas market suggested by Chiarella et al. [4] was presented. For pa-

rameter estimation a Markov Chain Monte Carlo (MCMC) technique was applied,

introduced ﬁrst by Fr¨ uhwirth-Schnatter (Fr¨ uhwirth-Schnatter [14]) and Hahn et

al. [18]. Episodes of higher volatility are followed by episodes of lower volatility

driven by market structure changes or supply-demand imbalances. The respective

changes in regime aﬀect the whole forward curve structure.

Both the transition probabilities of these switches and the model parameters

were inferred from natural gas forward price data, which included 12 forward

curve series. The use of MCMC techniques makes the calibration of more complex

volatility functions possible. The parameter estimates for the NBP sample were

found considerably higher than the estimators found by Chiarella et al. [4]. The

data in this essay spans from 23/10/2007 to 12/03/2009, whereas Chiarella et al. [4]

presented data from 29/09/2006 to 19/02/2008. The highly volatile remainder of

2008 and also the beginning of 2009 was thus not included.

Finally, as mentioned by Chiarella et al. [4] the Gibbs sampler presented is

an oﬀ line approach. When new data becomes available, the routine is slow to

update the estimates. It is thus not suited in a live setting. Therefore, it would

be recommended to implement an on line approach, like a particle ﬁlter, such that

the volatility functions can be updated quickly from high-frequency data.

47

Appendix A

nbp 1fac.m

one-factor volatility model, nbp 1fac.m

Generates forward dynamics of a one-factor regime switching model

% parameters

%

dt=1/365; % daily time-stepping

tT=(3:-dt:0)’; % time-to-maturity

t=flipud(tT); % time

p0=[.9 .1 .7 .3]; % transition probability matrix

th0=[.5 1 1.5 1 .5]; % initial values for both states 1,2

% volatility parameters:

% \sigma_11, \sigma_12

% attenuation parameters:

% \alpha_11, \alpha_12

% long-term volatility parameter

% \sigma_l_1

c=.8; d=.08; f=.31; % seasonality parameters

ct=c+d*(1+sin(f+2*pi.*t)); % seasonality function

% sample state vector x0

%

len=size(tT,1);

x0=ones(len,1); % state 1

x0(1)=unidrnd(2);

for it=2:len;

48

if rand>p0(1,2*x0(it-1)-1)

x0(it)=2;

end

end

x=x0;

% volatility function

%

x0=[x0==1 x0==2];

sig=sum(x0.*th0(ones(1,len),1:2),2).*...

(exp(-sum(x0.*th0(ones(1,len),3:4),2).*tT)*(1-th0(5))+th0(5));

sig=ct.*sig;

% simulate path of forward returns

%

y=-0.5*dt*(sig.*sig)+sig.*randn(len,1)*sqrt(dt);

% plot

%

figure, plot(y)

title(’forward data sample, one-factor model’)

xlabel(’time t’), ylabel(’y(t,T)’)

49

Appendix B

mcmc.m

Gibbs sampler, mcmc.m

Parameter estimation of Markov switching model with MCMC

clc, clear all

% initialize

%

iter=1e4;

burnin=iter/5;

p=zeros(iter,4); % allocate

th=zeros(iter,5);

% generate simulated data

%

nbp_1fac; % call nbp_1fac.m for data

% priors

%

p(1,:)=[.64 .36 .16 .84]; % guess transition probabilities

g=p(1,:)*15; % prior expectation of

% probability matrix

th(1,:)=[.5 1 1.5 1 .5]; % initial parameter values

rg=[zeros(1,5);1.5 1.5 5 5 1 ]; % bounds for parameter values

rth=0.05; % step size parameter updates

50

% sample initial state vector x

%

x=ones(len,1); % state 1

x(1)=unidrnd(2);

for it=2:len;

if rand>p(1,2*x(it-1)-1)

x(it)=2;

end

end

% algorithm

%

th1=th(1,:);

for k=2:iter

sp=zeros(len,2); % allocate

sf=zeros(len,2);

sc=zeros(len,2);

% sample transition probability matrix p

%

n12=sum(diff(x)==1); % count transitions between states

n21=sum(diff(x)==-1);

n11=sum((x(1:end-1)==1)+(x(2:end)==1)==2);

n22=sum((x(1:end-1)==2)+(x(2:end)==2)==2);

% sample from Beta distribution

p1=betarnd([g(1,1)+n11 g(1,3)+n21],[g(1,2)+n12 g(1,4)+n22]);

p1=[p1(1) 1-p1(1) p1(2) 1-p1(2)];

p(k,:)=p1; % update

% Metropolis-Hastings algorithm

%

idx=unidrnd(5); % random parameter choice

% generate

th1(idx)=th(k-1,idx) + rth*randn;

st=[x==1 x==2];

% complete-data likelihood

51

% call mclh.m

llh=sum(log(mclh(y,st,th1,tT,dt,t,len))...

-log(mclh(y,st,th(k-1,:),tT,dt,t,len)));

% prior densities

pr=unifpdf([th1(idx) th(k-1,idx)],rg(1,idx),rg(2,idx));

% acceptance probability

alpha=min(1,llh*pr(1)/pr(2));

if rand<=alpha,th(k,:)=th1;

else th(k,:)=th(k-1,:);

end

% filtering, FFBS algorithm

%

% forward filtering

%

sp(1,:)=0.5*(p1(1:2)+p1(3:end));

sf(1,:)=sp(1,:);

sf(2:end,1)=mclh(y(2:end),[ones(len-1,1) zeros(len-1,1)],...

th(k,:),tT(2:end),dt,t(2:end),len-1);

sf(2:end,2)=mclh(y(2:end),[zeros(len-1,1) ones(len-1,1)],...

th(k,:),tT(2:end),dt,t(2:end),len-1);

for it=2:len

sf(it,:)=sf(it,:).*sp(it-1,:);

sf(it,:)=sf(it,:)/(sf(it,1)+sf(it,2));

sp(it,:)=sf(it,1)*p1(1:2)+sf(it,2)*p1(3:end);

end

% backward sampling

%

x=ones(len,1); % state 1

if rand>sf(end,1)

x(len)=2;

end

for it=len-1:-1:1

sc(it,:)=p1([x(it+1) x(it+1)+2]).*sf(it,:);

sc(it,:)=sc(it,:)/(sc(it,1)+sc(it,2));

52

if rand>sc(it,1)

x(it)=2;

end

end

th1=th(k,:); % update

end

% output

%

mu_th=mean(th(burnin+1:end,:))

mu_p=mean(p(burnin+1:end,:))

In the routine for the Gibbs sampler, the function mclh.m is called to evaluate

the complete-data likelihood for various values of the parameters. This function

is given below.

function [lh,sig]=mclh(y,x,th,tT,dt,t,T), mclh.m

Returns components of complete-data likelihood function

sig=zeros(T,2);

ct=.8+.08*(1+sin(.31+2*pi.*t));

sig(:,1)=sum(x.*th(ones(1,T),1:2),2).*(th(5)+

exp(-sum(x.*th(ones(1,T),3:4),2).*tT)*(1-th(5)));

sig=ct(:,ones(2,1)).*sig;

mu=dt*sum(sig.*sig,2);

lh=exp(-0.5*((y+0.5*mu).^2)./mu);

lh=lh./sqrt(mu);

53

Appendix C

nbp 2fac.m

two-factor volatility model, nbp 2fac.m

Generates forward dynamics of a two-factor regime switching model

% parameters

%

dt=1/365; % daily

tT=(3:-dt:0)’; % time-to-maturity

t=flipud(tT); % time

p0=[.75 .25 .85 .15]; % transition probability matrix

th0=[.5 1 1.5 1 .6 ...

.75 1.3 2 3 .8]; % initial values for 2 factors &

% both states 1,2

% volatility parameters:

% \sigma_11, \sigma_12

% attenuation parameters:

% \alpha_11, \alpha_12

% long-term volatility parameter

% \sigma_l_1

% volatility parameters:

% \sigma_21, \sigma_22

% attenuation parameters:

% \alpha_21, \alpha_22

% long-term volatility parameter

% \sigma_l_2

54

c=.8; d=.08; f=.31; % seasonality parameters

ct=c+d*(1+sin(f+2*pi.*t)); % seasonality function

% sample state vector x0

%

len=size(tT,1);

x0=ones(len,1); % state 1

x0(1)=unidrnd(2);

for it=2:len;

if rand>p0(1,2*x0(it-1)-1)

x0(it)=2;

end

end

x=x0;

% volatility function

%

x0=[x0==1 x0==2];

sig(:,1)=sum(x0.*th0(ones(1,len),1:2),2).*...

(exp(-sum(x0.*th0(ones(1,len),3:4),2).*tT)*(1-th0(5))+th0(5));

sig(:,2)=sum(x0.*th0(ones(1,len),6:7),2).*...

(th0(10)-exp(-sum(x0.*th0(ones(1,len),8:9),2).*tT));

sig=ct(:,ones(2,1)).*sig;

% simulate path of forward returns

%

y=-0.5*dt*sum(sig.*sig,2)+sum(sig.*randn(len,2)*sqrt(dt),2);

% plot

%

figure, plot(y)

title(’forward data sample, two-factor model’)

xlabel(’time t’), ylabel(’y(t,T)’)

55

Appendix D

mcmc.m

Gibbs sampler, mcmc.m

Parameter estimation of Markov switching model with MCMC

clc, clear all

% initialize

%

iter=1e5;

burnin=iter/5;

p=zeros(iter,4); % allocate

th=zeros(iter,10);

% generate simulated data

%

nbp_2fac; % call nbp_2fac.m for data

% priors

%

p(1,:)=[.64 .36 .16 .84]; % guess transition probabilities

g=p(1,:)*15; % prior expectation of

% probability matrix

th(1,:)=[.25 .75 2 2 .5 ...

.5 1 2 2 1]; % initial parameter values

rg=[zeros(1,10);1.5 1.5 5 5 1 ...

1.5 1.5 5 5 1]; % bounds for parameter values

56

rth=0.025; % step size parameter updates

% sample initial state vector x

%

x=ones(len,1); % state 1

x(1)=unidrnd(2);

for it=2:len;

if rand>p(1,2*x(it-1)-1)

x(it)=2;

end

end

% algorithm

%

th1=th(1,:);

for k=2:iter

sp=zeros(len,2); % allocate

sf=zeros(len,2);

sc=zeros(len,2);

% sample transition probability matrix p

%

n12=sum(diff(x)==1); % count transitions between states

n21=sum(diff(x)==-1);

n11=sum((x(1:end-1)==1)+(x(2:end)==1)==2);

n22=sum((x(1:end-1)==2)+(x(2:end)==2)==2);

% sample from Beta distribution

p1=betarnd([g(1,1)+n11 g(1,3)+n21],[g(1,2)+n12 g(1,4)+n22]);

p1=[p1(1) 1-p1(1) p1(2) 1-p1(2)];

p(k,:)=p1; % update

% Metropolis-Hastings algorithm

%

idx=unidrnd(10); % random parameter choice

% generate

th1(idx)=th(k-1,idx) + rth*randn;

st=[x==1 x==2];

57

% complete-data likelihood

% call mclh.m

llh=sum(log(mclh(y,st,th1,tT,dt,t,len))...

-log(mclh(y,st,th(k-1,:),tT,dt,t,len)));

% prior densities

pr=unifpdf([th1(idx) th(k-1,idx)],rg(1,idx),rg(2,idx));

% acceptance probability

alpha=min(1,llh*pr(1)/pr(2));

if rand<=alpha,th(k,:)=th1;

else th(k,:)=th(k-1,:);

end

% filtering, FFBS algorithm

%

% forward filtering

%

sp(1,:)=0.5*(p1(1:2)+p1(3:end));

sf(1,:)=sp(1,:);

sf(2:end,1)=mclh(y(2:end),[ones(len-1,1) zeros(len-1,1)],...

th(k,:),tT(2:end),dt,t(2:end),len-1);

sf(2:end,2)=mclh(y(2:end),[zeros(len-1,1) ones(len-1,1)],...

th(k,:),tT(2:end),dt,t(2:end),len-1);

for it=2:len

sf(it,:)=sf(it,:).*sp(it-1,:);

sf(it,:)=sf(it,:)/(sf(it,1)+sf(it,2));

sp(it,:)=sf(it,1)*p1(1:2)+sf(it,2)*p1(3:end);

end

% backward sampling

%

x=ones(len,1); % state 1

if rand>sf(end,1)

x(len)=2;

end

for it=len-1:-1:1

58

sc(it,:)=p1([x(it+1) x(it+1)+2]).*sf(it,:);

sc(it,:)=sc(it,:)/(sc(it,1)+sc(it,2));

if rand>sc(it,1)

x(it)=2;

end

end

th1=th(k,:); % update

end

% output

%

mu_th=mean(th(burnin+1:end,:))

mu_p=mean(p(burnin+1:end,:))

In the routine for the Gibbs sampler, the function mclh.m is called to evaluate

the complete-data likelihood for various values of the parameters. This function

is given below.

function [lh,sig]=mclh(y,x,th,tT,dt,t,T), mclh.m

Returns components of complete-data likelihood function

sig=zeros(T,2);

ct=.8+.08*(1+sin(.31+2*pi.*t));

sig(:,1)=sum(x.*th(ones(1,T),1:2),2).*(th(5)+

exp(-sum(x.*th(ones(1,T),3:4),2).*tT)*(1-th(5)));

sig(:,2)=sum(x.*th(ones(1,T),6:7),2).*(th(10)-

exp(-sum(x.*th(ones(1,T),8:9),2).*tT));

sig=ct(:,ones(2,1)).*sig;

mu=dt*sum(sig.*sig,2);

lh=exp(-0.5*((y+0.5*mu).^2)./mu);

lh=lh./sqrt(mu);

59

Appendix E

mcmc.m

Gibbs sampler, mcmc.m

Parameter estimation of Markov switching model with MCMC

clc, clear all

% initialize

%

iter=2*1e2;

burnin=iter/5;

p=zeros(iter,4); % allocate

th=zeros(iter,13);

% generate simulated data

%

load f, load tT

y=log(f(2:end,1:12))-log(f(1:end-1,1:12));

tT=tT(1:end-1,1:12);

dt=1/252;% daily

% priors

%

p(1,:)=[.64 .36 .16 .84]; % guess transition probabilities

g=p(1,:)*15; % prior expectation of

% probability matrix

60

th(1,:)=[.3 .8 2 2 .5 ...

.5 1 1 3 .7 .8 .08 .3]; % initial parameter values

rg=[zeros(1,13);1.5 1.5 5 5 1 1.5 1.5 5 5 1 1 1 1]; % bounds for parameter values

rth=0.03; % step size parameter updates

% implement ’randomized’ algorithm

%

dim=size(y);

lam=unidrnd(dim(2),dim(1),1);

sample = sub2ind(dim, 1:dim(1), lam’);% use linear indexing

% construct return & maturity vectors with

% corresponding data points

y=y(sample)’;

tT=tT(sample)’;

t=flipud(tT);% time

% draw x

len=size(tT,1);

x=ones(len,1);

x(1)=unidrnd(2);

for it=2:len;

if rand>p(1,2*x(it-1)-1),x(it)=2;end

end

% algorithm

%

th1=th(1,:);

for k=2:iter

sp=zeros(len,2); % allocate

sf=zeros(len,2);

sc=zeros(len,2);

% sample transition probability matrix p

%

61

n12=sum(diff(x)==1); % count transitions between states

n21=sum(diff(x)==-1);

n11=sum((x(1:end-1)==1)+(x(2:end)==1)==2);

n22=sum((x(1:end-1)==2)+(x(2:end)==2)==2);

% sample from Beta distribution

p1=betarnd([g(1,1)+n11 g(1,3)+n21],[g(1,2)+n12 g(1,4)+n22]);

p1=[p1(1) 1-p1(1) p1(2) 1-p1(2)];

p(k,:)=p1; % update

% Metropolis-Hastings algorithm

%

idx=unidrnd(13); % random parameter choice

% generate

th1(idx)=th(k-1,idx) + rth*randn;

st=[x==1 x==2];

% complete-data likelihood

% call mclh.m

llh=sum(log(mclh2(y,st,th1,tT,dt,t,len))...

-log(mclh2(y,st,th(k-1,:),tT,dt,t,len)));

% prior densities

pr=unifpdf([th1(idx) th(k-1,idx)],rg(1,idx),rg(2,idx));

% acceptance probability

alpha=min(1,llh*pr(1)/pr(2));

if rand<=alpha,th(k,:)=th1;

else th(k,:)=th(k-1,:);

end

% filtering, FFBS algorithm

%

% forward filtering

%

sp(1,:)=0.5*(p1(1:2)+p1(3:end));

sf(1,:)=sp(1,:);

sf(2:end,1)=mclh2(y(2:end),[ones(len-1,1) zeros(len-1,1)],...

th(k,:),tT(2:end),dt,t(2:end),len-1);

62

sf(2:end,2)=mclh2(y(2:end),[zeros(len-1,1) ones(len-1,1)],...

th(k,:),tT(2:end),dt,t(2:end),len-1);

for it=2:len

sf(it,:)=sf(it,:).*sp(it-1,:);

sf(it,:)=sf(it,:)/(sf(it,1)+sf(it,2));

sp(it,:)=sf(it,1)*p1(1:2)+sf(it,2)*p1(3:end);

end

% backward sampling

%

x=ones(len,1); % state 1

if rand>sf(end,1)

x(len)=2;

end

for it=len-1:-1:1

sc(it,:)=p1([x(it+1) x(it+1)+2]).*sf(it,:);

sc(it,:)=sc(it,:)/(sc(it,1)+sc(it,2));

if rand>sc(it,1)

x(it)=2;

end

end

th1=th(k,:); % update

% debug

%th(k,6)

end

% output

%

mu_th=mean(th(burnin+1:end,:))

mu_p=mean(p(burnin+1:end,:))

% plot

%

% volatility parameters

subplot(2,2,1), plot(th(:,1))

63

subplot(2,2,2), plot(th(:,2))

subplot(2,2,3), plot(th(:,6))

subplot(2,2,4), plot(th(:,7))

% attenuation parameters

figure

subplot(2,2,1), plot(th(:,3))

subplot(2,2,2), plot(th(:,4))

subplot(2,2,3), plot(th(:,8))

subplot(2,2,4), plot(th(:,9))

In the routine for the Gibbs sampler, the function mclh2.mis called to evaluate

the complete-data likelihood for various values of the parameters. This function

is given below.

function [lh,sig]=mclh2(y,x,th,tT,dt,t,T)

Returns components of complete-data likelihood function

sig=zeros(T,2);

%ct=.8+.08*(1+sin(.31+2*pi.*t));

ct=th(11)+th(12)*(1+sin(th(13)+2*pi.*t));

sig(:,1)=sum(x.*th(ones(1,T),1:2),2).*(th(5)+exp(-sum(x.*th(ones(1,T),3:4),2).*tT)*(1-th(5)));

sig(:,2)=sum(x.*th(ones(1,T),6:7),2).*(th(10)-exp(-sum(x.*th(ones(1,T),8:9),2).*tT));

sig=ct(:,ones(2,1)).*sig;

mu=dt*sum(sig.*sig,2);

lh=exp(-0.5*((y+0.5*mu).^2)./mu);

lh=lh./sqrt(mu);

64

Bibliography

[1] Benth, F. & Koekebakker, S. (2008), “Stochastic modeling of ﬁnancial electric-

ity contracts”, Energy Economics 30, 1116-1157.

[2] Breslin, J., Clewlow, L., Kwok, C. & Strickland, C. (2008),“Gaining from

complexity: MFMC models”, Energy Risk, April, 60-64.

[3] Carlin, B. & Polson, N. (1992), “Monte Carlo Bayesian methods for discrete

regression models and categorical time series”, Bayesian Statistics 4, 577-586.

[4] Chiarella, C., Clewlow, L. & Kang, B. (2009) “Modelling and estimating the

forward price curve in the energy market”,Working Paper.

[5] Chib, S. (1995), “Marginal likelihood from the Gibbs output”, Journal of the

American Statistical Association 90, 1313-1321.

[6] Chib, S. (1996), “Calculating posterior distributions and modal estimates in

Markov Mixture models”, Journal of Econometrics 75, 79-97.

[7] Clewlow, L. & Strickland, C. (1999), “A multi-factor model for energy deriva-

tives”,

QFRC Research Paper Series 28, University of Technology, Sydney.

[8] Davis, M. (1984), “Piecewise-deterministic Markov processes: a general class

of non-diﬀusion stochastic models”, Journal of Royal Statistical Society B, 46,

353–88.

[9] de Jong, C. & R. Huisman (2002), “Option formulas for mean-reverting power

prices with spikes.”, Working Paper, Rotterdam School of Management at Eras-

mus University.

[10] Deng, S. (2000), “Pricing electricity derivatives under alternative stochastic

spot price models.”, Proceedings of the 33rd Hawaii International Conference

on System Sciences.

65

[11] Di Masi, G.B., Kabanov, Yu. M. & Runggaldier W.J. (1994),“Mean-variance

hedging of options on stocks with Markov volatilities”, Theory of Probability

and its Applications 39, 172-182.

[12] Elliott, R. Aggoun, L. & Moore, J. (1995), “Hidden Markov Models: estima-

tion and control, applications of mathematics”, Springer-Verlag, New York.

[13] Elliott, R. & Wilson, C. (2001), “The term structure of interest rates when

a Markov chain is driving drift and volatility parameters of the short rate

diﬀusion process”, Working Paper.

[14] Fr¨ uhwirth-Schnatter, S. (2006), “Finite Mixture and Markov Switching Mod-

els”, Springer, New York.

[15] Gibson, R. & Schwartz, E.S. (1990), “Stochastic convience yield and the pric-

ing of oil contingent claims, ”

The Journal of Finance 45, 959-976.

[16] Gilks, W.R., Richardson, S. & Spiegelhalter D.J. (1998), “Markov Chain

Monte Carlo in Practice”, Chapman & Hall, London.

[17] Goldfeld, S.M. & Quandt, R.E. (1973), “A Markov model for switching re-

gressions”,Journal of Econometrics 1, 3-15.

[18] Hahn, M., Fr¨ uhwirth-Schnatter, S. & Sass, J. (2007), “Markov Chain Monte

Carlo methods for parameter estimation in multidimensional continuous time

Markov switching models”, RICAM, Linz 2007-09.

[19] Hamilton, J.D. (1989), “A New approach to the economic analysis of nonsta-

tionary time series and the business cycle”, Econometrica 57, 357-384.

[20] Hamilton, J.D. (1990),“Analysis of time series subject to changes in regime”,

Journal of Econometrics 45, 39-70.

[21] Hansen, A.T. & Poulsen, R. (2000), “A simple regime switching term structure

model”, Finance and Stochastics 4, 409-29.

[22] Heath, D., Jarrow, R. & Morton, A. (1992), “Bond pricing and the term

structure of interest rates: a new methodology”, Econometrica 60, 77–105.

[23] Johannes, M. & Polson, N. (2002). “MCMC methods for continuous-time

ﬁnancial econometrics”, Handbook of Financial Econometrics.

[24] Naik, V. (1993),“Option valuation and hedging strategies with jumps in the

volatility of asset returns”, Journal of Finance 48, 1969-1984.

66

[25] Pilipovic, D. (2007), “Energy risk: valuing and managing energy derivatives”,

Second edition, McGraw-Hill.

[26] Rambharat, B.R., Brockwel A.E. & Seppi, D.J. (2005), “A threshold autore-

gressive model for wholesale electricity prices”, Journal of the Royal Statistical

Society C, 54, 287-299.

[27] Scott, S. (2002), “Bayesian methods for Hidden Markov models”, The Journal

of the American Statisctical Association 97, 337-351.

[28] Seifert, J. & Uhrig-Homburg, M. (2007), “ Modelling jumps in electricity

prices: theory and empirical evidence”, Review of Derivatives Research 10,

59-85.

[29] Valchev, S. (2004), “Stochastic volatility Gaussian Heath-Jarrow-Morton

models”, Applied Mathematical Finance 11, 347-368.

67

Waterloo, Ontario, Canada, 2010

I hereby declare that I am the sole author of this paper. This is a true copy of the paper, including any required ﬁnal revisions, as accepted by my examiners. I understand that my paper may be made electronically available to the public.

ii

A higher volatile environment for natural gas could be explained by the global ﬁnancial crisis which unfolded during the period of observation. more time is spent in a highvolatility regime. regime switching model is proposed to model forward price dynamics. That is. over the span of the data period. A Markov Chain Monte Carlo (MCMC) technique is used for estimation of the parameter set and the transition probability matrix. Compared to a previous study it is found that. for the better part of the time horizon the Markov Chain still settles in regime 1. A two-factor. A study is performed for a number of 2 states using data from NBP. Although.Abstract In this essay. The model is a Markov Switching model: the parameters. found in the respective volatility functions take diﬀerent values for diﬀerent states of the world. while the volatility and attenuation parameters are similar. iii . the Markov Chain stays in regime 2 more often. modeling of natural gas price forward curves is discussed. the state transitions are driven by a ﬁnite state Markov Chain. Further.

. . . . . . . 3. . . .2 Sample the transition matrix . . . . . . . . . . . . . . . . . .forward price relationship . . 4 Implementation 4. . . . 3. . .2 Two-factor model . . . . . . . . . 2. . . . . . . . . . . 3 Estimation 3. . . . . . .1 One-factor model . . . . . . . . . . . . . . . .3 Sample the model parameters . . . . . .1 Data transformation . . . . . . . . . . 1. . . . . . . . . . . . . . . . . . . 2. . . . . . .2 Choosing the prior . . . . . . . . .1 Data . . . 2. . . . . . . . . . . . . . . .1 Multi-factor single-commodity model . . . . . . . . . . . . . . . . . . iv . 4. . . . . . . . . . . .2 Bayesian estimation for a Markov switching model 3.3 Seasonality adjustment . . . . . . . . . . . . . . . . . . . . . . . 3. . 3. . . . . . . . . . . . . . 2 Forward price curve model 2. . . . . . . . . . . . . . . . . . . . .2 Spot . . . . . . . . . .4. . . . . . . . . 3. . . . . . . . .4. . . . . . . . . . . . . . . . .3.3 Running the Gibbs sampler 4. . . . .Contents List of Tables List of Figures 1 Introduction 1. . . . . . . . . . . 3. . . . . 4. . . .3 Prior distributions . . . . . .4 Multi-factor multi-commodity model . .1 Full conditional posterior distributions .4. . . . . . . . . .3. model . . . .2 Literature review . . . . . . . 2. . . . . . . . . . . . . . 4. . . . .4 Markov Chain state simulation . . . . . . . . . . . . . . . . . . .4 Gibbs sampler . . . . . . . . . . .5 Two-factor regime switching forward price curve vi vii 1 2 9 13 13 18 18 19 20 22 22 23 24 25 25 26 27 29 32 32 32 33 34 35 . . . . .1 Stylized facts of energy forward price dynamics . . . . . . . . . . . . . . . . . .4. . . . . . . . . . . . . . . . . . . . . . . .

. .m D mcmc. . . . . . . . . . . . .4. . . . 4. . . . . . . . . . 36 36 38 45 47 48 50 54 56 60 65 5 Conclusion A nbp 1fac. . . . . . . . .4. . . . 4. . . 4. . . . . . . . . .m E mcmc. . .m Bibliography v .4. . . .m C nbp 2fac. . . . .3 Historical NBP forward data . . . . . . .m B mcmc. . . . . . . . .4 Numerical Results . .2 Two-factor model . . . . . . . . .1 One-factor model . . . . . . . . .4. . .

List of Tables vi .

. (i. . . . . (j = 1. yT . . . j = 1. . . . . . . . . . . . . . F (t. . Path of parameter estimates for σ1j and α1j . . F (t. . . 5 6 8 Annualized covariance surface for NBP data F (t. . . . . . . T ) .7 Forward price curves from Oct-2007 to Mar-09. . . . . . . . . . . . . 2) . . . . . . . T ) . . . . . . . . .6 4. . . . . Path of parameter estimates for σij . . 34 37 38 40 41 43 44 vii . . . (i. . . . . . . . . 2) . T ) . . . 2) Generated forward price dynamics. . . . Path of parameter estimates for σij . . 2) . .4 4. . . . . . . . . . . . . . Log diﬀerences of forward prices yT . . . . . Path of parameter estimates for αij . yT . (i. . . . j = 1. 16 First three volatility functions for NBP data F (t.2 4. . . . . . 2) .3 4. . (i. . Path of parameter estimates for αij . . . . . .List of Figures 1. .1 4. j = 1. . Diﬀerent forward price curves.3 2. . .5 4. . j = 1. . .1 2. T ) . . . 17 Generated forward price dynamics. . .2 4. . . . . .1 1. . .2 1. . .

the estimation procedure is applied to real market data. [4]. A common modeling framework is provided that is consistent not only with the forward curve prices observed in the market but also the volatilities and correlations of forward price returns. Chapter 4. Finally. in Chapter 2 the general multi-factor multi-commodity model by Breslin et al. [4] is replicated with updated natural gas forward price data. The model was initially proposed by Chiarella et al. in Chapter 5 conclusions are drawn and suggestions for further research are discussed. [18]. a number of numerical examples and calibration results from simulated data are considered. The paper is built as follows. [4] where the parameters of the volatility functions are allowed to take diﬀerent values in diﬀerent states of the world. Here. Next. 1 . The dynamics of the two volatility functions are thus driven by shifts in the Markov Chain. a brief overview of theoretical and practical work by other authors is provided. In a following chapter. The model discussed and implemented is a two-factor regime switching model suggested by Chiarella et al. Also. The algorithms impleu mented are extensively discussed and code of the respective routines is supplied.Chapter 1 Introduction This paper considers the problem of modeling and estimating the forward price curve in natural gas markets. First. It is then important to incorporate those diﬀerences in the model to better explain the forward price dynamics of energy assets. The parameter estimation procedure is then explained in Chapter 3. The respective states are then governed by a Markov Chain. Energy markets diﬀer from non-physical. the analysis by Chiarella et al. the properties of energy forward prices are discussed. ﬁnancial markets. in Chapter 1. [2] is introduced after which a two-factor regime switching model for the natural gas forward price curve is described. Subsequently. A Bayesian approach is taken by means of a Markov Chain Monte Carlo (MCMC) method provided by Fr¨hwirth-Schnatter [14] and Hahn et al.

one expects natural gas prices to peak during winter and drop to lows in summer period. On the other hand. called mean level. the magnitude of these peaks and troughs.1 Stylized facts of energy forward price dynamics Energy markets. The 2 . the hurricanes Katrina and Rita damaged a number of natural gas processing facilities on the US Gulf Coast. in energy markets mean reversion is much stronger and related to various. The loss has delayed the recovery of natural gas production in the area. As a result. hence. or the degree of seasonality. a commodity price or a historical interest rate. Below. how fast events go away (Pilipovic [25]). to which the market for natural gas belongs. These seasonality eﬀects are recurring and. for example. Events that produce supply-demand imbalances could be wars. • Seasonality One of the major fundamental price drivers in energy markets is weather. hurricanes or other headline-grabbing events. Or. incorporated in observed forward prices (Pilipovic [25]). These market characteristics should be captured to model eﬃciently the evolution of natural gas forward curves. dynamics of production. diﬀer from nonphysical markets such as the markets of interest rates and equities. In the case of energy commodities mean-reversion depends on how fast the market supply side responds to certain events. Natural gas is consumed mostly during the winter. also. will vary according to the region. A comprehensive overview of the various supply and demand drivers of energy markets and their impacts on the prices and volatilities of the respective markets can be found in Pilipovic [25]. Further. The heating demand in the state of Massachusetts is expected to surpass the heating demand for Florida. could be a return on equity. On the demand side. consumption and storage. price spikes occurred in the spot and short-term forward markets. Most of these diﬀerences can be traced back to supply and demand fundamentals. the main features of energy forward price dynamics are presented. In ﬁnancial markets the actual rate of mean reversion is rather weak and tied to economic cycles.1. • Mean reversion Mean reversion is the process of a market returning to its equilibrium price level. there are considerable seasonality eﬀects of residential users. diﬀerent drivers. All drivers which are not found in the traditional markets. Therefore. This is witnessed in most ﬁnancial and physical markets where the equilibrium level. In 2005. but longer-term contracts did not move dramatically.

For example. The observations span over a year with prices at times t from 23/10/2007 to 12/03/2009. Throughout the essay. T ). Further. as revealed by the forward prices. in order to obtain the forward dynamics yt. The latter two characteristics demonstrate that the issue of storage causes energy prices to display a split personality. As a result. daily observations for the forward prices were obtained with maturities T ranging from July 2009 to September 2012. forward quarter. the log diﬀerence transform is applied to the original data F (t. It is the most liquid gas trading point in Europe. prices will easily reach very elevated levels (Pilipovic [25]). when there is no natural gas to go around. So while energy markets share some properties with traditional ﬁnancial markets. And these should be taken into account when modeling natural gas forward dynamics (Pilipovic [25]). and long-term forward prices reﬂect behavior of future potential energy. Natural gas at NBP trades on a forward month. 3 .T for every maturity T . long-term forward prices reveal a rather stable equilibrium price level.and long-term portions of the energy forward price curves tend to be driven by diﬀerent market factors with usually very little or no relationship (Pilipovic [25]). Especially spot and short forwards exhibit high levels of volatility.mean reversion. For parameter estimation of the chosen model. T ). thus depended on how fast the production side could restore the supply imbalance (Pilipovic [25]). This data is represented by F (t. This so-called storage limitation problem is causing day-to-day volatility which is high compared to ﬁnancial markets. overcapacity in natural gas markets will result in distressed prices and its impact will depend on how long the overcapacity is expected to last. Where short-term forward prices are the result of energy in storage. which is the British virtual trading location operated by TSO National Grid. It can be expected that in the long run supply and demand will be balanced and. they have unique and challenging workings. Expectations of market production and costs in the long run will be expressed in the levels and yields of long-term forward prices. Likewise. Although spot prices show extremely high volatility. • Decreasing term structure of forward curve volatility Storage limitation is thus a major volatility driver. hence. the short. the volatilities of forward prices decrease signiﬁcantly with increasing maturities. • High volatility Production and storage are two supply drivers which are nonexistent in ﬁnancial markets. The natural gas prices modeled are forward prices for the National Balancing Point (NBP). forward season or year forward basis and prices are expressed in pence (GBp) per therm. covering all entry and exit points in mainland Britain.

4 .T for each maturity T along all points in time t.the notation yT is used to represent the forward dynamics yt.

T ) and yT respectively. Figure 1.2 below show the behavior of F (t.Figures 1.1: Forward price curves from Oct-2007 to Mar-09.1 and 1. F (t. T ) 5 .

Figure 1.2: Log diﬀerences of forward prices yT 6 .

It is therefore easy to see that a regime switching model could be suited to approximate this behavior. Finally. after which things turn back to normal and a more stable price pattern emerges. natural gas for delivery further out in time is usually more expensive than delivery in the near time. 7 . Also. Such an increasing price curve is called contango. Or any combination of contango and backwardation could occur along the forward price curve. Although diﬀerent shapes could occur such as a decreasing path for the forward curve which is called backwardation. the forward curves spike during a certain period.At every point in time t a seasonal pattern can be distinguished with higher prices for forward deliveries in Winter compared to deliveries in Summer. The diﬀerence is explained by the carry. that is expenses incurred for storage and ﬁnancing when the commodity is bought at the spot price and delivered at a later point in time.

3: Diﬀerent forward price curves. F (t.3 depicts some of the forward price curves observed. Figure 1. T ) 8 .Figure 1.

[11]. Therefore. In Hamilton [20] a vector autoregression model is put forward subject to occasional discrete shifts. This set-up is applied to a model for a housing market in disequilibrium. Further.1. Episodes of dollar appreciation relative to other currencies are followed by episodes of dollar depreciation. An unobserved Markov process is assumed to govern the regime. between an appreciation and depreciation regime. Two regimes are distinguished: if there is excess demand. A regime switching model where the transitions are governed by a Markov process is called a Markov Switching model. In Hamilton [19] the approach by Goldfeld and Quandt [17] is used to describe exchange rate dynamics. in a regime switching model the dollar rate is allowed to switch. it lies on the demand function.2 Literature review In order to model the gas forward curve. a process where the current state depends only on the state before. Goldfeld and Quandt [17] propose a regression system of demand and supply functions thought to be switching between the two equations or regimes. For maximum likelihood estimates of the respective parameters. Applications of Markov regime switching processes to asset price volatility modeling can be found in contributions by Naik [24] and Di Masi et al. It is considered a useful approach because many economic time series are known to exhibit dramatic breaks in their behavior. Hamilton [19] and [20] extends the approach to asset prices. In a seminal paper. a process that governs the transition has to be deﬁned. diﬀerent behavior is assumed in one subsample or regime to another. Since the prevailing regime is not directly observable. when modeling. They also could be regarded as events of a certain duration in which the dynamics of ﬁnancial time series might behave diﬀerently from what is seen outside these periods. a regime switching model is proposed. where a discrete-valued Markov process governs the shifts. 9 . Therefore. one has to ﬁnd out when the shifts occurred and estimate parameters characterizing the diﬀerent regimes and the probabilities for the transition between regimes. major exogenous economic events such as OPEC oil shocks aﬀect ﬁnancial time series. the observed point lies on the supply function and if there is an excess demand. Next. Changes in asset prices are driven by speciﬁc identiﬁable events. For example. is called a Markov process. with a certain probability. There has been an enormous amount of theoretical and practical work on regime switching models. an EM algorithm is applied.

that is the volatility function is non-stochastic. The class of piecewisedeterministic processes. which is only one point of the volatility curve. Markov Chain models for the instantaneous short-term interest rate were introduced by. Fixed income models have been an important source for applications to energy price modeling. one starts out with a stochastic model for the spot interest rate and derives bond prices from this short rate based on no-arbitrage principles. In the ﬁrst paper. The model is an extension of the class of deterministic volatility HJM models to the wider class of HJM models with piecewise-deterministic volatility. these modeling approaches for ﬁxed income markets could be applied to energy markets. In between jumps the volatility follows an almost deterministic process. First. One could take two approaches for stochastic modeling of ﬁxed income markets. Di Masi et al. Since commodities trade both in spot and forward markets. The volatility modeled is stochastic only through its dependence 10 . shifts in corporate strategy and changes in economic policy. only the drift rate of the short rate was modeled by a continuous Markov chain. Hansen and Poulsen [21] and Elliott and Wilson [13]. but a Markov Chain stochastic volatility HJM model is introduced. Those jumps are driven by various unsystematic and systematic events. For example. It means that forward rates are modeled directly. The work of Valchev [29] builds on that of Elliott and Wilson [13]. a volatility model that captures the outcomes of such events is proposed.The volatility of risky assets is aﬀected by random and discontinuous shifts over time. [11] consider the problem of hedging an European call option for a diﬀusion model where drift and volatility are functions of a Markov jump process. Whereas Elliott and Wilson [13] extended this approach to the case when both the drift rate and the volatility of the short rate are driven by a common Markov Chain. one could specify the complete yield curve dynamics directly which is suggested by the HJM approach. especially the Heath-Jarrow-Morton (HJM) model by Heath et al. introduced by Davis [8]. The Markov Chain speciﬁcation allows for jump discontinuities and captures the various shapes of the term structure of volatilities as well. not merely the volatility of the short rate. [22]. amongst others. In order to hedge claims contingent on risky assets. Also. The energy forward price curve exhibit features similar to forward interest rate dynamics. the evolution of the whole term structure of volatilities is explored. Examples are mergers and acquisitions. Alternatively. provides a suitable framework for modeling the dynamics of the volatility term structure.

on the Markov Chain. Fr¨hwirth-Schnatter u [14] and Fr¨hwirth-Schnatter & Sass [18] further extend the approach and found u that the MCMC framework outperformed the corresponding EM algorithm. This process only approaches the actual jumps with jumps over a ﬁnite set of values but permits the use of stochastic calculus for continuous Markov chains Elliot et al. [26] which estimates a discrete time model for electricity prices using a Markov Chain Monte Carlo (MCMC) approach. most of existing literature focuses on developing realistic spot price markets. Next. for the estimation of the parameters of the proposed volatility functions a Bayesian solution is proposed. Elliot et al. The Bayesian way to tackle the inference problem is to come up with the distribution of parameters and latent variables conditional on observed data. Therefore. The class of piecewise deterministic processes is retained where the volatility functions are speciﬁed explicitly and the coeﬃcients switch values dependent on the Markov Chain. MCMC techniques are used to explore these distributions. An application to energy markets was ﬁrst found in Rambharat et al. In energy markets modeling. Deng [10] and de Jong & Huisman [9]). for example. the MCMC set-up and respective algorithms suggested by Fr¨hwirth-Schnatter [14] and Hahn. various regime-switching models are calibrated to electricity spot prices (see. [12]. is in the spirit of Davis [8]. Based on a stochastic model for the time evolution of the spot price. Finally. Johannes & Polson [23] provide a general algorithm based on the work by Scott [27]. forward dynamics are derived calling arbitrage theory. u Fr¨hwirth-Schnatter & Sass [18] are implemented to estimate the parameters of the u 11 . Also Seifert & Uhrig-Homburg [28] follow a similar approach to model European electricity spot prices. In this essay. [12] and Valchev [29]. There were early contributions by Carlin and Polson [3] and Chib [5] & [6]. Both the volatility functional form and Markov switching were introduced for electricity markets by Benth & Koekebakker [1] where various diﬀerent volatility dynamics of forward curve models were speciﬁed based on the HJM approach. The result is a stochastic model that speciﬁes directly the dynamics of the forward contracts traded in the natural gas markets. The approach taken in this essay. A forward ﬁltering backward sampling (FFBS) algorithm is applied to the case of regime-switching models. [4]. based on the framework provided by Chiarella et al. A process in the class of piecewise-deterministic processes is the continuous-time homogeneous Markov Chain with a ﬁnite number of jump times. There has been a fair amount of theoretical and practical work on regime-switching models using MCMC methods.

[4] for the estimation of natural gas forward prices which is explained thoroughly and deployed in this essay. 12 . This is also the framework adopted by Chiarella et al.model including the transition probabilities of the Markov Chain from all available forward curves on the market.

2. However. [2]). a single factor. [2]). T ) = σ(t. It determines the magnitude and direction of the single random shock that drives changes in the forward curve. z(t) is an independent Brownian motion. Further.1). multi-commodity (MFMC) model is introduced. Although the separate price curves usually move up and down together. 13 . more than one single factor of uncertainty needs to be introduced to capture forward curve changes other than parallel moves along the curve.1) Here.Chapter 2 Forward price curve model In this chapter a general multi-factor. as incorporated in (2. The volatility function could be interpreted as the the time t volatility of the T maturity forward price return. It is the sole source of uncertainty and is associated with a volatility function σ(t. T )dz(t) F (t. the term F (t. dF (t. T ) (2. in the next section the process of parameter estimation from historical data is explained. T ) stands for the forward price at time t with expiry T . Subsequently.1 Multi-factor single-commodity model From the stylized facts detailed above in Section 1. both parts of curve change shape in diﬀerent ways (see Breslin et al. T ). Therefore. This can be done by adding independent Brownian motions (Breslin et al. And.1 it is clear that forward prices of diﬀerent maturities are not perfectly correlated. the front end of the curve displays much more volatility than the end of the curve. is not suﬃcient to explain the behavior witnessed in the markets.

which renders the following forward curve dynamics: 1 ∆ log F (t. In our data sample. The respective volatility functions now deﬁne the magnitude and direction of multiple shocks that trigger changes along all points on the forward curve. dzi (t).2) will represent changes in shapes where diﬀerent parts of the forward curve will move in diﬀerent ways (Breslin et al. only a few of these will be signiﬁcant for explaining the variation in the forward curve. Therefore.3) 14 . T )dzi (t) i=1 (2.2). t + τj ) ∆t + i=1 i=1 2 σi (t. For every source of risk there is a correspondent volatility function σi (t. dz2 (t) and dz3 (t) correspond to the functions σ1 (t. Then the eigenvectors of the covariance matrix yield approximate the factors governing changes in the forward curve (Breslin et al. As a result. The respective volatility functions can easily be obtained from time series analysis. T ) = F (t. Three independent Brownians. [2]). dz1 (t). In order to start estimating the volatility functions.2) for a single commodity with n factors is rewritten. [2]). (2. t + τj ) = − 2 n n σi (t. Equation (2. In practice. Ito’s lemma is applied to (2. However. 12 diﬀerent contracts are included. The ﬁrst function is positive for all maturities which implies that a positive shock to the system causes all prices to shift up. The second most important factor is a tilt factor which causes the short and long ends of the curve to move in opposite directions. t + τj )∆zi (2. the third factors is a bending factor which causes the long and short ends to move opposite to the middle. One method that can be applied is principal components analysis (PCA) or eigenvector decomposition of the covariance matrix of the forward returns. T ) which respectively act to shift. represented by F (t.The stochastic diﬀerential equation (SDE) below represents a general multifactor model of the forward curve: dF (t. there are 12 factors that can explain the variance of the evolution of the curve.σ2 (t. tilt and bend the forward curve. T ) and σ3 (t. T ). A typical example of a multi-factor model is a model with three risk factors. T ) n σi (t. T ). T ). Sample covariance values between pairs of forward price returns are calculated. it is found that a number of three factors is usually adequate to capture the forward price dynamics (Breslin et al.2) The evolution of the forward price is now driven by n independent Brownian motions. Finally. [2]).

Therefore, the diﬀerence of the log of forward prices with respective maturities τj for j = 1, . . . , m are jointly normally distributed with mean − 1 n σi (t, t+τj )2 ∆t i=1 2 n and standard deviation σi (t, t + τj )2 ∆t. i=1 Next, the annualized sample covariance matrix of these forward prices F (t, T ) is calculated and the eigen-decomposition is computed: Σ = ΓΛΓT where ν11 ν21 Γ= ... νn1 and λ1 0 0 0 0 λ2 0 0 Λ= 0 0 ... 0 0 0 0 λn ν12 ν22 ... νn2 ... ... ... ... ν1n ν2n ... νnn (2.4)

(2.5)

(2.6)

. The eigenvectors are found in the columns of Γ. Then the variances of the factors that govern the points on the forward curve are the eigenvalues weighed by the corresponding eigenvectors (Breslin et al. [2]). The discrete volatility functions become thus, σi (t, t + τj ) = νji λi (2.7)

15

Figure 2.1 shows the covariance surface of the data F (t, T ). Figure 2.1: Annualized covariance surface for NBP data F (t, T )

One observes that higher covariance values are found at the short end of the forward curve. For longer-dated contracts the surface will decay. The surface is not smooth due to illiquidity in longer-dated contracts and changes in market dynamics. However, another important source of noise is seasonality. It is therefore advised to repeat the PCA analysis for the diﬀerent seasons deﬁned (Breslin et al. [2]).

16

Next, from the covariance matrix the form of the volatility functions is obtained as described by (2.7). Figure 2.2 plots the ﬁrst three volatility functions σ1 (t, T ), σ2 (t, T ) and σ3 (t, T ) which respectively shift, tilt and bend the forward curve. Figure 2.2: First three volatility functions for NBP data F (t, T )

17

Hence. Alternatively. In the case of natural gas the delivery will take place the next day. [2]).3 Seasonality adjustment Further. It contains integrals over the Brownian motions from time zero to time t. Further. t) du + ∂t t 0 ∂σi (u. an SDE is obtained which describes the spot price dynamics. seasonality should be taken into account when modeling evolution of the forward curve. t) = S(t) (see Breslin et al. an equation for the evolution of the spot price can be written down which is consistent with forward price dynamics. the functions of (2.8) is found between square brackets.2) could be rewritten as a product of a timedependent spot volatility function and maturity-dependent volatility functions (Breslin et al. (2. t)dzi (t) The drift term of (2. Since the forward curve and spot dynamics are related. One could estimate a diﬀerent volatility function for each season.2 Spot . dS(t) = S(t) ∂lnF (0. t) dzi (u) ∂t dt (2. The spot price process described is thus non-Markovian.2. 2. where seasons are obtained by splitting the data. F (t. The spot price is given by.1.2) thus becomes: 18 . t) i=1 ∂σi (u. Therefore. The spot price is the price quoted at which a particular commodity can be bought or sold for immediate delivery.forward price relationship The dynamics of the forward curve are related to spot price dynamics. as mentioned in Section 1. [2]). an important stylized fact of energy markets is seasonality in the forward price volatilities. (2. That is. the spot price is essentially the front end of the forward curve. At the front end of the curve the maturity date is equal to the current date t. t) − ∂t n n 0 t σi (u. Following a further diﬀerentiation. Examples are summer/winter and summer/autumn/winter/spring. This is called day-ahead delivery.8) + i=1 σi (t.2) is integrated. all random shocks from the start of the process up till the current date are incorporated in the spot price.

But now the correlations between the Brownian motions driving diﬀerent commodities c.i (t). Then.i (t. . [2]). m stands for the diﬀerent commodities and i = 1. . T ) nc σc. . . as described by equation (2.10) where c = 1. • µ(t) is the vector of drift terms over the time step. 2. . T )dzc. the discrete-time evolution of the forward curve can be written in terms of the estimated volatility functions. (2. the spark spread is the spread between the power price and the price for natural gas used to produce the electricity. dzi (t) for a given commodity c.9) where the spot price volatility at time t is described by σs (t) and σi (T − t). nc points out the particular volatility function that corresponds to each commodity. For example.i (t) i=1 (2.10) describes the joint forward curve dynamics of multiple commodities as: dFc (t. Spark spread modeling is critical in order to value power plants. T ) n σi (T − t)dzi (t) i=1 (2. are still zero. the correlations between the Brownians governing a commodity.11) • x(t) is the vector of changes in the natural logarithms of the forward prices ¯ for each maturity at the speciﬁed time step.4 Multi-factor multi-commodity model Equation (2. n who respresent the n maturity-dependent volatility functions.dF (t. . ¯ 19 . represent the inter-commodity correlations (Breslin et al. Equivalent to the approach taken for a single commodity. Obviously. . . . i = 1. . T ) = Fc (t. . Practitioners in energy risk management often have to deal with joint modeling of diﬀerent commodities. T ) = σs (t) F (t. dzc.9). . The correlation between the diﬀerent commodities is ﬁxed by a correlation matrix for the Brownian motions. This results in the following matrix representation: ˜ε x(t) = µ(t) + Σ¯ ¯ ¯ where (2.2) could be further generalized to incorporate multiple commodities.

• ε is the unknown vector of standard normally distributed random shocks. T ).5 Two-factor regime switching forward price curve model Building on the general framework for commodity forward price curves introduced in Section 2. · is introduced and stands for the scalar product in RN if u = (u1 . . . T ) = σ1 (t. . . dF (t. that is for i = 1. • both volatility functions. 2. .1. Further. • further. . [4]). σi2 . T ) where • the natural gas forward price at time t with maturity T is denoted by F (t. . the model belongs to the class of Markov Switching models (Chiarella et al. T )dz1 (t) + σ2 (t. Markov Switching of the coeﬃcients is imposed. [4]). . T )dz2 (t) F (t. σi = (σi1 . As indicated in Section 1. ¯ 2. In between two random jump times an almost deterministic process is followed by the volatility. σiN ). Therefore. 20 . αi = (αi1 . . .12) u. uN ) then N (2.˜ • Σ is the matrix of discrete volatility function terms. the following two-factor regime switching model for the natural gas forward curve is proposed (see Chiarella et al.2 it is modeling a process in the class of piecewise-deterministic processes which provides a suitable framework for modeling the dynamics of the volatility term structure. the notation ·. . αiN ). αi2 . . That is. have diﬀerent volatility and attenuation parameters depending on the state of the Markov Chain Xt . Xt = i=1 ui I(Xt =ei ) where the indicator function is represented by I(Xt =ei ) : I(Xt =ei ) = 1 if Xt = ei 0 otherwise.

the Fourier series will consist of only one series. . e2 . . . . .σ1 (t. eN }. parameters σl1 and σl2 are deﬁned to describe long run volatility. • the transition probability matrix of the Markov Chain Xt is deﬁned by ξ = (ξij )N xN . . . . For the application below. Where ξij is the conditional probability that the Markov Chain Xt switches from state ei at time t to state ej at time t + 1. with the state space deﬁned by X = {e1 . that is J = 1. .13) where • switching between parameter values is governed by a ﬁnite state Markov Chain Xt . d1 and f1 are then estimated. that is ei = (0. • z1 (t) and z2 (t) are independent Brownian motions. . . . N . . T ) = σ1 . j = 1. that is ξij = π(Xt+1 = ej |Xt = ei ) • c(t) represents the seasonal part which is modeled as a truncated Fourier series Therefore seasonality is introduced into the model by making the parameters periodic functions of time. T ) = σ2 . for all i = 1. 0)T ∈ RN . Xt c(t) (e− α1 . .Xt J (T −t) (1 − σl1 ) + σl1 ) (T −t) σ2 (t. . with ei a vector of length N that has a value of 1 at the i-th position and 0 elsewhere. 1. .Xt c(t) = c + j=1 ) (dj (1 + sin(fj + 2πjt))) (2. 0. 21 . . with a periodicity of one year. • since the long term volatility behaves diﬀerently from short term behavior. . Xt c(t) (σl2 − e− α2 . N. 0. . . The parameters c.

2. .12) and (2. X. take diﬀerent values for diﬀerent states of the world. dj . 2). c. It is thus assumed that the state process can jump only at the discrete observation times (Chiarella et al. 3. Further. and the transition probability matrix of the underlying Markov Chain. . . . M ∆t = t. where t is the present time. M are observed. k = 1. . for the diﬀerent maturities the forward prices F (k∆t. J)} (3. The set of parameters is deﬁned as θ: θ = {σi . The model is a Markov Switching model: the parameters. αi . .1) The elements of the transition probability matrix ξ are also unknown and have to be inferred from the historical data as well. Then in discrete-time the forward dynamics of (2.12) can be rewritten as 22 . a Markov Chain Monte Carlo (MCMC) method is suggested and implemented. . σli (i = 1. T ).13). [4]). fj . ξ. .1 Data transformation So. T ) and σ2 (t. . For the econometric estimation of the states for drift and volatility. . .Chapter 3 Estimation In this chapter a Bayesian approach is presented to estimate the parameters of the forward curve model described by (2. In particular. θ. found in the respective volatility functions σ1 (t. the state transitions are driven by a ﬁnite state Markov Chain. T ). a discrete-time Gibbs sampler is developed to estimate θ and ξ given the forward prices at ﬁxed observation times ∆t. . (j = 1. 2∆t.

3.T is abbreviated to yT .5) Before drawing from this augmented complete-data likelihood distribution the prior distributions have to be chosen (Chiarella et al. u The posterior distribution π(X. and the sampler applied here is a Gibbs sampler (Fr¨hwirth-Schnatter [14]). the latent Markov Chain X is introduced as missing data and samples for θ and X are generated given yT for parameter estimation.yt. (3.2) One can see that diﬀerence of the log of forward price. i=1 (3. The sampling distribution is the posterior distribution. θ) which expresses the forward dynamics yT given the states of the Markov Chain X and parameter values θ. T ) 1 =− 2 2 2 σi (t.3) σi (t. and initial knowledge about the model parameters is expressed by deﬁning a prior distribution for θ. 23 . The technique of constructing sampling algorithms via the introduction of latent variables is called data augmentation. π(X. T )2 ∆t.2 Bayesian estimation for a Markov switching model In the Bayesian estimation for a Markov switching model.4) The notation for the forward dynamics yt. θ|yT ) is proportional to the complete-data likelihood distribution π(yT |X. θ|yT ) ∝ π(yT |X. θ|yT ). Further. the conditional distribution π(X|θ) indicates that realizations of X are dependent on the parameter values θ. T )∆zi (t). π(Xt .T = log F (t∆t. θ)π(X|θ)pr(θ) (3. pr(θ). [4]). yt. T ) ∆t + i=1 i=1 2 σi (t.T is normally distributed with mean 1 µ(t. T ) = − 2 and standard deviation 2 2 σi (t. T )2 ∆t i=1 (3. T ) − log F (t.

f ∼ U (ac . and il il αil ∼ U (aα . the volatility and attenuation parameters are bounded which eases convergence. X0 ∼ U ({1. = ξl. σli ∼ U (0. X0 ) = pr(ξ) i=1 (pr(σi ) · pr(αi ) · pr(σli ))pr(c) j=1 (pr(dj )pr(fj ))pr(X0 ). 24 . bα ) where aσ and aα are discrete values which deﬁne the paramil il il il eters of the uniform distribution. are uniformly distributed c. are uniformly distributed as well. • The priors of the long run volatility parameters. aα . d. . bσ ). glN ) where the vector gl. equals the prior expectation of xil. All parameters gl1 . bα . . . c. [4]). . σli . N. . times a constant that determines the variance. . d.3.1). the priors can be written as follows 2 J π(θ. If ξ0 denotes our prior expectation of ξ. • The priors for the parameters of the seasonal part. the state of the Markov Chain at t = 0. Then cp can be interpreted as the number of observations of jumps out of state l in the prior distribution. ac . bc in the prior distributions are deil il il il ﬁned before running the Gibbs sampler (Chiarella et al. ξ and X0 are independent. ξ. the Dirichlet distribution simpliﬁes to a Beta distribution. . we may 0 set gl. glN .3 Prior distributions Prior distributions are chosen for θ and X0 . bc ) • The prior of the initial state of the Markov Chain is following a discrete uniform distribution. f . As a result. is restricted to 2. cp . aσ . 1) • The rows ξl of the transition probability matrix ξ. . Where the following distributions are assumed for the priors: • The priors of volatility and attenuation parameters are σil ∼ U (aσ . are assumed to be independent and to follow a Dirichlet distribution ξl ∼ D(gl1 . . Under the assumption that the set of parameters θ given by (3. . . If the number of states. . N }) where N is equal to the number of states deﬁned for the Markov Chain. bσ .

ξ.5 ) (Chiarella et al. [4]). K + K0 . The particular scheme is explained in Algorithm 1 below. µ. . X (k−1) ). K0 . µk∆t.T and standard deviation σk∆t.T . . 2. and the rate of convergence. . These samples are thrown away for the calculation of the estimators. . described by φ(yT . a three-step MCMC sampler is used to sample from the augmented posterior distribution π(θ. Parameter simulation conditional on the states X (k−1) (a) Sample the transition matrix ξ (k) from the complete-data posterior distribution π(·|X (k−1) ). [4]). Conditional on knowing the state of the ﬁnite Markov Chain X.T . Clearly. . the length of burn-in depends on the initial state of the Markov Chain state. yT ) using Algorithm 3. The complete-data likelihood function is a product of normal densities. which will be discussed below. The notation K0 represents the number of iterations for the burn-in. . X0 . Store the actual values of all parameters θ(k) and ξ (k) . (b) Sample the model parameters θ(k) from the complete-data posterior π(θ|yT .T ) 25 (3.T .4. X|yT ) given the observed data yT where each part is drawn from the proper conditional density (Chiarella et al. X) = k=1 φ(yk∆t. given by the moments of ( 3. u Algorithm 1: Unconstrained MCMC for a Markov Switching Model Start with some state process X (0) and repeat the following steps for k = 1. θ is sampled and X is sampled conditional on knowing θ (Fr¨hwirth-Schnatter [14]). σk∆t. 1. 3.1 Full conditional posterior distributions Next. ξ and X. M π(yT |θ. ξ. σ) with the with mean µk∆t. the full conditional posteriors required for the three sampling steps are derived. .4 Gibbs sampler Starting from the prior distributions speciﬁed in Section 3. . Next.2.3. the unknowns are partitioned into three blocks θ.6) . State simulation conditional on knowing θ(k) by sampling a path X of the hidden Markov Chain from the conditional posterior π(X|θ(k) .

k=1 3. the conditional joint distribution of the parameters associated with drift and volatility is given by π(θ|yT .Xk =q) (Chiarella et al.4 to infer the parameters of the volatility functions. u Given the transition matrix ξ (k) of the hidden Markov Chain. assumptions regarding the distribution π0 of the initial value X0 have to be made. ξ) ∝ π(yT |θ. ξ) = π(X0 |ξ) l. In this essay the initial 26 . M .9) where the notation Nlq stands for the number of transitions from state l to q. ξ.Further the full conditional of θ.2 Sample the transition matrix The MCMC routine Algorithm 1 was introduced in Section 3. The complete-data likelihood π(X|ξ) is given by. complete-data estimation is carried out for a given path X. X) ∝ π(yT |θ. In the next sections the several steps involved will be explained in more detail. [4]). u In order to determine the particular algorithm.4. the transition matrix ξ (k) is sampled (Fr¨hwirth-Schnatter [14]). l = 1. each row is an unknown probability distribution that has to be estimated from the data.10) where 2 states are deﬁned for the Markov Chain and Njk counts the number of transitions from j to k (Fr¨hwirth-Schnatter [14]). 2 2 π(X|ξ) = j=1 k=1 ξjk NKjk (X) (3.7) where the prior distribution π(X|ξ) is not dependent on θ but rather speciﬁed by the distribution of X0 and the transition matrix ξ. . is π(X|yT . that is Nlq = M I(Xk−1 =l. The conditional probability π(X|ξ) in ( 3.8) (3. First. θ. Therefore. X)π(X|ξ) (3. .8 ) is provided by M N π(X|ξ) = π(X0 |ξ) k=1 π(Xk |Xk−1 .q=1 ξlq lq N (3. . . from the complete-data posterior distribution π(ξ|X (k−1) ). X)pr(θ) Finally. the full conditional posterior of the state process Xl∆t . 2.

distribution π0 is assumed to be independent of ξ.3 Sample the model parameters A single-component Metropolis-Hastings algorithm is set up in order to update the parameter set θ. The candidate θ∗ is generated by a so-called candidate generating density q(θ. θ2 . . e12 + N12 (X))ξ22 ∼ B(e21 + N21 (X). Further. . . Xt = k} counts the numbers of transitions from j to k for the actual draw of X. . instead of updating the elements of θ all at once. . θ∗ = θ + rθ ψ (3. ejK (X) + NjK (X))j = 1. Now a classical Bayesian inference problem. . . The rows ξj· of ξ. with d the number of parameters. N (3.12) These densities generalize to the Dirichlet distribution for the case N > 2 (Fr¨hwirthu Schnatter [14]). it is more straightforward and computationally eﬃcient to split θ into its components {θ1 . . are each following a Beta distribution. both independent. that is N = 2.11) where Njk (X) = #{Xt−1 = j. . . are drawn from the following Dirichlet distribution (Fr¨hwirth-Schnatter [14]). the persistence probabilities ξ11 and ξ22 . .13) where ψ is a vector of independent standard normal random variables and rθ is a scalar which represents a ﬁxed value for the step width.4. θd }. a normal random walk is used to draw θ∗ . independent a posteriori. ξ11 ∼ B(e11 + N11 (X). . u ξj· ∼ D(ej1 + Nj1 (X). and update one by one. θ∗ ). e22 + N22 (X)) (3. Since only two distinct states are deﬁned for the transition matrix ξ. Here. 27 . 3. that is sequentially. Gibbs sampling from the conditional posterior π(ξ|X) can be applied.

θi ) where ∗ ∗ π(θi |θ−i )qi (θi |θi . θ−i ) (k) (k) (k) (k) (k) ∗ α(θ−i . One could. 2. (3. . . ∗ If this random number is less than α(θ−i .14). θ−i ) = qi (θi |θi . . Let θi denote the value of θi at end of iteration k. At this step θ−i is left untouched. 2. Initialize vector θ0 at some values for its components. This special case of the Metropolis-Hastings algorithm is often referred to as the random-walk Metropolis-Hastings (Fr¨hwirth-Schnatter [14]). Therefore. For step i of iteration k + 1. θ−i ) (k) (k) (k) (k) drops out of the Metropolis probability calculation (3. ∗ 3. the candidate is accepted with probability α(θ−i . θi ) then the move is accepted. . . look at parameter values found in previous research. Otherwise. The candidate is generated from proposal distribution qi (θi |θi . thus the proposed move for component i of parameter set θ is rejected. So. θ−i ) (k) where θ−i denotes the value of θ−i after completing step i − 1 of iteration (k) (k+1) (k+1) (k+1) (k) (k) k + 1: θ−i = {θ1 . θ−i ) ∗ qi (θi |θi . . . . 4. 1). θ−i ) by the symmetry of the normal distribution. . θi . ∗ ∗ Notice that qi (θi |θi . So. θi+1 . Next. θi = θi . . (m+1) (m+1) (m) (m) ∗ ∗ if θi is accepted. for example. θi . θi ) = min 1. Generate a random number ∼ U (0. This greatly simpliﬁes the calculation of α. Diﬀerent starting values could be chosen. θh } where components 1. θi is updated.14) where the full conditional distribution for θi under π(·) is denoted by π(θi |θ−i ). θi−1 . u 28 . θi . . i − 1 have already been updated. only for the i-th component of θ a candidate is generated and this candidate is dependent on the current values of the other elements of θ. the factor ∗ qi (θi |θi . . otherwise θi = θi .Algorithm 2: single-component Metropolis-Hastings 1. θ2 . θ−i ) ∗ π(θi |θ−i )qi (θi |θi . the random number is greater than the acceptance probability.

15) where the ﬁltered probability distribution at t = T is denoted by π(XT |yT . . yT ) ∝ ξXt . is worked out in great detail. and in a region of the parameter space that has low probability.16) t where π(XT |yT . First. θ) (3. θ. yT ) π(XT |yT .When the random-walk Metropolis algorithm is used as candidate generating density q(·. θ) (3. θ. Further. ξ (k) ). when rθ is chosen to be too low. XT ). θ) is the ﬁltered probability distribution at time t. θ) = t=0 π(Xt |Xt+1 . Here.4 Markov Chain state simulation In a ﬁnal step of the Gibbs sampler. If that step size is too high.4. but the chain will move slowly around the parameter space. . In this section this sampling method for the hidden Markov Chain X = (X0 . . ξ (k) ). 3. . to help assess convergence (Fr¨hwirth-Schnatter [14]). θ). the joint posterior π(X|yT . θ). Hence. . and a Markov Chain that doesn’t move very often. As a consequence. . the assumption is taken that the Markov Chain Xt is homogeneous. . a path X of the hidden Markov Chain from the conditional posterior π(X|(θ(k) . it is a good idea to experiment with diﬀerent values for step size. yT ) is simpliﬁed to ξXt . XT .Xt+1 . ·). in general. candidate draws θi will be very far away from the current draw. the updating order for the elements of θ in above Algorithm 2 is assumed to be ﬁxed. And. Whereas. Sampling Posterior Paths of the Hidden Markov Chain A resourceful way to sample is called multi-move sampling where the states of the whole path X are jointly sampled from the conditional posterior distribution π(X|yT . 29 . θ) is written as follows T −1 π(X|y. This would lead to a high rejection rate. But random permutations of the updating order are acceptable as well.Xt+1 π(XT |yT . yT ) is sampled conditional on (θ(k) . . the algorithm accepts frequently. . . t π(Xt |Xt+1 . XT . . θ. So. then candidate draws will be very close to the current draw. u Finally. as described by Algorithm 1. the standard deviation of the normal random variable is the step ∗ size rθ . it is wise to run multiple chains from disperse starting values. . t π(Xt+1 |Xt .

1. k=1 30 . Algorithm 3: Multi-Move Sampling of the States Given ﬁxed values for parameter set θ.1: Filtering the States For t = 1. 2} of Xt . θ) = t−1 π(yt |yT . θ)π(Xt = l|yT . yT . For a state space model. θ) for all possible realizations l ∈ {1.18) where 2 t−1 t π(yT |yT . Algorithm 3. (b) Filtering for Xt : t−1 t−1 π(yt |Xt = l. Obtain Filtered state probabilities First. π(Xt = l|yT . The resulting ﬁltered state probability distribution π(Xt = j|y t . run the ﬁlter described in Algorithm 3. θ) t (3. . θ) = k=1 t−1 t−1 t π(yT |Xt = k. (a) One-step ahead prediction of Xt : 2 π(Xt = l|y t−1 .19) At t = 1. .Given the above-mentioned distributions it is now possible to implement a forward-ﬁltering-backward-sampling algorithm. θ) j = 1. θ)π(Xt = k|yT . θ) (3. yT . θ) = k=1 t−1 ξkl π(Xt−1 = k|yT . the ﬁlter is started with the initial distribution π(X0 = k|ξ). θ) simpliﬁes to the transition probability ξkl for homogeneous Markov Chains. π(X1 = l|yT . 2. 2 where π(Xt = l|Xt−1 = k. . 0 So. yT . . T . θ) π(Xt = l|y . the following steps are executed sequentially. T is then stored. conditional on θ. θ) (3. . execute the following steps to sample a path X k of the hidden Markov Chain. the ﬁltering problem implies statistical inference about the state variable conditional on observations from the beginning up till time t. . . θ) = 2 ξkl π(X0 = k|ξ).1. The complete ﬁltering distribution is obtained by the discreteness t of the support of the state variable Xt .17) t−1 for l = 1. 2 for t = 1. .

To obtain inference about Xt at time t t in terms of the posterior distribution π(Xt = l|yT . yT contain about Xt−1 . . . 0 sample St (k) π(Xt = j|Xt+1 .lm π(Xt t = k|yT . θ) at time t − 1 and only the actual t value of yT are suﬃcient.. . θ) (k) from the ﬁltered state probability distribution π(Xt = (k) 3. . for a ﬁxed value of θ. θ) = t ξj. . θ) given by (k) from the conditional distribution t π(Xt = j|Xt+1 .lm π(Xt = j|yT . . Sample XT t j|yT . m t For each t. yT . . θ). π(Xt |Xt+1 . For t = T −1. . θ) needs to be evaluated for all j = 1. θ). which were stored in step 1 of Algorithm 3. . all information the observations t−1 y1 . yT ) reduces to ξj. θ. knowledge of the t−1 posterior distribution π(Xt−1 = l|yT . the discrete ﬁlter described in Algorithm 3 is an adaptive inference tool. . y t . . θ) K k=1 ξk. K.lm since the Markov Chain Xt is homogeneous. the ﬁltered probabilities π(Xt−1 = t−1 l|yT . 2. At time t − 1.As is typical for any ﬁlter. 31 . This t requires knowledge of the ﬁltered state probabilities π(Xt = j|yT . . T −2. θ) t where lm is equal to the state of St+1 and π(Xt+1 = lm |Xt = j. yT . θ) summarize.

It is the most liquid gas trading point in Europe. the log diﬀerence transform is applied to the original data F (t.1 Data The natural gas prices modeled are forward prices for the National Balancing Point (NBP). Further.2 Choosing the prior The complete-data likelihood and the full conditionals introduced in Chapter 3 contain prior knowledge about the parameter set θ. and X0 . Further. 4. T ).5. the algorithms are tested with simulated data. in order to obtain the forward dynamics yT for every maturity T . Before applying the chosen methodology to historical gas forward prices. estimators are given for both a one-factor model and the two-factor model described in Section 2. For parameter estimation of the chosen model. The observations span over a year with prices at times t from 23/10/2007 to 12/03/2009. There is some degree of freedom in the choice of prior distribution but the prior distribution should be 32 . 4. forward season or year forward basis and prices are expressed in pence (GBp) per therm. Natural gas at NBP trades on a forward month.Chapter 4 Implementation In this chapter. the details of the implementation are laid out and the numerical results for the routines are provided. which is the British virtual trading location operated by TSO National Grid. forward quarter. This data is represented by F (t. covering all entry and exit points in mainland Britain. daily observations for the forward prices were obtained with maturities ranging from July 2009 to September 2012. T ).

X) = k=1 φ(yk∆t. (i. . .84 g= (4. . µ and σ deﬁned as in Section 3.Tλk . k = 1. Finally. one may set gl. .5). If ξ0 denotes the prior 0 expectation of ξ. . µk∆t. 33 . the data yt.36 0. cp . (i = 1. 2}) 4. 2. λ2 . . 1). [4]). . 12}). 2) • The priors of c. and αil ∼ U (0. 1. 5) • The priors of σli are σli ∼ U (0. .16 0. f (J = 1) are c.independent of the data and the posterior distribution. λN ) with λk ∼ U ({1. the matrix of parameters for the Dirichlet distribution is set to 0. N where λk ranges from 1 to 12 to label 12 diﬀerent maturities.T corresponding to the maturity Tj is picked if λk = j. d. . . At each time k · ∆t in the data series. Before estimation a string λ is selected. [4]): • For the transition matrix ξ the vector gl. This way. the scaling factors rθ have to be chosen.2) where φ. 2) are σil ∼ U (0. The following priors are used in the implementation (Chiarella et al. all observations along the forward price curve at each time t are taken into account. [4]).1) • The priors of σs and αs. . σk∆t. Then cp can be interpreted as the number of observations of jumps out of state l in the prior distribution. 1) • The prior of the initial state of the Markov chain is X0 ∼ U ({1. Hence.64 0. The complete-data likelihood function thus becomes N π(yTλ |θ. to implement the Metropolis-Hastings algorithm.1 (Chiarella et al.Tλk .3 Running the Gibbs sampler A randomized algorithm is used to calculate the complete-date likelihood function. times a constant that determines the variance. d1 . = ξl. λ = (λ1 . . ξ. l = 1. Fixing rθ around 2% to 5% seemed to work well (Chiarella et al. equals the prior expectation of xil. f1 ∼ U (0.Tλk ) (4.

4.9 0.1: Generated forward price dynamics. d = 0. f = 0.5. T ) = σ1 (t. σl1 = 0. σ2 (t.1 One-factor model First.7 0. Then the parameters for the ﬁrst volatility function σ1 (t. the implementation of the Gibbs sampler is veriﬁed by means of simulated forward data.6. α11 = 2.3 34 .08. yT following formula (3. After which the model parameters are inferred with the Gibbs sampler. the second volatility function. Figure 4. The transition probabilities ξ were equal to ξ= and. the parameter set θ θ = {σ1 1 = 0. T ) are deﬁned as in Section 2. T ) (4.75. T ) is omitted in (2.12) such that one is left with a one-factor model.1 below shows the forward price dynamics yT of a one-factor regime switching model. dF (t. yT 0.5.2).1 0.3) Next. α12 = 1. T )dz1 (t) F (t. σ12 = 1.8. The code in Appendix A (p.3. c = 0.31} Figure 4.) generates forward price dynamics.

) Also in the case of the two-factor model. yT . 4. For this very ﬁrst stage of the implementation.12). In Appendix B (p. the parameters of the seasonality function. yT . The code for this discrete-time sampler is provided in Appendix D (p.31.3.08 and 0. Below one can ﬁnd the routine for the Gibbs sampler which is applied to the generated forward price dynamics. d and f are ﬁxed at their true values 0. The respective parameters c. 0.m.2 Two-factor model Forward price dynamics are simulated to check the implementation of the Gibbs sampler for the two-factor model as expressed by (2.) 35 . the parameters for the seasonality function c(t) are not estimated.) one can ﬁnd the routine for the Gibbs sampler which is applied to the generated forward price dynamics. c(t) are initially ﬁxed. which is found in Appendix C (p. The dynamics yT are generated calling the routine nbp 2fac. parameter estimation is carried out with the Gibbs sampler.Next.8.

72 1 2 2 0.4.31. the parameters c.9 0.12 0.1 One-factor model For a two-state regime. f = 0.01 1.4 Numerical Results 4. 2) Simulated data Actual Estimated 1 2 1 0. • Number of states = 2 • Transition probability matrix ξ Simulated data Actual Estimated 1 2 1 0. Below one can ﬁnd the estimates of the transition probability matrix ξ and the parameter set θ.000 steps were run with simulated data. [4]. At this stage of the implementation. d = 0.06 j σ1j α1j 2 1. one-factor model.08.7 0.47 2 1.1 0. about 100.78 36 .4.81.5 1 0. which are seasonality parameters obtained from previous estimations by Chiarella et al. Parameters are respectively c = 0.28 • Regime-switching parameters σ1j and α1j . (j = 1. A rate of 20% is chosen for the burnin which means that the ﬁrst 20% of the output is thrown away and does not contribute to the estimated values.88 0.75 2. the values for the seasonality function c(t) are kept ﬁxed. That is. d and f are not included in the parameter set θ.3 0.

62. but also the values for the attenuation parameters α1j reach the actual values of the underlying forward dynamics yT . 2) • estimator for σl1 . with an actual value of 0.6 37 .2: Path of parameter estimates for σ1j and α1j .2 below shows the parameter estimates throughout the runs.Figure 4. Figure 4. (j = 1. σl1 = 0. Convergence is reached fast for the volatility parameters σ1j . (j = 1. 2).

σl2 = 0. d = 0.8. two-factor model.3.2 Two-factor model For a two-state regime.2 0. f = 0.6.6 0.4 38 . α12 = 2. Any parameters that lie within the boundaries set by the prior distributions could be chosen for the simulated forward dynamics. σ12 = 0.5.4. σl1 = 0.31} Figure 4.4. α11 = 1. c = 0. about 100. α22 = 3. The transition probabilities ξ were equal to ξ= and. σ21 = 0. σ22 = 1. yT 0.8.3: Generated forward price dynamics. Here the following parameter values were used to generate yT . Figure 4.000 steps were run with simulated data.2. the parameter set θ θ= {σ11 = 0.8 0.5. α21 = 1.08.9.3 below shows the forward price dynamics yT of a two-factor regime switching model.

f = 0.6 0.67 1 3 1. [4]. With ﬁxed seasonality function c(t) Parameters are respectively c = 0.5 2 1.81.83 0.31 2.Next. As previously stated. the Gibbs sampler implemented for the two-factor regime should be able to retrieve those values.8 0.3 0.2 0. Below one can ﬁnd the estimates of the transition probability matrix ξ and the parameter set θ.17 0.8 0.01 j σ1j σ2j α1j α2j 2 0. • Number of states = 2 • Transition probability matrix ξ Simulated data Actual Estimated 1 2 1 0.63 1 2 2 0. 1. 2) Simulated data Actual Estimated 1 2 1 0.31 Those seasonality parameters were obtained from previous estimations by Chiarella et al.67 1.37 0.6 1.69 3. d = 0.4 0.08.59 39 .2 0. (j = 1.78 1. a rate of 20% is chosen for the burnin which means that the ﬁrst 20% of the output is thrown away and does not contribute to the estimated values.37 • Regime-switching parameters σ1j and α1j .

The values for the attenuation parameters αij are near the actual values of the underlying forward dynamics yT .5 below show the parameter estimates throughout the runs. Convergence is reached fast for the volatility parameters σij . (i. Figure 4.4: Path of parameter estimates for σij . 2). One could increase the number of runs.4 and 4. (i. j = 1. j = 1. 2) 40 .Figures 4.

6 estimator for σl2 . with an actual value of 0. σl1 = 0.66. d and f are included in the parameter set θ • Number of states = 2 41 . With varying seasonality function c(t) Now. (i. j = 1.9 The same exercise is repeated.000. but now the parameters for the seasonality function c(t) are inferred as well from the simulated forward data.Figure 4. 2) • estimator for σl1 . the seasonality parameters c. with an actual value of 0. σl2 = 0.5: Path of parameter estimates for αij . 2.83. The number of runs is increased to 200.

3 0.19 1.21 0.53 1.38 • Regime-switching parameters σ1j and α1j .8 0.8 0.94 j σ1j σ2j α1j α2j 2 0.83 1 3 0.6 1.2 0.62 1 2 2 0.61 3.30 42 .6 0. 2) Simulated data Actual Estimated 1 2 1 0.79 0. (j = 1.2 0.4 0.• Transition probability matrix ξ Simulated data Actual Estimated 1 2 1 0.73 1.5 2 1.26 0.

2) 43 . Figure 4. 2).5 below show the parameter estimates throughout the runs. Convergence is reached fast for the volatility parameters σij . j = 1. (i.4 and 4. One could increase the number of runs. j = 1. The values for the attenuation parameters αij are near the actual values of the underlying forward dynamics yT . (i.Figures 4.6: Path of parameter estimates for σij .

6 estimator for σl2 .7: Path of parameter estimates for αij . d = 0. σl1 = 0. 2) • estimator for σl1 .31 44 .53. d = 0.35 with actual values of c = 0.93. with an actual value of 0. σl2 = 0.92.9 • estimators for seasonality function are respectively. c = 0.08 and f = 0.8.Figure 4. with an actual value of 0. j = 1. (i.04 and f = 0.

3654 estimator for σl2 .2080 2.000 steps were run and the following are the estimates of the parameters. The burnin rate is 20%. with rather similar results.3 Historical NBP forward data Now all pieces have been put together and tested.4. • Number of states = 2 • Transition probability matrix ξ Historical data Estimated 1 2 0. The estimates for the transition probability matrix ξ show that with high probability the Markov Chain will stay in regime 1 for the better part of the time horizon.5020 1.1.6207 0. In Appendix E (p.0885 1.4. Sporadically.5673 1 2 • Regime-switching parameters σ1j and α1j . the Gibbs sampler for the two-factor regime switching model is applied to historical forward NBP data.4115 2. The data sample was introduced in Section 4.7833 45 .0948 1.9067 j σ1j σ2j α1j α2j • estimator for σl1 is 0.8185 0. Finally. is 0. About 200. A number of MCMC estimation procedures were run with diﬀerent initial values for the respective parameters.3777 0. (j = 1. 2) Historical data Estimated 1 2 0. a jump from regime 1 to regime 2 is witnessed.185 0.) one can ﬁnd the routine for the Gibbs sampler which is applied to the sample.4327 0.

6203 • estimators for seasonality function are respectively. which indicates that the environment is less volatile. 2) Historical data Estimated 1 2 0.8932 1. (j = 1. d = 0.8516 0. c = 0.3070 46 .4762 1.0292 2.6922. c = 0.1484 0.2920 1 2 • Regime-switching parameters σ1j and α1j . d = 0.8121. • Number of states = 2 • Transition probability matrix ξ Historical data Estimated 1 2 0. is 0.4869 estimator for σl2 . It could be argued that volatility levels for natural gas have exceeded normal levels in 2008 as a result of the global ﬁnancial crisis.• estimators for seasonality function are respectively.0781 and f = 0. One could see that less time is spent in regime 2 here.0464 1.8429 0.1533 3.2536 j σ1j σ2j α1j α2j • estimator for σl1 is 0. [4] for NBP forward price data that spanned from 29/09/2006 to 19/02/2008.2791 These estimates can be compared to the estimates provided by Chiarella et al.3362 and f = 0.7080 0.3057 0.

For parameter estimation a Markov Chain Monte Carlo (MCMC) technique was applied. like a particle ﬁlter.Chapter 5 Conclusion In this essay a two-factor regime switching model for the forward price curve in the natural gas market suggested by Chiarella et al. [4] the Gibbs sampler presented is an oﬀ line approach. [4]. When new data becomes available. such that the volatility functions can be updated quickly from high-frequency data. The respective changes in regime aﬀect the whole forward curve structure. which included 12 forward curve series. The use of MCMC techniques makes the calibration of more complex volatility functions possible. The highly volatile remainder of 2008 and also the beginning of 2009 was thus not included. the routine is slow to update the estimates. 47 . whereas Chiarella et al. Finally. The parameter estimates for the NBP sample were found considerably higher than the estimators found by Chiarella et al. [4] presented data from 29/09/2006 to 19/02/2008. It is thus not suited in a live setting. Both the transition probabilities of these switches and the model parameters were inferred from natural gas forward price data. Episodes of higher volatility are followed by episodes of lower volatility driven by market structure changes or supply-demand imbalances. [4] was presented. it would be recommended to implement an on line approach. Therefore. The data in this essay spans from 23/10/2007 to 12/03/2009. [18]. as mentioned by Chiarella et al. introduced ﬁrst by Fr¨hwirth-Schnatter (Fr¨hwirth-Schnatter [14]) and Hahn et u u al.

3].7 . x0=ones(len. % state 1 48 .5 1 1.2 % volatility parameters: % \sigma_11.9 .1 .Appendix A nbp 1fac. x0(1)=unidrnd(2).31. \alpha_12 % long-term volatility parameter % \sigma_l_1 % seasonality parameters % seasonality function c=.m Generates forward dynamics of a one-factor regime switching model % parameters % dt=1/365. for it=2:len. tT=(3:-dt:0)’. % sample state vector x0 % len=size(tT.m one-factor volatility model. d=.08. % daily time-stepping % time-to-maturity % time % transition probability matrix % initial values for both states 1.5]. t=flipud(tT). th0=[.5 1 . f=.1).1).8. p0=[. nbp 1fac.*t)). \sigma_12 % attenuation parameters: % \alpha_11. ct=c+d*(1+sin(f+2*pi.

len). % simulate path of forward returns % y=-0.if rand>p0(1.3:4).2*x0(it-1)-1) x0(it)=2.2). sig=sum(x0. % plot % figure. sig=ct. end end x=x0.1)*sqrt(dt).5*dt*(sig.len).*th0(ones(1..*sig)+sig. one-factor model’) xlabel(’time t’). % volatility function % x0=[x0==1 x0==2].*sig.*.2).T)’) 49 ..1:2). ylabel(’y(t.*tT)*(1-th0(5))+th0(5)). (exp(-sum(x0. plot(y) title(’forward data sample.*th0(ones(1.*randn(len.

4).16 .Appendix B mcmc.m for data % guess transition probabilities % prior expectation of % probability matrix % initial parameter values % bounds for parameter values % step size parameter updates 50 th(1.:)=[.m Parameter estimation of Markov switching model with MCMC clc. clear all % initialize % iter=1e4. p=zeros(iter.5 1.m Gibbs sampler.84].5). mcmc. th=zeros(iter. rg=[zeros(1.:)=[.5]. g=p(1.1. burnin=iter/5.5 1 . rth=0.:)*15.05. % generate simulated data % nbp_1fac.64 . % allocate % call nbp_1fac. .5 5 5 1 ]. % priors % p(1.5).36 .5 1 1.

for k=2:iter sp=zeros(len. p1=[p1(1) 1-p1(1) p1(2) 1-p1(2)].1).:)=p1.[g(1.3)+n21]. % update % Metropolis-Hastings algorithm % idx=unidrnd(5). % complete-data likelihood 51 . sf=zeros(len. end end % algorithm % th1=th(1.2). n22=sum((x(1:end-1)==2)+(x(2:end)==2)==2). p(k. % state 1 % allocate % sample transition probability matrix p % n12=sum(diff(x)==1). for it=2:len.2)+n12 g(1. % count transitions between states n21=sum(diff(x)==-1).:). st=[x==1 x==2].2). % random parameter choice % generate th1(idx)=th(k-1.2*x(it-1)-1) x(it)=2. sc=zeros(len. n11=sum((x(1:end-1)==1)+(x(2:end)==1)==2).% sample initial state vector x % x=ones(len.1)+n11 g(1. % sample from Beta distribution p1=betarnd([g(1.4)+n22]). x(1)=unidrnd(2).2). if rand>p(1.idx) + rth*randn.

idx)).. FFBS algorithm % % forward filtering % sp(1.t(2:end). end % filtering.dt.llh*pr(1)/pr(2)).len))).len)).t.:).th1. sf(2:end.2)). sp(it.1)].*sf(it.dt. sf(1..*sp(it-1.:)=p1([x(it+1) x(it+1)+2]).:).2)=mclh(y(2:end). else th(k.:).1) x(len)=2. if rand<=alpha..:)=sp(1.idx)]..m llh=sum(log(mclh(y.:)=0.:)=th1.len-1).[ones(len-1.:)/(sc(it. th(k. for it=2:len sf(it.% call mclh.tT(2:end). % acceptance probability alpha=min(1.st.1)+sc(it.t.1)]..dt. sf(it. sc(it.:)=sf(it. 52 .:)=sf(it. end % state 1 for it=len-1:-1:1 sc(it.st. -log(mclh(y.th(k-1.2)).:).dt. if rand>sf(end.:)=sc(it.tT. end % backward sampling % x=ones(len..1) ones(len-1.5*(p1(1:2)+p1(3:end)).rg(2.1) zeros(len-1.tT(2:end).rg(1.:)=sf(it.:).:)=th(k-1.1).t(2:end).. % prior densities pr=unifpdf([th1(idx) th(k-1. sf(2:end.2)*p1(3:end).:)/(sf(it.len-1).:). th(k.:).1)=mclh(y(2:end).tT.th(k.[zeros(len-1.1)*p1(1:2)+sf(it.:).idx).1)+sf(it..

^2). mclh.t.dt.:).1)=sum(x.if rand>sc(it.1)).*sig.th.*th(ones(1.*tT)*(1-th(5))).*t)).T). 53 . mu=dt*sum(sig.ones(2.:)) mu_p=mean(p(burnin+1:end.08*(1+sin(.2).2).3:4).5*mu). end end th1=th(k.5*((y+0. This function is given below./sqrt(mu).T).x. function [lh.tT.sig]=mclh(y.8+.2).m is called to evaluate the complete-data likelihood for various values of the parameters./mu).31+2*pi. lh=exp(-0. sig(:. sig=ct(:. the function mclh.*(th(5)+ exp(-sum(x.m Returns components of complete-data likelihood function sig=zeros(T.*sig.:)) In the routine for the Gibbs sampler.T).*th(ones(1.1:2).2). ct=. end % update % output % mu_th=mean(th(burnin+1:end. lh=lh.1) x(it)=2.

Appendix C nbp 2fac. p0=[. \alpha_22 long-term volatility parameter \sigma_l_2 54 . tT=(3:-dt:0)’. \sigma_22 attenuation parameters: \alpha_21.. % daily % time-to-maturity % time % transition probability matrix % initial values for 2 factors & % both states 1. \sigma_12 % attenuation parameters: % \alpha_11.6 .25 . th0=[. nbp 2fac.m Generates forward dynamics of a two-factor regime switching model % parameters % dt=1/365.m two-factor volatility model.3 2 3 .5 1 1. \alpha_12 % long-term volatility parameter % \sigma_l_1 % % % % % % volatility parameters: \sigma_21. ..85 .8].75 1.5 1 .15].2 % volatility parameters: % \sigma_11.75 . t=flipud(tT).

*th0(ones(1..2). % plot % figure.2)+sum(sig.2).1).2)=sum(x0. ylabel(’y(t.08.1)=sum(x0.*th0(ones(1.8. d=.*tT)*(1-th0(5))+th0(5))..ones(2.3:4).*th0(ones(1. x0=ones(len..8:9). (th0(10)-exp(-sum(x0. if rand>p0(1. ct=c+d*(1+sin(f+2*pi.5*dt*sum(sig.*th0(ones(1.2*x0(it-1)-1) x0(it)=2.1:2).*tT)). end end x=x0.6:7). f=. % volatility function % x0=[x0==1 x0==2]. sig(:. two-factor model’) xlabel(’time t’).*sig.T)’) 55 . % state 1 x0(1)=unidrnd(2).1)). sig=ct(:. sig(:.2)*sqrt(dt).*randn(len.*..len). for it=2:len. % simulate path of forward returns % y=-0.2).c=. (exp(-sum(x0.1). % seasonality parameters % seasonality function % sample state vector x0 % len=size(tT.len).2).*t)).*.len).len). plot(y) title(’forward data sample.31.2).*sig.

16 .5 5 5 1 .10). clear all % initialize % iter=1e5.25 .. .1. % initial parameter values rg=[zeros(1..m Gibbs sampler. % allocate % call nbp_2fac.36 .m for data % guess transition probabilities % prior expectation of % probability matrix th(1.84].4). % bounds for parameter values 56 .m Parameter estimation of Markov switching model with MCMC clc. g=p(1...5 5 5 1].:)*15.10).64 .5 1. th=zeros(iter. % priors % p(1.75 2 2 .5 1 2 2 1].Appendix D mcmc. burnin=iter/5.:)=[.5 .5 1. p=zeros(iter. % generate simulated data % nbp_2fac.:)=[. mcmc. 1.

n11=sum((x(1:end-1)==1)+(x(2:end)==1)==2). % count transitions between states n21=sum(diff(x)==-1).idx) + rth*randn.4)+n22]). 57 . st=[x==1 x==2]. p1=[p1(1) 1-p1(1) p1(2) 1-p1(2)]. % random parameter choice % generate th1(idx)=th(k-1. n22=sum((x(1:end-1)==2)+(x(2:end)==2)==2).025. for k=2:iter sp=zeros(len.2*x(it-1)-1) x(it)=2.[g(1. % sample initial state vector x % x=ones(len. p(k. sc=zeros(len. % update % Metropolis-Hastings algorithm % idx=unidrnd(10).:)=p1.2).:). % step size parameter updates % state 1 % allocate % sample transition probability matrix p % n12=sum(diff(x)==1).2). end end % algorithm % th1=th(1.2)+n12 g(1.1)+n11 g(1.2). % sample from Beta distribution p1=betarnd([g(1. x(1)=unidrnd(2). if rand>p(1. sf=zeros(len.rth=0.1).3)+n21]. for it=2:len.

sf(2:end.1) zeros(len-1.idx).t.dt.:)/(sf(it.tT.1)].dt.[zeros(len-1.t. end % backward sampling % x=ones(len.st.m llh=sum(log(mclh(y. th(k.. end % filtering.:).:)=th1. else th(k.:).len-1).:)=sf(it.1)]..len)).llh*pr(1)/pr(2)).rg(1..:)=0..idx)).[ones(len-1.dt.:).st. sf(1.. sp(it.idx)].1)=mclh(y(2:end). sf(it.dt.:)=sp(1.len-1)..:). -log(mclh(y. % prior densities pr=unifpdf([th1(idx) th(k-1. % acceptance probability alpha=min(1. sf(2:end.:). for it=2:len sf(it.th1.:)=sf(it. th(k.5*(p1(1:2)+p1(3:end)).:)=sf(it.t(2:end).th(k.th(k-1.t(2:end).tT.2)*p1(3:end).1)*p1(1:2)+sf(it.tT(2:end). if rand>sf(end.% complete-data likelihood % call mclh.:).1)+sf(it. end for it=len-1:-1:1 % state 1 58 .len))).1) ones(len-1.. if rand<=alpha.tT(2:end).1) x(len)=2.*sp(it-1.:).rg(2.. FFBS algorithm % % forward filtering % sp(1.:)=th(k-1.2)).1).2)=mclh(y(2:end).

sig(:. lh=lh. % update end % output % mu_th=mean(th(burnin+1:end.sc(it. the function mclh.2).8:9).:)/(sc(it.:)=sc(it.*sig.*tT)).1)+sc(it.1)=sum(x.T).x.*(th(5)+ exp(-sum(x./mu). function [lh. mclh.*th(ones(1.1:2)./sqrt(mu).3:4).*tT)*(1-th(5))).*t)).:)) In the routine for the Gibbs sampler.T).m Returns components of complete-data likelihood function sig=zeros(T.:).31+2*pi.^2). sig=ct(:.m is called to evaluate the complete-data likelihood for various values of the parameters.dt. This function is given below.*th(ones(1.5*((y+0.sig]=mclh(y.2)=sum(x.5*mu).t.*th(ones(1.08*(1+sin(. if rand>sc(it. end end th1=th(k.T).ones(2.*(th(10)exp(-sum(x.*th(ones(1.8+.2).1) x(it)=2. mu=dt*sum(sig.2). sc(it.6:7).2).2).:)) mu_p=mean(p(burnin+1:end. lh=exp(-0.tT.:).1)).T).*sf(it.2). 59 .:)=p1([x(it+1) x(it+1)+2]).T).2)). sig(:.*sig.th. ct=.

13). th=zeros(iter.1:12). tT=tT(1:end-1.:)*15.4).1:12)). burnin=iter/5. p=zeros(iter. % guess transition probabilities % prior expectation of % probability matrix 60 .1:12))-log(f(1:end-1. g=p(1. clear all % initialize % iter=2*1e2.84].:)=[.36 . load tT y=log(f(2:end.m Parameter estimation of Markov switching model with MCMC clc.% daily % priors % p(1. mcmc. dt=1/252.16 .64 .m Gibbs sampler. % allocate % generate simulated data % load f.Appendix E mcmc.

for k=2:iter sp=zeros(len.1).1).:)=[. x(1)=unidrnd(2).x(it)=2. .5 .5 5 5 1 1.. 1:dim(1).3]. t=flipud(tT).% use linear indexing % construct return & maturity vectors with % corresponding data points y=y(sample)’. % allocate % sample transition probability matrix p % 61 .03.1)..8 .% time % draw x len=size(tT.th(1. sample = sub2ind(dim.1.5 5 5 1 1 1 1].2).2).8 2 2 .5 1.5 1.dim(1).:).08 . rth=0. lam=unidrnd(dim(2).2).2*x(it-1)-1). sf=zeros(len.5 1 1 3 .3 . lam’).end end % algorithm % th1=th(1. if rand>p(1. tT=tT(sample)’.7 . sc=zeros(len. % bounds for parameter va % step size parameter updates % implement ’randomized’ algorithm % dim=size(y). % initial parameter values rg=[zeros(1. x=ones(len. for it=2:len.13).

t..n12=sum(diff(x)==1).dt.1)=mclh2(y(2:end). -log(mclh2(y.idx))..tT(2:end). th(k. FFBS algorithm % % forward filtering % sp(1. n11=sum((x(1:end-1)==1)+(x(2:end)==1)==2). sf(2:end.llh*pr(1)/pr(2)).st. n22=sum((x(1:end-1)==2)+(x(2:end)==2)==2).idx)].st.5*(p1(1:2)+p1(3:end)).[g(1.th1. % complete-data likelihood % call mclh.t.dt. % acceptance probability alpha=min(1. sf(1.:)=p1.:)=th(k-1.rg(1. % update % Metropolis-Hastings algorithm % idx=unidrnd(13). % prior densities pr=unifpdf([th1(idx) th(k-1.1)+n11 g(1. st=[x==1 x==2].:).th(k.:)=sp(1.1)].tT.:).t(2:end). if rand<=alpha. 62 .:).idx) + rth*randn. % sample from Beta distribution p1=betarnd([g(1..[ones(len-1.len)).:)=0.th(k-1.2)+n12 g(1. else th(k.m llh=sum(log(mclh2(y.1) zeros(len-1..tT.:)=th1.4)+n22]). % random parameter choice % generate th1(idx)=th(k-1.rg(2.dt.len-1).len))). p(k.idx).:).. % count transitions between states n21=sum(diff(x)==-1).3)+n21]. end % filtering. p1=[p1(1) 1-p1(1) p1(2) 1-p1(2)].

:)=p1([x(it+1) x(it+1)+2]). if rand>sc(it.:)=sf(it. sc(it. plot(th(:.1)+sf(it. end end th1=th(k.:)=sc(it.t(2:end).1) x(it)=2.:)) mu_p=mean(p(burnin+1:end.1)+sc(it.:)=sf(it. sp(it.. for it=2:len sf(it.:)=sf(it.2)=mclh2(y(2:end).sf(2:end.[zeros(len-1.dt.:).2)).1).:).6) end % output % mu_th=mean(th(burnin+1:end.:)) % plot % % volatility parameters subplot(2.:)/(sc(it.len-1). sf(it..2. th(k.*sf(it.*sp(it-1.tT(2:end).:)/(sf(it.:)..:).2)*p1(3:end).1)*p1(1:2)+sf(it.1). if rand>sf(end.1) x(len)=2. % update % debug %th(k.1) ones(len-1.1)) 63 .:). end % backward sampling % x=ones(len.2)).1)]. end % state 1 for it=len-1:-1:1 sc(it.

/sqrt(mu).3).31+2*pi. plot(th(:.6)) subplot(2.08*(1+sin(.2).3).T) Returns components of complete-data likelihood function sig=zeros(T.dt.6:7).2.5*mu).*th(ones(1.*(th(10)-exp(-sum(x./mu).*t sig=ct(:.8:9).1).4).2). lh=lh.x.2)) subplot(2. plot(th(:.sig]=mclh2(y.1:2).*(th(5)+exp(-sum(x.*th(ones(1.3:4).T). plot(th(:.1)=sum(x.2. plot(th(:.5*((y+0.m is called to evaluate the complete-data likelihood for various values of the parameters.2)=sum(x.*t)).8)) subplot(2.*th(ones(1.1)).2). plot(th(:.*sig.9)) In the routine for the Gibbs sampler.^2).4)) subplot(2.*th(ones(1. function [lh. plot(th(:. mu=dt*sum(sig. the function mclh2. lh=exp(-0.th. 64 . plot(th(:.2.subplot(2.T).8+.7)) % attenuation parameters figure subplot(2.2).*sig.2). ct=th(11)+th(12)*(1+sin(th(13)+2*pi.t.2).2). %ct=.*t)).ones(2.tT.*tT sig(:.3)) subplot(2.2).T). This function is given below.2.T).2.2.4). sig(:.2.

Clewlow. L.“Gaining from complexity: MFMC models”. 1313-1321. [3] Carlin. (2000). 79-97. [5] Chib. Proceedings of the 33rd Hawaii International Conference on System Sciences. & Koekebakker. 46. [7] Clewlow. S. [9] de Jong. M. Energy Risk. (2008). & R. 353–88. C. (2009) “Modelling and estimating the forward price curve in the energy market”. 60-64. 65 . (1996). [10] Deng. L.”. Huisman (2002).Bibliography [1] Benth.. Kwok. (2008).. N. QFRC Research Paper Series 28. 1116-1157. Working Paper. “Calculating posterior distributions and modal estimates in Markov Mixture models”. Journal of Royal Statistical Society B. F. & Kang. C. S. (1995). [6] Chib. [2] Breslin. S. “Option formulas for mean-reverting power prices with spikes. Clewlow. Rotterdam School of Management at Erasmus University. Energy Economics 30. & Strickland. Journal of Econometrics 75. “Pricing electricity derivatives under alternative stochastic spot price models. C. J. & Strickland. Sydney. [4] Chiarella. & Polson. “Piecewise-deterministic Markov processes: a general class of non-diﬀusion stochastic models”.. [8] Davis. C. C.Working Paper. Journal of the American Statistical Association 90. (1984). S. “A multi-factor model for energy derivatives”. April. L. “Monte Carlo Bayesian methods for discrete regression models and categorical time series”. B. (1992). University of Technology. “Marginal likelihood from the Gibbs output”. Bayesian Statistics 4.”. 577-586. “Stochastic modeling of ﬁnancial electricity contracts”. B. (1999).

(1993). (1992). 3-15. (1973). W. Yu. J.“Mean-variance hedging of options on stocks with Markov volatilities”. [12] Elliott. Handbook of Financial Econometrics. R. New York. & Polson. S. ” The Journal of Finance 45. (1995). [19] Hamilton. R. Kabanov. (1990). “A Markov model for switching regressions”. New York.. A. (1989). 66 . 1969-1984. Jarrow.[11] Di Masi.R. [17] Goldfeld. & Spiegelhalter D. “Finite Mixture and Markov Switching Modu els”. M.D.J. Linz 2007-09.“Option valuation and hedging strategies with jumps in the volatility of asset returns”. & Poulsen. 959-976. [15] Gibson. E.M. D. (1994). Econometrica 60. Finance and Stochastics 4. “Bond pricing and the term structure of interest rates: a new methodology”. Aggoun. “Markov Chain Monte Carlo in Practice”. 172-182. Econometrica 57. Theory of Probability and its Applications 39. S. (2006).B. (2001).D. [21] Hansen. [13] Elliott. & Wilson. A. G. Springer. V. J. (2007). Springer-Verlag.S. [18] Hahn.“Analysis of time series subject to changes in regime”. & Morton. M. “Markov Chain Monte u Carlo methods for parameter estimation in multidimensional continuous time Markov switching models”. [23] Johannes.Journal of Econometrics 1. (2000). “Stochastic convience yield and the pricing of oil contingent claims. “The term structure of interest rates when a Markov chain is driving drift and volatility parameters of the short rate diﬀusion process”. “Hidden Markov Models: estimation and control. & Quandt. R. S. Journal of Econometrics 45. 39-70. Working Paper. N. London. applications of mathematics”. & Moore. (1990). 409-29. Fr¨hwirth-Schnatter. “A New approach to the economic analysis of nonstationary time series and the business cycle”. 357-384. “A simple regime switching term structure model”... R. [14] Fr¨hwirth-Schnatter. RICAM.. J. & Sass. Chapman & Hall. 77–105. R.E. (1998). L. [22] Heath. M. & Schwartz. & Runggaldier W. R. Richardson. (2002). J.T. C. Journal of Finance 48. [20] Hamilton. [24] Naik. [16] Gilks.J. “MCMC methods for continuous-time ﬁnancial econometrics”. S.

“Energy risk: valuing and managing energy derivatives”. M. S. (2004). & Uhrig-Homburg. [29] Valchev. 337-351. Brockwel A.R. & Seppi. McGraw-Hill. D. “ Modelling jumps in electricity prices: theory and empirical evidence”. S. Review of Derivatives Research 10. J. “A threshold autoregressive model for wholesale electricity prices”. 59-85. [26] Rambharat. (2007). “Stochastic volatility Gaussian Heath-Jarrow-Morton models”.E. [28] Seifert. Second edition. B.J. [27] Scott. 347-368. 287-299. “Bayesian methods for Hidden Markov models”. 54. (2002). (2005). D.. Applied Mathematical Finance 11. 67 . The Journal of the American Statisctical Association 97. Journal of the Royal Statistical Society C.[25] Pilipovic. (2007).

- Kalman Filter and Economic Applications
- Chapter4.1 HMM
- Tutorial
- Thesis
- Lecture 14
- Rainflow Matrix for Switching Random Loads
- 04MA246L4C
- Preload
- Market Volatility- Causes and Consequences
- 2004 Zhang
- Artemis Capital Q12012_Volatility at World's End
- What
- Systems Volatility
- 3495_expandedtocetc
- Analytic Methods for Pricing Double Barrier Options Volatility Faulhaber 2002
- Know Your Weapon 1
- Pricing Under Pressure
- Semi-Huber Quadratic Function and Comparative Study
- Option Greeks
- An International Carbon-Price Commitment Promotes Cooperation Eeep4-2-Cramton
- WESM Handbook Vol. 1
- Examining the Markets for Nordic Electricity Price Area Differentials (EPAD) ‐ Focus on Finland
- SSRN-id1640552-1
- A u t u m n 2 0 0 9
- content asp pdf (2)
- Doc 1
- kroszner_20071022
- Williamson Trade-Off Model
- 31235_1975-1979

Are you sure?

This action might not be possible to undo. Are you sure you want to continue?

We've moved you to where you read on your other device.

Get the full title to continue

Get the full title to continue reading from where you left off, or restart the preview.

scribd