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

BooksAudiobooksComicsSheet Music### Categories

### Categories

### Categories

### Publishers

Scribd Selects Books

Hand-picked favorites from

our editors

our editors

Scribd Selects Audiobooks

Hand-picked favorites from

our editors

our editors

Scribd Selects Comics

Hand-picked favorites from

our editors

our editors

Scribd Selects Sheet Music

Hand-picked favorites from

our editors

our editors

Top Books

What's trending, bestsellers,

award-winners & more

award-winners & more

Top Audiobooks

What's trending, bestsellers,

award-winners & more

award-winners & more

Top Comics

What's trending, bestsellers,

award-winners & more

award-winners & more

Top Sheet Music

What's trending, bestsellers,

award-winners & more

award-winners & more

P. 1

Estimating Forward Price Curve In|Views: 196|Likes: 0

Published by Ian Galea

See more

See less

https://www.scribd.com/doc/61736271/Estimating-Forward-Price-Curve-In

08/06/2011

text

original

- Introduction
- 1.1 Stylized facts of energy forward price dynamics
- 1.2 Literature review
- Forward price curve model
- 2.1 Multi-factor single-commodity model
- 2.2 Spot - forward price relationship
- 2.3 Seasonality adjustment
- 2.4 Multi-factor multi-commodity model
- 2.5 Two-factor regime switching forward price curve model
- Estimation
- 3.1 Data transformation
- 3.2 Bayesian estimation for a Markov switching model
- 3.3 Prior distributions
- 3.4 Gibbs sampler
- 3.4.1 Full conditional posterior distributions
- 3.4.2 Sample the transition matrix
- 3.4.3 Sample the model parameters
- 3.4.4 Markov Chain state simulation
- Implementation
- 4.1 Data
- 4.2 Choosing the prior
- 4.3 Running the Gibbs sampler
- 4.3.1 One-factor model
- 4.3.2 Two-factor model
- 4.4 Numerical Results
- 4.4.1 One-factor model
- 4.4.2 Two-factor model
- 4.4.3 Historical NBP forward data
- nbp 1fac.m
- nbp 2fac.m
- Bibliography

**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

modeling of natural gas price forward curves is discussed. iii . The model is a Markov Switching model: the parameters. Compared to a previous study it is found that.Abstract In this essay. 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. A two-factor. A study is performed for a number of 2 states using data from NBP. over the span of the data period. A higher volatile environment for natural gas could be explained by the global ﬁnancial crisis which unfolded during the period of observation. A Markov Chain Monte Carlo (MCMC) technique is used for estimation of the parameter set and the transition probability matrix. more time is spent in a highvolatility regime. Although. regime switching model is proposed to model forward price dynamics. for the better part of the time horizon the Markov Chain still settles in regime 1. Further. the Markov Chain stays in regime 2 more often. That is. the state transitions are driven by a ﬁnite state Markov Chain.

. . . . . . . . . . .2 Sample the transition matrix . . . . . . . . .Contents List of Tables List of Figures 1 Introduction 1. . . . . . . . .4 Markov Chain state simulation . . . 4 Implementation 4. . . . . . 4. . . . . . . 3. . . . . . . . . . . . . 2. . . . . . . . . . . . . . . . .3 Sample the model parameters . . . .4 Gibbs sampler . . . . . . . . . . . . . . . . . . . .3. . . 3. . 3. . . . . . . . . .2 Choosing the prior . . . . . . .forward price relationship . . . . . . . . 1. . . . . . . .3 Prior distributions . .3 Seasonality adjustment . . .1 Data . . . . . . . . . . . . . . . . . . . . . . 3. . .1 One-factor model . . . . . 4. . . .2 Spot . . . . . . . . . .2 Bayesian estimation for a Markov switching model 3. . . . . . . . . . .4 Multi-factor multi-commodity model .1 Multi-factor single-commodity model . . . . . . . . .1 Data transformation . . . . . . . . . . . . . . .3 Running the Gibbs sampler 4. . . . . . . . . . . . 2 Forward price curve model 2. . . 2.4. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2 Literature review . . . . . . . . . . . . .4. . . 3. . . . . . . . . . . . . . . . . . . . . model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2. . . . . .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 . . . . . . . . . . . . 2. . . . . . . .3. . . . . . . . . 3. . . . . . .2 Two-factor model . . . . . . . . . .1 Full conditional posterior distributions . . . . . .4. . . .1 Stylized facts of energy forward price dynamics . . . . . .4. . . 3 Estimation 3. . . . . 4. . . . . . . . iv . . . . . . . . . . . . .

. . . . . .4. 4. . . . . . . . . . . . . . . . .3 Historical NBP forward data . .m D mcmc. . . .4 Numerical Results .4. . . . 36 36 38 45 47 48 50 54 56 60 65 5 Conclusion A nbp 1fac.1 One-factor model .m Bibliography v . . . . . . 4.m C nbp 2fac. . . . . . . . . . . . .4. . . . . . . 4. . . . . . . .2 Two-factor model . . . . . . . . . .4.m E mcmc. . . . . . . . . . . . . . . .m B mcmc. . . . . . . .

List of Tables vi .

Path of parameter estimates for αij . .List of Figures 1. (i. yT . . . . .4 4. . . . . . . . . . . . . . . . . . . 5 6 8 Annualized covariance surface for NBP data F (t. . . . . . . Diﬀerent forward price curves. . . . . .2 1. . . . . . 2) . . . . . .1 1. 16 First three volatility functions for NBP data F (t. .1 4. . . . . Path of parameter estimates for σij . j = 1. . j = 1. F (t. . .5 4. . . j = 1.2 4. T ) . . . . . . . . . . .3 4. yT . . . . . Path of parameter estimates for σ1j and α1j . . . . . . . . . . (i. . T ) . .7 Forward price curves from Oct-2007 to Mar-09. . . . 2) . . . . . . . .2 4.3 2. . . . T ) . . . F (t. . 2) . (i. Log diﬀerences of forward prices yT . 2) . (i. 17 Generated forward price dynamics. . . 34 37 38 40 41 43 44 vii . Path of parameter estimates for αij . .6 4. . . . . . . . . . . . . T ) . . .1 2. . . . . j = 1. Path of parameter estimates for σij . . (j = 1. . . . . . 2) Generated forward price dynamics. . . . . . . . .

the estimation procedure is applied to real market data. [18]. 1 . The paper is built as follows. in Chapter 2 the general multi-factor multi-commodity model by Breslin et al. Chapter 4. In a following chapter. Subsequently. The dynamics of the two volatility functions are thus driven by shifts in the Markov Chain. 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. the properties of energy forward prices are discussed. Next. in Chapter 5 conclusions are drawn and suggestions for further research are discussed. in Chapter 1. a brief overview of theoretical and practical work by other authors is provided. 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. It is then important to incorporate those diﬀerences in the model to better explain the forward price dynamics of energy assets. Energy markets diﬀer from non-physical. a number of numerical examples and calibration results from simulated data are considered. the analysis by Chiarella et al. [4]. Also. [2] is introduced after which a two-factor regime switching model for the natural gas forward price curve is described. First. [4] is replicated with updated natural gas forward price data.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. Finally. The algorithms impleu mented are extensively discussed and code of the respective routines is supplied. ﬁnancial markets. Here. The model was initially proposed by Chiarella et al. The parameter estimation procedure is then explained in Chapter 3.

The heating demand in the state of Massachusetts is expected to surpass the heating demand for Florida. but longer-term contracts did not move dramatically. hence. These market characteristics should be captured to model eﬃciently the evolution of natural gas forward curves. In the case of energy commodities mean-reversion depends on how fast the market supply side responds to certain events. On the demand side. Or. consumption and storage. • Mean reversion Mean reversion is the process of a market returning to its equilibrium price level. could be a return on equity. On the other hand. These seasonality eﬀects are recurring and. to which the market for natural gas belongs. in energy markets mean reversion is much stronger and related to various. In ﬁnancial markets the actual rate of mean reversion is rather weak and tied to economic cycles. there are considerable seasonality eﬀects of residential users. the main features of energy forward price dynamics are presented. the magnitude of these peaks and troughs. Most of these diﬀerences can be traced back to supply and demand fundamentals. Natural gas is consumed mostly during the winter. diﬀer from nonphysical markets such as the markets of interest rates and equities. how fast events go away (Pilipovic [25]). incorporated in observed forward prices (Pilipovic [25]). a commodity price or a historical interest rate. called mean level. In 2005. dynamics of production. for example. the hurricanes Katrina and Rita damaged a number of natural gas processing facilities on the US Gulf Coast. price spikes occurred in the spot and short-term forward markets. hurricanes or other headline-grabbing events. The loss has delayed the recovery of natural gas production in the area. 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]. also. will vary according to the region. Below.1 Stylized facts of energy forward price dynamics Energy markets. or the degree of seasonality. one expects natural gas prices to peak during winter and drop to lows in summer period. diﬀerent drivers. Events that produce supply-demand imbalances could be wars. • Seasonality One of the major fundamental price drivers in energy markets is weather. As a result. The 2 . Further. All drivers which are not found in the traditional markets. Therefore. This is witnessed in most ﬁnancial and physical markets where the equilibrium level.1.

hence. T ). the log diﬀerence transform is applied to the original data F (t. 3 . For parameter estimation of the chosen model. which is the British virtual trading location operated by TSO National Grid. Likewise. • High volatility Production and storage are two supply drivers which are nonexistent in ﬁnancial markets. prices will easily reach very elevated levels (Pilipovic [25]). Natural gas at NBP trades on a forward month. 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. when there is no natural gas to go around. forward season or year forward basis and prices are expressed in pence (GBp) per therm. and long-term forward prices reﬂect behavior of future potential energy. The latter two characteristics demonstrate that the issue of storage causes energy prices to display a split personality. long-term forward prices reveal a rather stable equilibrium price level.T for every maturity T . T ). Where short-term forward prices are the result of energy in storage. Expectations of market production and costs in the long run will be expressed in the levels and yields of long-term forward prices. the short. in order to obtain the forward dynamics yt. Throughout the essay. Further. So while energy markets share some properties with traditional ﬁnancial markets. as revealed by the forward prices. the volatilities of forward prices decrease signiﬁcantly with increasing maturities. forward quarter. daily observations for the forward prices were obtained with maturities T ranging from July 2009 to September 2012. Especially spot and short forwards exhibit high levels of volatility. covering all entry and exit points in mainland Britain. It can be expected that in the long run supply and demand will be balanced and. This data is represented by F (t. For example.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]).mean reversion. they have unique and challenging workings. The observations span over a year with prices at times t from 23/10/2007 to 12/03/2009. It is the most liquid gas trading point in Europe. As a result. The natural gas prices modeled are forward prices for the National Balancing Point (NBP). Although spot prices show extremely high volatility. And these should be taken into account when modeling natural gas forward dynamics (Pilipovic [25]). • Decreasing term structure of forward curve volatility Storage limitation is thus a major volatility driver. thus depended on how fast the production side could restore the supply imbalance (Pilipovic [25]).

the notation yT is used to represent the forward dynamics yt.T for each maturity T along all points in time t. 4 .

Figures 1. T ) 5 . T ) and yT respectively.2 below show the behavior of F (t. F (t.1: Forward price curves from Oct-2007 to Mar-09. Figure 1.1 and 1.

2: Log diﬀerences of forward prices yT 6 .Figure 1.

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. It is therefore easy to see that a regime switching model could be suited to approximate this behavior. after which things turn back to normal and a more stable price pattern emerges. 7 . the forward curves spike during a certain period. Such an increasing price curve is called contango. Or any combination of contango and backwardation could occur along the forward price curve. Finally. Although diﬀerent shapes could occur such as a decreasing path for the forward curve which is called backwardation. natural gas for delivery further out in time is usually more expensive than delivery in the near time. Also. 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. The diﬀerence is explained by the carry.

F (t. Figure 1.Figure 1.3: Diﬀerent forward price curves. T ) 8 .3 depicts some of the forward price curves observed.

Therefore. major exogenous economic events such as OPEC oil shocks aﬀect ﬁnancial time series. Two regimes are distinguished: if there is excess demand. with a certain probability. the observed point lies on the supply function and if there is an excess demand. 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. For maximum likelihood estimates of the respective parameters. when modeling. A regime switching model where the transitions are governed by a Markov process is called a Markov Switching model. Next. Therefore. a process that governs the transition has to be deﬁned. Episodes of dollar appreciation relative to other currencies are followed by episodes of dollar depreciation. diﬀerent behavior is assumed in one subsample or regime to another. a regime switching model is proposed.2 Literature review In order to model the gas forward curve. an EM algorithm is applied. It is considered a useful approach because many economic time series are known to exhibit dramatic breaks in their behavior. An unobserved Markov process is assumed to govern the regime. Hamilton [19] and [20] extends the approach to asset prices. There has been an enormous amount of theoretical and practical work on regime switching models. In Hamilton [19] the approach by Goldfeld and Quandt [17] is used to describe exchange rate dynamics. where a discrete-valued Markov process governs the shifts. in a regime switching model the dollar rate is allowed to switch. 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. is called a Markov process. In Hamilton [20] a vector autoregression model is put forward subject to occasional discrete shifts. Since the prevailing regime is not directly observable. Applications of Markov regime switching processes to asset price volatility modeling can be found in contributions by Naik [24] and Di Masi et al. In a seminal paper. 9 . This set-up is applied to a model for a housing market in disequilibrium. Changes in asset prices are driven by speciﬁc identiﬁable events.1. a process where the current state depends only on the state before. Further. it lies on the demand function. [11]. For example. Goldfeld and Quandt [17] propose a regression system of demand and supply functions thought to be switching between the two equations or regimes. between an appreciation and depreciation regime.

The class of piecewisedeterministic processes. In between jumps the volatility follows an almost deterministic process. these modeling approaches for ﬁxed income markets could be applied to energy markets. only the drift rate of the short rate was modeled by a continuous Markov chain. Fixed income models have been an important source for applications to energy price modeling. Those jumps are driven by various unsystematic and systematic events. [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. not merely the volatility of the short rate. amongst others. the evolution of the whole term structure of volatilities is explored. especially the Heath-Jarrow-Morton (HJM) model by Heath et al. The Markov Chain speciﬁcation allows for jump discontinuities and captures the various shapes of the term structure of volatilities as well. The energy forward price curve exhibit features similar to forward interest rate dynamics. 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. Examples are mergers and acquisitions. a volatility model that captures the outcomes of such events is proposed. Di Masi et al. Hansen and Poulsen [21] and Elliott and Wilson [13]. introduced by Davis [8]. One could take two approaches for stochastic modeling of ﬁxed income markets. First. In order to hedge claims contingent on risky assets. 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. Also. [22]. shifts in corporate strategy and changes in economic policy. It means that forward rates are modeled directly. The model is an extension of the class of deterministic volatility HJM models to the wider class of HJM models with piecewise-deterministic volatility. For example. one could specify the complete yield curve dynamics directly which is suggested by the HJM approach. that is the volatility function is non-stochastic.The volatility of risky assets is aﬀected by random and discontinuous shifts over time. The volatility modeled is stochastic only through its dependence 10 . Alternatively. which is only one point of the volatility curve. Markov Chain models for the instantaneous short-term interest rate were introduced by. Since commodities trade both in spot and forward markets. The work of Valchev [29] builds on that of Elliott and Wilson [13]. provides a suitable framework for modeling the dynamics of the volatility term structure. but a Markov Chain stochastic volatility HJM model is introduced.

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. the MCMC set-up and respective algorithms suggested by Fr¨hwirth-Schnatter [14] and Hahn. forward dynamics are derived calling arbitrage theory. Therefore. for example. An application to energy markets was ﬁrst found in Rambharat et al. Deng [10] and de Jong & Huisman [9]). Also Seifert & Uhrig-Homburg [28] follow a similar approach to model European electricity spot prices. [12] and Valchev [29]. based on the framework provided by Chiarella et al. Elliot 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. most of existing literature focuses on developing realistic spot price markets. A forward ﬁltering backward sampling (FFBS) algorithm is applied to the case of regime-switching models. 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. 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]. 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. Johannes & Polson [23] provide a general algorithm based on the work by Scott [27]. In this essay. In energy markets modeling. 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. The approach taken in this essay. is in the spirit of Davis [8]. [26] which estimates a discrete time model for electricity prices using a Markov Chain Monte Carlo (MCMC) approach. [4]. MCMC techniques are used to explore these distributions. 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. for the estimation of the parameters of the proposed volatility functions a Bayesian solution is proposed. u Fr¨hwirth-Schnatter & Sass [18] are implemented to estimate the parameters of the u 11 . various regime-switching models are calibrated to electricity spot prices (see. [12]. Finally. Based on a stochastic model for the time evolution of the spot price.on the Markov Chain.

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. [4] for the estimation of natural gas forward prices which is explained thoroughly and deployed in this essay. 12 .

multi-commodity (MFMC) model is introduced. more than one single factor of uncertainty needs to be introduced to capture forward curve changes other than parallel moves along the curve. a single factor. both parts of curve change shape in diﬀerent ways (see Breslin et al. Further.1) Here. Subsequently. 13 . z(t) is an independent Brownian motion. This can be done by adding independent Brownian motions (Breslin et al. as incorporated in (2. T ) = σ(t.1). Therefore. T ).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. T ) (2. [2]).Chapter 2 Forward price curve model In this chapter a general multi-factor. in the next section the process of parameter estimation from historical data is explained. And. [2]). It determines the magnitude and direction of the single random shock that drives changes in the forward curve.1 Multi-factor single-commodity model From the stylized facts detailed above in Section 1. T )dz(t) F (t. the term F (t. is not suﬃcient to explain the behavior witnessed in the markets. It is the sole source of uncertainty and is associated with a volatility function σ(t. The volatility function could be interpreted as the the time t volatility of the T maturity forward price return. T ) stands for the forward price at time t with expiry T . However. 2. dF (t. the front end of the curve displays much more volatility than the end of the curve.

Three independent Brownians. One method that can be applied is principal components analysis (PCA) or eigenvector decomposition of the covariance matrix of the forward returns. 12 diﬀerent contracts are included. T ). tilt and bend the forward curve. represented by F (t. Ito’s lemma is applied to (2.σ2 (t. In practice.2) will represent changes in shapes where diﬀerent parts of the forward curve will move in diﬀerent ways (Breslin et al. Sample covariance values between pairs of forward price returns are calculated. For every source of risk there is a correspondent volatility function σi (t. (2. T ) n σi (t. However. The ﬁrst function is positive for all maturities which implies that a positive shock to the system causes all prices to shift up. T ).2) for a single commodity with n factors is rewritten. only a few of these will be signiﬁcant for explaining the variation in the forward curve. T ) and σ3 (t. dzi (t). The respective volatility functions can easily be obtained from time series analysis. In order to start estimating the volatility functions.2) The evolution of the forward price is now driven by n independent Brownian motions. Finally. the third factors is a bending factor which causes the long and short ends to move opposite to the middle. T ) = F (t. Equation (2. A typical example of a multi-factor model is a model with three risk factors. As a result. The second most important factor is a tilt factor which causes the short and long ends of the curve to move in opposite directions. [2]). Then the eigenvectors of the covariance matrix yield approximate the factors governing changes in the forward curve (Breslin et al. T ) which respectively act to shift. T ).3) 14 . [2]). dz2 (t) and dz3 (t) correspond to the functions σ1 (t. t + τj )∆zi (2. In our data sample. it is found that a number of three factors is usually adequate to capture the forward price dynamics (Breslin et al.The stochastic diﬀerential equation (SDE) below represents a general multifactor model of the forward curve: dF (t. t + τj ) = − 2 n n σi (t.2). The respective volatility functions now deﬁne the magnitude and direction of multiple shocks that trigger changes along all points on the forward curve. Therefore. dz1 (t). T )dzi (t) i=1 (2. which renders the following forward curve dynamics: 1 ∆ log F (t. [2]). t + τj ) ∆t + i=1 i=1 2 σi (t. there are 12 factors that can explain the variance of the evolution of the curve.

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

1. dS(t) = S(t) ∂lnF (0. seasonality should be taken into account when modeling evolution of the forward curve.2. Further. all random shocks from the start of the process up till the current date are incorporated in the spot price.8) is found between square brackets. t) = S(t) (see Breslin et al.2) could be rewritten as a product of a timedependent spot volatility function and maturity-dependent volatility functions (Breslin et al. t) du + ∂t t 0 ∂σi (u. [2]).2) is integrated. an SDE is obtained which describes the spot price dynamics. At the front end of the curve the maturity date is equal to the current date t. an equation for the evolution of the spot price can be written down which is consistent with forward price dynamics. This is called day-ahead delivery. One could estimate a diﬀerent volatility function for each season. the spot price is essentially the front end of the forward curve. t) − ∂t n n 0 t σi (u. Following a further diﬀerentiation. (2. [2]). The spot price is given by. (2. where seasons are obtained by splitting the data. In the case of natural gas the delivery will take place the next day.3 Seasonality adjustment Further.8) + i=1 σi (t. F (t. t) i=1 ∂σi (u. the functions of (2. Therefore. Since the forward curve and spot dynamics are related.2) thus becomes: 18 . 2. t) dzi (u) ∂t dt (2.2 Spot . Hence. The spot price process described is thus non-Markovian. Alternatively. as mentioned in Section 1. Examples are summer/winter and summer/autumn/winter/spring.forward price relationship The dynamics of the forward curve are related to spot price dynamics. an important stylized fact of energy markets is seasonality in the forward price volatilities. It contains integrals over the Brownian motions from time zero to time t. That is. The spot price is the price quoted at which a particular commodity can be bought or sold for immediate delivery. t)dzi (t) The drift term of (2.

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.10) describes the joint forward curve dynamics of multiple commodities as: dFc (t. (2. .dF (t. are still zero. . .i (t. represent the inter-commodity correlations (Breslin et al. But now the correlations between the Brownian motions driving diﬀerent commodities c.2) could be further generalized to incorporate multiple commodities. the correlations between the Brownians governing a commodity. 2. as described by equation (2. . . . • µ(t) is the vector of drift terms over the time step. . For example. [2]). dzi (t) for a given commodity c. i = 1. . m stands for the diﬀerent commodities and i = 1. Spark spread modeling is critical in order to value power plants. T ) = σs (t) F (t. . Equivalent to the approach taken for a single commodity. Then.i (t) i=1 (2. . T )dzc. T ) nc σc.i (t). nc points out the particular volatility function that corresponds to each commodity. T ) = Fc (t. The correlation between the diﬀerent commodities is ﬁxed by a correlation matrix for the Brownian motions. T ) n σi (T − t)dzi (t) i=1 (2. Practitioners in energy risk management often have to deal with joint modeling of diﬀerent commodities. dzc.10) where c = 1. .4 Multi-factor multi-commodity model Equation (2. . the discrete-time evolution of the forward curve can be written in terms of the estimated volatility functions. ¯ 19 . Obviously. the spark spread is the spread between the power price and the price for natural gas used to produce the electricity. n who respresent the n maturity-dependent volatility functions.9). This results in the following matrix representation: ˜ε x(t) = µ(t) + Σ¯ ¯ ¯ where (2.9) where the spot price volatility at time t is described by σs (t) and σi (T − t).

· is introduced and stands for the scalar product in RN if u = (u1 . T )dz2 (t) F (t. Further. . . ¯ 2. • further. that is for i = 1. • ε is the unknown vector of standard normally distributed random shocks. 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. . uN ) then N (2.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.5 Two-factor regime switching forward price curve model Building on the general framework for commodity forward price curves introduced in Section 2. dF (t. That is. . [4]). the model belongs to the class of Markov Switching models (Chiarella et al. σi2 . αi = (αi1 . αiN ). 20 . 2. As indicated in Section 1.12) u. . T ) = σ1 (t. T )dz1 (t) + σ2 (t.˜ • Σ is the matrix of discrete volatility function terms. .1. • both volatility functions. . the following two-factor regime switching model for the natural gas forward curve is proposed (see Chiarella et al. Markov Switching of the coeﬃcients is imposed. have diﬀerent volatility and attenuation parameters depending on the state of the Markov Chain Xt . . Therefore. T ) where • the natural gas forward price at time t with maturity T is denoted by F (t. . σiN ). [4]). . σi = (σi1 . . T ). In between two random jump times an almost deterministic process is followed by the volatility. αi2 . the notation ·. .

13) where • switching between parameter values is governed by a ﬁnite state Markov Chain Xt . . • z1 (t) and z2 (t) are independent Brownian motions. . . . The parameters c. that is ei = (0.Xt J (T −t) (1 − σl1 ) + σl1 ) (T −t) σ2 (t. 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. . .σ1 (t. N . for all i = 1. T ) = σ1 . . 0. . Xt c(t) (σl2 − e− α2 . For the application below. • the transition probability matrix of the Markov Chain Xt is deﬁned by ξ = (ξij )N xN . parameters σl1 and σl2 are deﬁned to describe long run volatility. . 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. N. . . . with a periodicity of one year. 0)T ∈ RN . . . .Xt c(t) = c + j=1 ) (dj (1 + sin(fj + 2πjt))) (2. . . the Fourier series will consist of only one series. . with the state space deﬁned by X = {e1 . 21 . 1. j = 1. with ei a vector of length N that has a value of 1 at the i-th position and 0 elsewhere. Xt c(t) (e− α1 . that is J = 1. . d1 and f1 are then estimated. eN }. e2 . . T ) = σ2 . 0. • since the long term volatility behaves diﬀerently from short term behavior.

the state transitions are driven by a ﬁnite state Markov Chain. where t is the present time. ξ. . In particular. for the diﬀerent maturities the forward prices F (k∆t. Further. For the econometric estimation of the states for drift and volatility. . and the transition probability matrix of the underlying Markov Chain. take diﬀerent values for diﬀerent states of the world. T ). c. Then in discrete-time the forward dynamics of (2. fj .12) can be rewritten as 22 . M ∆t = t. . θ. . M are observed. . . σli (i = 1. . dj . (j = 1. . X.13). . 3. a Markov Chain Monte Carlo (MCMC) method is suggested and implemented.1) The elements of the transition probability matrix ξ are also unknown and have to be inferred from the historical data as well. a discrete-time Gibbs sampler is developed to estimate θ and ξ given the forward prices at ﬁxed observation times ∆t. 2). 2∆t. It is thus assumed that the state process can jump only at the discrete observation times (Chiarella et al. αi .12) and (2. . The model is a Markov Switching model: the parameters. k = 1. found in the respective volatility functions σ1 (t.Chapter 3 Estimation In this chapter a Bayesian approach is presented to estimate the parameters of the forward curve model described by (2. The set of parameters is deﬁned as θ: θ = {σi . . T ) and σ2 (t. T ). . J)} (3.1 Data transformation So. [4]). 2.

T ) ∆t + i=1 i=1 2 σi (t.yt.T is abbreviated to yT . u The posterior distribution π(X. π(Xt . the latent Markov Chain X is introduced as missing data and samples for θ and X are generated given yT for parameter estimation. T ) − log F (t. and the sampler applied here is a Gibbs sampler (Fr¨hwirth-Schnatter [14]).T = log F (t∆t.2) One can see that diﬀerence of the log of forward price. The technique of constructing sampling algorithms via the introduction of latent variables is called data augmentation. i=1 (3. the conditional distribution π(X|θ) indicates that realizations of X are dependent on the parameter values θ. T )∆zi (t). 3.5) Before drawing from this augmented complete-data likelihood distribution the prior distributions have to be chosen (Chiarella et al. θ|yT ) ∝ π(yT |X.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. θ) which expresses the forward dynamics yT given the states of the Markov Chain X and parameter values θ. (3. yt.T is normally distributed with mean 1 µ(t. T )2 ∆t.3) σi (t. θ|yT ) is proportional to the complete-data likelihood distribution π(yT |X. Further. θ|yT ). pr(θ). T ) = − 2 and standard deviation 2 2 σi (t. π(X. 23 . The sampling distribution is the posterior distribution. T )2 ∆t i=1 (3. and initial knowledge about the model parameters is expressed by deﬁning a prior distribution for θ. θ)π(X|θ)pr(θ) (3. [4]). T ) 1 =− 2 2 2 σi (t.

Then cp can be interpreted as the number of observations of jumps out of state l in the prior distribution. the priors can be written as follows 2 J π(θ. [4]). we may 0 set gl. . ξ and X0 are independent. cp . bα ) where aσ and aα are discrete values which deﬁne the paramil il il il eters of the uniform distribution. Where the following distributions are assumed for the priors: • The priors of volatility and attenuation parameters are σil ∼ U (aσ . • The priors of the long run volatility parameters. aσ . . d. and il il αil ∼ U (aα .1). equals the prior expectation of xil. glN .3. ac . 1) • The rows ξl of the transition probability matrix ξ. bc in the prior distributions are deil il il il ﬁned before running the Gibbs sampler (Chiarella et al. 24 . aα . glN ) where the vector gl. As a result. .3 Prior distributions Prior distributions are chosen for θ and X0 . . . X0 ∼ U ({1. ξ. times a constant that determines the variance. σli ∼ U (0. bσ ). . If the number of states. are uniformly distributed as well. If ξ0 denotes our prior expectation of ξ. X0 ) = pr(ξ) i=1 (pr(σi ) · pr(αi ) · pr(σli ))pr(c) j=1 (pr(dj )pr(fj ))pr(X0 ). are assumed to be independent and to follow a Dirichlet distribution ξl ∼ D(gl1 . . c. bc ) • The prior of the initial state of the Markov Chain is following a discrete uniform distribution. d. N. All parameters gl1 . f ∼ U (ac . = ξl. • The priors for the parameters of the seasonal part. . are uniformly distributed c. . is restricted to 2. . Under the assumption that the set of parameters θ given by (3. . bσ . σli . the volatility and attenuation parameters are bounded which eases convergence. the Dirichlet distribution simpliﬁes to a Beta distribution. the state of the Markov Chain at t = 0. f . N }) where N is equal to the number of states deﬁned for the Markov Chain. bα . .

3.T ) 25 (3. σ) with the with mean µk∆t. .4. X0 . given by the moments of ( 3. described by φ(yT . the unknowns are partitioned into three blocks θ. yT ) using Algorithm 3. . State simulation conditional on knowing θ(k) by sampling a path X of the hidden Markov Chain from the conditional posterior π(X|θ(k) . . and the rate of convergence. . Clearly. [4]). K + K0 . K0 . X) = k=1 φ(yk∆t. σk∆t. µk∆t. X|yT ) given the observed data yT where each part is drawn from the proper conditional density (Chiarella et al. . .T and standard deviation σk∆t. (b) Sample the model parameters θ(k) from the complete-data posterior π(θ|yT . These samples are thrown away for the calculation of the estimators. [4]). ξ. ξ. 1. The notation K0 represents the number of iterations for the burn-in. X (k−1) ). . M π(yT |θ. .6) .T . Parameter simulation conditional on the states X (k−1) (a) Sample the transition matrix ξ (k) from the complete-data posterior distribution π(·|X (k−1) ).5 ) (Chiarella et al.4 Gibbs sampler Starting from the prior distributions speciﬁed in Section 3. The complete-data likelihood function is a product of normal densities. the length of burn-in depends on the initial state of the Markov Chain state. The particular scheme is explained in Algorithm 1 below. θ is sampled and X is sampled conditional on knowing θ (Fr¨hwirth-Schnatter [14]). µ. 2.1 Full conditional posterior distributions Next. 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. a three-step MCMC sampler is used to sample from the augmented posterior distribution π(θ.T .T .2. ξ and X. which will be discussed below.3. Store the actual values of all parameters θ(k) and ξ (k) . the full conditional posteriors required for the three sampling steps are derived. Next. Conditional on knowing the state of the ﬁnite Markov Chain X.

from the complete-data posterior distribution π(ξ|X (k−1) ). that is Nlq = M I(Xk−1 =l.4. In the next sections the several steps involved will be explained in more detail.Xk =q) (Chiarella et al.9) where the notation Nlq stands for the number of transitions from state l to q. complete-data estimation is carried out for a given path X. . l = 1. X)pr(θ) Finally. . .4 to infer the parameters of the volatility functions. each row is an unknown probability distribution that has to be estimated from the data.Further the full conditional of θ. . is π(X|yT . k=1 3. X)π(X|ξ) (3. 2. ξ.7) where the prior distribution π(X|ξ) is not dependent on θ but rather speciﬁed by the distribution of X0 and the transition matrix ξ. First.2 Sample the transition matrix The MCMC routine Algorithm 1 was introduced in Section 3. [4]).8 ) is provided by M N π(X|ξ) = π(X0 |ξ) k=1 π(Xk |Xk−1 . assumptions regarding the distribution π0 of the initial value X0 have to be made.q=1 ξlq lq N (3. M . X) ∝ π(yT |θ. ξ) ∝ π(yT |θ.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]).8) (3. The conditional probability π(X|ξ) in ( 3. ξ) = π(X0 |ξ) l. u In order to determine the particular algorithm. The complete-data likelihood π(X|ξ) is given by. u Given the transition matrix ξ (k) of the hidden Markov Chain. θ. the transition matrix ξ (k) is sampled (Fr¨hwirth-Schnatter [14]). Therefore. the full conditional posterior of the state process Xl∆t . In this essay the initial 26 . the conditional joint distribution of the parameters associated with drift and volatility is given by π(θ|yT . 2 2 π(X|ξ) = j=1 k=1 ξjk NKjk (X) (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. independent a posteriori. . The candidate θ∗ is generated by a so-called candidate generating density q(θ. ejK (X) + NjK (X))j = 1. u ξj· ∼ D(ej1 + Nj1 (X). instead of updating the elements of θ all at once.distribution π0 is assumed to be independent of ξ. . The rows ξj· of ξ. Since only two distinct states are deﬁned for the transition matrix ξ. . Now a classical Bayesian inference problem. are each following a Beta distribution. . e12 + N12 (X))ξ22 ∼ B(e21 + N21 (X).11) where Njk (X) = #{Xt−1 = j.4. N (3. . it is more straightforward and computationally eﬃcient to split θ into its components {θ1 . θ∗ ). and update one by one. Further. with d the number of parameters. Gibbs sampling from the conditional posterior π(ξ|X) can be applied. .3 Sample the model parameters A single-component Metropolis-Hastings algorithm is set up in order to update the parameter set θ. that is N = 2. . . both independent. Here. θ∗ = θ + rθ ψ (3. 27 . . θ2 . . that is sequentially. Xt = k} counts the numbers of transitions from j to k for the actual draw of X. 3. θd }. .12) These densities generalize to the Dirichlet distribution for the case N > 2 (Fr¨hwirthu Schnatter [14]). e22 + N22 (X)) (3. are drawn from the following Dirichlet distribution (Fr¨hwirth-Schnatter [14]). . a normal random walk is used to draw θ∗ . the persistence probabilities ξ11 and ξ22 . ξ11 ∼ B(e11 + N11 (X).

2.Algorithm 2: single-component Metropolis-Hastings 1. So. Therefore. θ2 . . .14). . θ−i ) by the symmetry of the normal distribution. Initialize vector θ0 at some values for its components. . look at parameter values found in previous research. θ−i ) (k) (k) (k) (k) (k) ∗ α(θ−i . . This special case of the Metropolis-Hastings algorithm is often referred to as the random-walk Metropolis-Hastings (Fr¨hwirth-Schnatter [14]). θ−i ) ∗ qi (θi |θi . otherwise θi = θi . ∗ ∗ Notice that qi (θi |θi . θ−i ) (k) (k) (k) (k) drops out of the Metropolis probability calculation (3. (3. θi . 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 θ. For step i of iteration k + 1. . u 28 . At this step θ−i is left untouched. θi . θi is updated. . Diﬀerent starting values could be chosen. for example. θi . the candidate is accepted with probability α(θ−i . the random number is greater than the acceptance probability. Otherwise. 2.14) where the full conditional distribution for θi under π(·) is denoted by π(θi |θ−i ). θi−1 . θi = θi . θi+1 . This greatly simpliﬁes the calculation of α. One could. So. Let θi denote the value of θi at end of iteration k. θ−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 . ∗ If this random number is less than α(θ−i . θ−i ) ∗ π(θi |θ−i )qi (θi |θi . Next. θi ) = min 1. i − 1 have already been updated. θ−i ) = qi (θi |θi . θi ) where ∗ ∗ π(θi |θ−i )qi (θi |θi . Generate a random number ∼ U (0. 1). . . thus the proposed move for component i of parameter set θ is rejected. the factor ∗ qi (θi |θi . 4. (m+1) (m+1) (m) (m) ∗ ∗ if θi is accepted. θi ) then the move is accepted. The candidate is generated from proposal distribution qi (θi |θi . . θh } where components 1. . ∗ 3. .

4. θ) is written as follows T −1 π(X|y. θ). to help assess convergence (Fr¨hwirth-Schnatter [14]). So. θ) = t=0 π(Xt |Xt+1 . . As a consequence. Further. it is a good idea to experiment with diﬀerent values for step size. . 3. yT ) is simpliﬁed to ξXt . Hence. This would lead to a high rejection rate. Whereas. ξ (k) ). a path X of the hidden Markov Chain from the conditional posterior π(X|(θ(k) . as described by Algorithm 1.16) t where π(XT |yT . θ. it is wise to run multiple chains from disperse starting values. But random permutations of the updating order are acceptable as well. t π(Xt |Xt+1 . yT ) π(XT |yT . candidate draws θi will be very far away from the current draw. θ) (3. the assumption is taken that the Markov Chain Xt is homogeneous. ·). u Finally.Xt+1 . XT ). If that step size is too high. the updating order for the elements of θ in above Algorithm 2 is assumed to be ﬁxed.Xt+1 π(XT |yT . . t π(Xt+1 |Xt . . yT ) is sampled conditional on (θ(k) . Here. the standard deviation of the normal random variable is the step ∗ size rθ . First.4 Markov Chain state simulation In a ﬁnal step of the Gibbs sampler. . In this section this sampling method for the hidden Markov Chain X = (X0 . θ. then candidate draws will be very close to the current draw. 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 . And. XT . is worked out in great detail. . the algorithm accepts frequently. .15) where the ﬁltered probability distribution at t = T is denoted by π(XT |yT . θ) is the ﬁltered probability distribution at time t. ξ (k) ). in general.When the random-walk Metropolis algorithm is used as candidate generating density q(·. . θ). yT ) ∝ ξXt . . . when rθ is chosen to be too low. . 29 . but the chain will move slowly around the parameter space. θ. and in a region of the parameter space that has low probability. the joint posterior π(X|yT . XT . θ) (3. and a Markov Chain that doesn’t move very often. .

θ) t (3. yT . . run the ﬁlter described in Algorithm 3. . θ)π(Xt = k|yT . the following steps are executed sequentially. .17) t−1 for l = 1. T is then stored. (b) Filtering for Xt : t−1 t−1 π(yt |Xt = l. k=1 30 . The resulting ﬁltered state probability distribution π(Xt = j|y t . 2} of Xt . θ) for all possible realizations l ∈ {1. yT .18) where 2 t−1 t π(yT |yT . 0 So. Algorithm 3.1: Filtering the States For t = 1. . (a) One-step ahead prediction of Xt : 2 π(Xt = l|y t−1 . . θ) = k=1 t−1 t−1 t π(yT |Xt = k. θ)π(Xt = l|yT . θ) (3. 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 t of the support of the state variable Xt . 2 for t = 1. θ) π(Xt = l|y . the ﬁlter is started with the initial distribution π(X0 = k|ξ).19) At t = 1. θ) = k=1 t−1 ξkl π(Xt−1 = k|yT .1.Given the above-mentioned distributions it is now possible to implement a forward-ﬁltering-backward-sampling algorithm. execute the following steps to sample a path X k of the hidden Markov Chain. θ) simpliﬁes to the transition probability ξkl for homogeneous Markov Chains. yT . 2. 2 where π(Xt = l|Xt−1 = k. conditional on θ. θ) j = 1. Obtain Filtered state probabilities First. θ) = 2 ξkl π(X0 = k|ξ). Algorithm 3: Multi-Move Sampling of the States Given ﬁxed values for parameter set θ. π(Xt = l|yT . . For a state space model. π(X1 = l|yT . T . . θ) = t−1 π(yt |yT . . θ) (3. 1.

all information the observations t−1 y1 . θ) t where lm is equal to the state of St+1 and π(Xt+1 = lm |Xt = j. . . θ) given by (k) from the conditional distribution t π(Xt = j|Xt+1 . . m t For each t. θ) K k=1 ξk.lm since the Markov Chain Xt is homogeneous. θ). .lm π(Xt t = k|yT .As is typical for any ﬁlter. θ). . θ. Sample XT t j|yT . . 31 . . θ) summarize. . θ) (k) from the ﬁltered state probability distribution π(Xt = (k) 3. yT contain about Xt−1 . . 0 sample St (k) π(Xt = j|Xt+1 . θ) at time t − 1 and only the actual t value of yT are suﬃcient. To obtain inference about Xt at time t t in terms of the posterior distribution π(Xt = l|yT . knowledge of the t−1 posterior distribution π(Xt−1 = l|yT . y t . which were stored in step 1 of Algorithm 3. yT . yT .lm π(Xt = j|yT . π(Xt |Xt+1 . . for a ﬁxed value of θ. . . 2. yT ) reduces to ξj. the discrete ﬁlter described in Algorithm 3 is an adaptive inference tool. This t requires knowledge of the ﬁltered state probabilities π(Xt = j|yT . For t = T −1. the ﬁltered probabilities π(Xt−1 = t−1 l|yT . At time t − 1. θ) = t ξj. θ) needs to be evaluated for all j = 1. K.. T −2.

There is some degree of freedom in the choice of prior distribution but the prior distribution should be 32 . 4. estimators are given for both a one-factor model and the two-factor model described in Section 2. forward quarter. the algorithms are tested with simulated data. Natural gas at NBP trades on a forward month. which is the British virtual trading location operated by TSO National Grid. Further. in order to obtain the forward dynamics yT for every maturity T . It is the most liquid gas trading point in Europe. 4. daily observations for the forward prices were obtained with maturities ranging from July 2009 to September 2012. T ).5. the log diﬀerence transform is applied to the original data F (t. the details of the implementation are laid out and the numerical results for the routines are provided. T ). forward season or year forward basis and prices are expressed in pence (GBp) per therm. and X0 . The observations span over a year with prices at times t from 23/10/2007 to 12/03/2009. Further.2 Choosing the prior The complete-data likelihood and the full conditionals introduced in Chapter 3 contain prior knowledge about the parameter set θ. Before applying the chosen methodology to historical gas forward prices. covering all entry and exit points in mainland Britain.1 Data The natural gas prices modeled are forward prices for the National Balancing Point (NBP). For parameter estimation of the chosen model. This data is represented by F (t.Chapter 4 Implementation In this chapter.

1) • The prior of the initial state of the Markov chain is X0 ∼ U ({1. σk∆t. [4]). all observations along the forward price curve at each time t are taken into account.independent of the data and the posterior distribution. . . . µ and σ deﬁned as in Section 3. and αil ∼ U (0.Tλk ) (4. .36 0. . the matrix of parameters for the Dirichlet distribution is set to 0. [4]): • For the transition matrix ξ the vector gl. Finally. 2}) 4.84 g= (4. l = 1. If ξ0 denotes the prior 0 expectation of ξ. . 1. times a constant that determines the variance. = ξl. the scaling factors rθ have to be chosen.3 Running the Gibbs sampler A randomized algorithm is used to calculate the complete-date likelihood function. to implement the Metropolis-Hastings algorithm. .T corresponding to the maturity Tj is picked if λk = j. Before estimation a string λ is selected. . 2) • The priors of c.2) where φ. k = 1. 33 . . Then cp can be interpreted as the number of observations of jumps out of state l in the prior distribution. f1 ∼ U (0. f (J = 1) are c. 5) • The priors of σli are σli ∼ U (0. X) = k=1 φ(yk∆t. (i = 1. 12}). The complete-data likelihood function thus becomes N π(yTλ |θ.64 0. . At each time k · ∆t in the data series. the data yt. λ2 . 1).5). cp . (i. . one may set gl.1 (Chiarella et al. N where λk ranges from 1 to 12 to label 12 diﬀerent maturities. d1 . Hence.Tλk . λ = (λ1 . 2) are σil ∼ U (0. 2. Fixing rθ around 2% to 5% seemed to work well (Chiarella et al. The following priors are used in the implementation (Chiarella et al. λN ) with λk ∼ U ({1. ξ. This way. d. . µk∆t. equals the prior expectation of xil.Tλk .16 0.1) • The priors of σs and αs. [4]).

5. the second volatility function. d = 0. T ) are deﬁned as in Section 2.3. dF (t. f = 0.2). The transition probabilities ξ were equal to ξ= and.1 0.75. σ12 = 1. σl1 = 0.5.08.4. the parameter set θ θ = {σ1 1 = 0.12) such that one is left with a one-factor model.8.7 0.3 34 . T ) (4. the implementation of the Gibbs sampler is veriﬁed by means of simulated forward data.31} Figure 4.9 0. T ) = σ1 (t.) generates forward price dynamics. yT following formula (3. After which the model parameters are inferred with the Gibbs sampler. T )dz1 (t) F (t. α11 = 2.1: Generated forward price dynamics. Figure 4.3) Next. σ2 (t. α12 = 1.6. T ) is omitted in (2.1 One-factor model First. c = 0.1 below shows the forward price dynamics yT of a one-factor regime switching model. The code in Appendix A (p. Then the parameters for the ﬁrst volatility function σ1 (t. yT 0.

which is found in Appendix C (p.12). Below one can ﬁnd the routine for the Gibbs sampler which is applied to the generated forward price dynamics.3. For this very ﬁrst stage of the implementation. In Appendix B (p. parameter estimation is carried out with the Gibbs sampler. yT . The respective parameters c.m. 4.08 and 0. d and f are ﬁxed at their true values 0.Next.) Also in the case of the two-factor model. the parameters for the seasonality function c(t) are not estimated. c(t) are initially ﬁxed. the parameters of the seasonality function.31.) 35 .) one can ﬁnd the routine for the Gibbs sampler which is applied to the generated forward price dynamics. The code for this discrete-time sampler is provided in Appendix D (p.8. The dynamics yT are generated calling the routine nbp 2fac.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. 0. yT .

31.81.1 0. d = 0. which are seasonality parameters obtained from previous estimations by Chiarella et al. about 100.1 One-factor model For a two-state regime. 2) Simulated data Actual Estimated 1 2 1 0.28 • Regime-switching parameters σ1j and α1j . one-factor model. d and f are not included in the parameter set θ. (j = 1. • Number of states = 2 • Transition probability matrix ξ Simulated data Actual Estimated 1 2 1 0. Parameters are respectively c = 0.3 0.01 1.88 0.5 1 0.75 2. That is. f = 0.4 Numerical Results 4.000 steps were run with simulated data. the values for the seasonality function c(t) are kept ﬁxed. 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.4. [4].78 36 . At this stage of the implementation.4.12 0.06 j σ1j α1j 2 1. Below one can ﬁnd the estimates of the transition probability matrix ξ and the parameter set θ.72 1 2 2 0.47 2 1.08. the parameters c.9 0.7 0.

62. 2). (j = 1. (j = 1.6 37 . with an actual value of 0. 2) • estimator for σl1 . Convergence is reached fast for the volatility parameters σ1j . σl1 = 0.2: Path of parameter estimates for σ1j and α1j .2 below shows the parameter estimates throughout the runs.Figure 4. but also the values for the attenuation parameters α1j reach the actual values of the underlying forward dynamics yT . Figure 4.

3: Generated forward price dynamics. σl1 = 0. The transition probabilities ξ were equal to ξ= and.000 steps were run with simulated data.8.2 0.2. the parameter set θ θ= {σ11 = 0.3.5. f = 0.08. Here the following parameter values were used to generate yT . σ22 = 1. α11 = 1.4. α21 = 1.8 0.3 below shows the forward price dynamics yT of a two-factor regime switching model. σ12 = 0.8. about 100. two-factor model. Figure 4. Any parameters that lie within the boundaries set by the prior distributions could be chosen for the simulated forward dynamics. σl2 = 0. d = 0.5.4.6.6 0.9.31} Figure 4. c = 0.2 Two-factor model For a two-state regime. yT 0.4 38 . α12 = 2. α22 = 3. σ21 = 0.

17 0.31 Those seasonality parameters were obtained from previous estimations by Chiarella et al. 2) Simulated data Actual Estimated 1 2 1 0.6 0.3 0. f = 0.59 39 .2 0. [4].67 1 3 1.01 j σ1j σ2j α1j α2j 2 0. the Gibbs sampler implemented for the two-factor regime should be able to retrieve those values.37 0.5 2 1. • Number of states = 2 • Transition probability matrix ξ Simulated data Actual Estimated 1 2 1 0.69 3.31 2.8 0.08. With ﬁxed seasonality function c(t) Parameters are respectively c = 0.63 1 2 2 0.4 0.6 1. d = 0.2 0. 1. As previously stated.Next.37 • Regime-switching parameters σ1j and α1j .67 1.8 0. 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. (j = 1.81.78 1. Below one can ﬁnd the estimates of the transition probability matrix ξ and the parameter set θ.83 0.

2). (i. Figure 4. j = 1. j = 1. (i. One could increase the number of runs. Convergence is reached fast for the volatility parameters σij .Figures 4.4: Path of parameter estimates for σij . 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. 2) 40 .4 and 4.

2) • estimator for σl1 . j = 1. 2.5: Path of parameter estimates for αij . the seasonality parameters c.9 The same exercise is repeated. σl1 = 0.Figure 4. With varying seasonality function c(t) Now.83.000.6 estimator for σl2 . σl2 = 0. The number of runs is increased to 200.66. with an actual value of 0. d and f are included in the parameter set θ • Number of states = 2 41 . but now the parameters for the seasonality function c(t) are inferred as well from the simulated forward data. (i. with an actual value of 0.

2 0.2 0.8 0. 2) Simulated data Actual Estimated 1 2 1 0.62 1 2 2 0.73 1.38 • Regime-switching parameters σ1j and α1j .8 0. (j = 1.61 3.94 j σ1j σ2j α1j α2j 2 0.21 0.83 1 3 0.5 2 1.26 0.79 0.19 1.6 0.• Transition probability matrix ξ Simulated data Actual Estimated 1 2 1 0.30 42 .3 0.4 0.6 1.53 1.

Figure 4.6: Path of parameter estimates for σij . j = 1. (i. One could increase the number of runs. j = 1.5 below show the parameter estimates throughout the runs. 2). The values for the attenuation parameters αij are near the actual values of the underlying forward dynamics yT . (i. Convergence is reached fast for the volatility parameters σij . 2) 43 .4 and 4.Figures 4.

7: Path of parameter estimates for αij . (i.9 • estimators for seasonality function are respectively. σl1 = 0.04 and f = 0. d = 0.92.31 44 .Figure 4. 2) • estimator for σl1 .8. d = 0.53. with an actual value of 0.93. σl2 = 0. c = 0. j = 1.35 with actual values of c = 0. with an actual value of 0.6 estimator for σl2 .08 and f = 0.

7833 45 .4327 0. (j = 1.5020 1. In Appendix E (p. 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. 2) Historical data Estimated 1 2 0.8185 0.0885 1. is 0.1.0948 1.9067 j σ1j σ2j α1j α2j • estimator for σl1 is 0.4.185 0.000 steps were run and the following are the estimates of the parameters.2080 2. a jump from regime 1 to regime 2 is witnessed. Sporadically. with rather similar results.) one can ﬁnd the routine for the Gibbs sampler which is applied to the sample.6207 0. Finally.4115 2. The burnin rate is 20%.3777 0. About 200.4. the Gibbs sampler for the two-factor regime switching model is applied to historical forward NBP data. • Number of states = 2 • Transition probability matrix ξ Historical data Estimated 1 2 0.5673 1 2 • Regime-switching parameters σ1j and α1j .3654 estimator for σl2 . A number of MCMC estimation procedures were run with diﬀerent initial values for the respective parameters. The data sample was introduced in Section 4.3 Historical NBP forward data Now all pieces have been put together and tested.

0464 1. One could see that less time is spent in regime 2 here.8429 0. d = 0.8932 1.1533 3.0781 and f = 0. c = 0.3057 0.1484 0.4762 1. 2) Historical data Estimated 1 2 0.6203 • estimators for seasonality function are respectively. (j = 1.3070 46 . c = 0. • Number of states = 2 • Transition probability matrix ξ Historical data Estimated 1 2 0.8516 0.2536 j σ1j σ2j α1j α2j • estimator for σl1 is 0.6922. d = 0.3362 and f = 0. [4] for NBP forward price data that spanned from 29/09/2006 to 19/02/2008. It could be argued that volatility levels for natural gas have exceeded normal levels in 2008 as a result of the global ﬁnancial crisis.2791 These estimates can be compared to the estimates provided by Chiarella et al.4869 estimator for σl2 . is 0.• estimators for seasonality function are respectively.7080 0.2920 1 2 • Regime-switching parameters σ1j and α1j .0292 2. which indicates that the environment is less volatile.8121.

Finally. The highly volatile remainder of 2008 and also the beginning of 2009 was thus not included. [4] presented data from 29/09/2006 to 19/02/2008. it would be recommended to implement an on line approach. When new data becomes available. [4] the Gibbs sampler presented is an oﬀ line approach. The respective changes in regime aﬀect the whole forward curve structure. as mentioned by Chiarella et al. 47 . introduced ﬁrst by Fr¨hwirth-Schnatter (Fr¨hwirth-Schnatter [14]) and Hahn et u u al. Episodes of higher volatility are followed by episodes of lower volatility driven by market structure changes or supply-demand imbalances. [4].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. 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. For parameter estimation a Markov Chain Monte Carlo (MCMC) technique was applied. the routine is slow to update the estimates. The parameter estimates for the NBP sample were found considerably higher than the estimators found by Chiarella et al. [4] was presented. like a particle ﬁlter. which included 12 forward curve series. Therefore. The data in this essay spans from 23/10/2007 to 12/03/2009. such that the volatility functions can be updated quickly from high-frequency data. [18]. whereas Chiarella et al. The use of MCMC techniques makes the calibration of more complex volatility functions possible.

1). th0=[. t=flipud(tT). \alpha_12 % long-term volatility parameter % \sigma_l_1 % seasonality parameters % seasonality function c=.3].5].5 1 1. ct=c+d*(1+sin(f+2*pi.Appendix A nbp 1fac.31. x0(1)=unidrnd(2). % sample state vector x0 % len=size(tT. % daily time-stepping % time-to-maturity % time % transition probability matrix % initial values for both states 1. for it=2:len. nbp 1fac. x0=ones(len.2 % volatility parameters: % \sigma_11.1 .1).8. d=. % state 1 48 .9 .m one-factor volatility model.*t)). f=. \sigma_12 % attenuation parameters: % \alpha_11.5 1 .m Generates forward dynamics of a one-factor regime switching model % parameters % dt=1/365. tT=(3:-dt:0)’. p0=[.7 .08.

*th0(ones(1.1)*sqrt(dt). sig=sum(x0. % volatility function % x0=[x0==1 x0==2].*sig)+sig.1:2).len).2).. sig=ct. % plot % figure. plot(y) title(’forward data sample.*tT)*(1-th0(5))+th0(5)).if rand>p0(1.*. % simulate path of forward returns % y=-0.2).*th0(ones(1.5*dt*(sig..3:4).T)’) 49 .2*x0(it-1)-1) x0(it)=2.*randn(len. end end x=x0.len).*sig. one-factor model’) xlabel(’time t’). (exp(-sum(x0. ylabel(’y(t.

% generate simulated data % nbp_1fac.16 .4).m Gibbs sampler.Appendix B mcmc.5).36 . % allocate % call nbp_1fac. clear all % initialize % iter=1e4. rth=0.5]. burnin=iter/5. th=zeros(iter.5). g=p(1.m Parameter estimation of Markov switching model with MCMC clc.5 1 1. rg=[zeros(1.:)=[. .5 1.5 1 .5 5 5 1 ].1.:)=[. mcmc.64 . p=zeros(iter.05. % priors % p(1.84].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.:)*15.

1)+n11 g(1. for it=2:len.2*x(it-1)-1) x(it)=2.2). sf=zeros(len. end end % algorithm % th1=th(1.1). if rand>p(1.[g(1.% sample initial state vector x % x=ones(len. st=[x==1 x==2]. % sample from Beta distribution p1=betarnd([g(1. n11=sum((x(1:end-1)==1)+(x(2:end)==1)==2). p1=[p1(1) 1-p1(1) p1(2) 1-p1(2)].2).2).2)+n12 g(1. for k=2:iter sp=zeros(len. n22=sum((x(1:end-1)==2)+(x(2:end)==2)==2).3)+n21]. x(1)=unidrnd(2). sc=zeros(len. % state 1 % allocate % sample transition probability matrix p % n12=sum(diff(x)==1). % count transitions between states n21=sum(diff(x)==-1). % random parameter choice % generate th1(idx)=th(k-1. p(k.4)+n22]).idx) + rth*randn. % complete-data likelihood 51 . % update % Metropolis-Hastings algorithm % idx=unidrnd(5).:).:)=p1.

5*(p1(1:2)+p1(3:end)).tT.*sp(it-1.rg(2..:)=sf(it.2)).:)=th1.st.len)).*sf(it.th1. end % state 1 for it=len-1:-1:1 sc(it.:).:)=p1([x(it+1) x(it+1)+2]).:)=0. th(k.t.:)=sf(it.dt.m llh=sum(log(mclh(y. if rand<=alpha. sf(1.:).2)*p1(3:end).. sf(2:end. sp(it. else th(k. end % backward sampling % x=ones(len.:)=sp(1. th(k.[zeros(len-1.dt.rg(1.:). for it=2:len sf(it.len-1).th(k.tT(2:end).1)]. -log(mclh(y. sf(it...len-1).1) ones(len-1.2)=mclh(y(2:end).1)+sf(it.:). sf(2:end..1)+sc(it.[ones(len-1.dt.llh*pr(1)/pr(2)).idx).% call mclh.:).tT(2:end).idx)].:)=sc(it.st.tT.:)=th(k-1.:).dt.t(2:end).t.:)/(sf(it.1)*p1(1:2)+sf(it.:)=sf(it..2)).:). end % filtering.1)=mclh(y(2:end). 52 .:)/(sc(it.len))). sc(it. if rand>sf(end..:).1) x(len)=2.th(k-1.1).1) zeros(len-1. FFBS algorithm % % forward filtering % sp(1.t(2:end). % prior densities pr=unifpdf([th1(idx) th(k-1.1)].. % acceptance probability alpha=min(1.idx)).

sig(:.2). end % update % output % mu_th=mean(th(burnin+1:end. lh=exp(-0.x.*tT)*(1-th(5))).m is called to evaluate the complete-data likelihood for various values of the parameters./mu).2).1)=sum(x.*t)). 53 . end end th1=th(k. function [lh.1) x(it)=2.1)).if rand>sc(it./sqrt(mu).ones(2. the function mclh. mu=dt*sum(sig.:).1:2).2). This function is given below. ct=.tT.:)) In the routine for the Gibbs sampler.*th(ones(1.sig]=mclh(y.*(th(5)+ exp(-sum(x.5*mu).*sig.31+2*pi.*sig. lh=lh.8+. mclh.th.5*((y+0.*th(ones(1.T). sig=ct(:.:)) mu_p=mean(p(burnin+1:end.T).2).t.^2).m Returns components of complete-data likelihood function sig=zeros(T.dt.08*(1+sin(.3:4).T).

. th0=[..m two-factor volatility model.15].3 2 3 .m Generates forward dynamics of a two-factor regime switching model % parameters % dt=1/365.75 .25 . t=flipud(tT). . \alpha_22 long-term volatility parameter \sigma_l_2 54 . \alpha_12 % long-term volatility parameter % \sigma_l_1 % % % % % % volatility parameters: \sigma_21. tT=(3:-dt:0)’. % daily % time-to-maturity % time % transition probability matrix % initial values for 2 factors & % both states 1.8].5 1 .2 % volatility parameters: % \sigma_11. \sigma_22 attenuation parameters: \alpha_21.85 .5 1 1. \sigma_12 % attenuation parameters: % \alpha_11.75 1.Appendix C nbp 2fac.6 . nbp 2fac. p0=[.

2). sig=ct(:.3:4).2)=sum(x0.*sig. ylabel(’y(t.*tT)*(1-th0(5))+th0(5)).T)’) 55 . sig(:. sig(:.6:7).1)=sum(x0.1).*th0(ones(1. (th0(10)-exp(-sum(x0.08. % simulate path of forward returns % y=-0.2). if rand>p0(1..2)+sum(sig.*th0(ones(1.31. d=.2)*sqrt(dt).. % seasonality parameters % seasonality function % sample state vector x0 % len=size(tT.1:2). plot(y) title(’forward data sample..2).*.8:9). % plot % figure..*randn(len.ones(2. for it=2:len.*th0(ones(1.1). % state 1 x0(1)=unidrnd(2).*t)). (exp(-sum(x0.2*x0(it-1)-1) x0(it)=2.len). end end x=x0.len).*th0(ones(1.c=. x0=ones(len.len).2).5*dt*sum(sig.*.8.1)).*sig.*tT)). % volatility function % x0=[x0==1 x0==2].2). ct=c+d*(1+sin(f+2*pi. two-factor model’) xlabel(’time t’).len). f=.

% initial parameter values rg=[zeros(1.5 1. burnin=iter/5.m for data % guess transition probabilities % prior expectation of % probability matrix th(1.64 .:)*15. 1. g=p(1.84]. . % generate simulated data % nbp_2fac..m Parameter estimation of Markov switching model with MCMC clc.10).5 .10).25 .:)=[.m Gibbs sampler. clear all % initialize % iter=1e5.5 5 5 1]. p=zeros(iter.5 5 5 1 .16 .. % bounds for parameter values 56 .36 .Appendix D mcmc.75 2 2 . th=zeros(iter..5 1. % allocate % call nbp_2fac. % priors % p(1. mcmc.5 1 2 2 1]..4).1.:)=[.

4)+n22]). % update % Metropolis-Hastings algorithm % idx=unidrnd(10). for k=2:iter sp=zeros(len. sf=zeros(len. end end % algorithm % th1=th(1. for it=2:len. sc=zeros(len. st=[x==1 x==2]. % random parameter choice % generate th1(idx)=th(k-1.2). n22=sum((x(1:end-1)==2)+(x(2:end)==2)==2).3)+n21]. x(1)=unidrnd(2).[g(1.2)+n12 g(1. p1=[p1(1) 1-p1(1) p1(2) 1-p1(2)].2).025. if rand>p(1.rth=0.2*x(it-1)-1) x(it)=2. % sample initial state vector x % x=ones(len. % count transitions between states n21=sum(diff(x)==-1).:).2).idx) + rth*randn.1)+n11 g(1. % step size parameter updates % state 1 % allocate % sample transition probability matrix p % n12=sum(diff(x)==1).:)=p1. % sample from Beta distribution p1=betarnd([g(1. n11=sum((x(1:end-1)==1)+(x(2:end)==1)==2).1). 57 . p(k.

sp(it.2)*p1(3:end). FFBS algorithm % % forward filtering % sp(1. end % filtering..tT(2:end).:)=0.1)+sf(it.len-1).idx)). end % backward sampling % x=ones(len. sf(it.tT.tT(2:end).:).rg(2.1)*p1(1:2)+sf(it.t(2:end).th(k-1.m llh=sum(log(mclh(y.dt.idx)].:).. sf(2:end. % acceptance probability alpha=min(1.:)=sf(it.1) ones(len-1.1)].dt. -log(mclh(y.th(k.. th(k. th(k.:)..:)=sp(1.:). else th(k.t..st.tT..*sp(it-1.1) zeros(len-1.:).2)).2)=mclh(y(2:end).len-1).1) x(len)=2.1)]. sf(1.:)=sf(it..1)=mclh(y(2:end).:)=th1. if rand<=alpha.dt.t(2:end).th1.[ones(len-1.:)/(sf(it.:)=th(k-1.t.% complete-data likelihood % call mclh. for it=2:len sf(it. if rand>sf(end. end for it=len-1:-1:1 % state 1 58 .[zeros(len-1.:). % prior densities pr=unifpdf([th1(idx) th(k-1.len))).:).dt.1).:)=sf(it.st. sf(2:end.len)).5*(p1(1:2)+p1(3:end)).llh*pr(1)/pr(2)).idx).rg(1..

x.1:2).*tT)*(1-th(5))).1)=sum(x.m Returns components of complete-data likelihood function sig=zeros(T.^2).1) x(it)=2.th. lh=lh.*(th(10)exp(-sum(x. mu=dt*sum(sig.*sf(it.5*mu).31+2*pi. % update end % output % mu_th=mean(th(burnin+1:end.8+.*th(ones(1.*t)).*sig.*tT)).:)) In the routine for the Gibbs sampler.2)./sqrt(mu).*th(ones(1.*th(ones(1.2).:).2)).T).T).2).:)/(sc(it.sc(it.tT. 59 . the function mclh.*sig.:)=sc(it.*th(ones(1.*(th(5)+ exp(-sum(x.T).:)=p1([x(it+1) x(it+1)+2]).dt.:)) mu_p=mean(p(burnin+1:end. mclh.2). end end th1=th(k. sc(it.3:4).5*((y+0.:).sig]=mclh(y. function [lh.6:7).2).2). This function is given below.8:9).1)).t. if rand>sc(it.m is called to evaluate the complete-data likelihood for various values of the parameters.08*(1+sin(./mu).2)=sum(x.ones(2. sig(:.T). sig=ct(:. sig(:. lh=exp(-0.1)+sc(it.T). ct=.

36 .:)*15. burnin=iter/5. g=p(1. dt=1/252.m Parameter estimation of Markov switching model with MCMC clc.% daily % priors % p(1. mcmc.m Gibbs sampler.16 .4). tT=tT(1:end-1. load tT y=log(f(2:end. % guess transition probabilities % prior expectation of % probability matrix 60 .84].64 .13).1:12).1:12)). p=zeros(iter.:)=[.1:12))-log(f(1:end-1. th=zeros(iter. % allocate % generate simulated data % load f.Appendix E mcmc. clear all % initialize % iter=2*1e2.

sample = sub2ind(dim. lam=unidrnd(dim(2).2). if rand>p(1. for it=2:len. 1:dim(1).5 5 5 1 1 1 1]. for k=2:iter sp=zeros(len.13).end end % algorithm % th1=th(1.5 1.2). sf=zeros(len. % allocate % sample transition probability matrix p % 61 . t=flipud(tT).. .1). tT=tT(sample)’.1.% time % draw x len=size(tT. % initial parameter values rg=[zeros(1.5 1.8 .8 2 2 .dim(1).5 5 5 1 1.2*x(it-1)-1).3]. sc=zeros(len.:).5 1 1 3 .5 . lam’). x=ones(len.2).1).% use linear indexing % construct return & maturity vectors with % corresponding data points y=y(sample)’. rth=0.03.1). % bounds for parameter va % step size parameter updates % implement ’randomized’ algorithm % dim=size(y).x(it)=2.th(1.08 .:)=[..3 . x(1)=unidrnd(2).7 .

% sample from Beta distribution p1=betarnd([g(1.1)=mclh2(y(2:end).idx)].2)+n12 g(1. % prior densities pr=unifpdf([th1(idx) th(k-1.:)=th1.4)+n22]). th(k. % acceptance probability alpha=min(1.dt..st. p(k.:)=p1.dt.idx) + rth*randn. FFBS algorithm % % forward filtering % sp(1. n22=sum((x(1:end-1)==2)+(x(2:end)==2)==2).llh*pr(1)/pr(2)).:).1)+n11 g(1. % random parameter choice % generate th1(idx)=th(k-1. if rand<=alpha.idx). end % filtering.len))).tT. st=[x==1 x==2].:).n12=sum(diff(x)==1).. 62 .len)).[ones(len-1. sf(2:end.rg(1. % update % Metropolis-Hastings algorithm % idx=unidrnd(13)..t.t(2:end).1)].:).5*(p1(1:2)+p1(3:end)).tT(2:end).[g(1.idx))..:).len-1).dt.rg(2. % complete-data likelihood % call mclh.tT.st. p1=[p1(1) 1-p1(1) p1(2) 1-p1(2)].th(k-1.:)=sp(1.th1. else th(k. sf(1. % count transitions between states n21=sum(diff(x)==-1).3)+n21]..m llh=sum(log(mclh2(y.:)=th(k-1.th(k.t. -log(mclh2(y.:)=0. n11=sum((x(1:end-1)==1)+(x(2:end)==1)==2).1) zeros(len-1.

if rand>sc(it.2)). plot(th(:..2)).tT(2:end).:)=p1([x(it+1) x(it+1)+2]). sc(it.*sf(it.:).:)) mu_p=mean(p(burnin+1:end.1)+sf(it.dt. end % state 1 for it=len-1:-1:1 sc(it.1) x(len)=2. end % backward sampling % x=ones(len.1) x(it)=2.:)/(sf(it. % update % debug %th(k.1) ones(len-1..:)=sf(it.:).:).1)].len-1).:). for it=2:len sf(it.1).1).:)=sf(it.:)) % plot % % volatility parameters subplot(2.:)/(sc(it.1)+sc(it. th(k. sf(it. end end th1=th(k..2)*p1(3:end).:)=sf(it.1)) 63 .t(2:end).1)*p1(1:2)+sf(it.2)=mclh2(y(2:end).*sp(it-1.:).sf(2:end.:)=sc(it.2. if rand>sf(end. sp(it.6) end % output % mu_th=mean(th(burnin+1:end.[zeros(len-1.

m is called to evaluate the complete-data likelihood for various values of the parameters.*(th(5)+exp(-sum(x.2.dt.3:4).2).2.5*((y+0.*th(ones(1.6:7).*tT sig(:.sig]=mclh2(y.t. the function mclh2. 64 . plot(th(:.2.T).1)=sum(x.8+. plot(th(:.4)) subplot(2. This function is given below.2). plot(th(:. ct=th(11)+th(12)*(1+sin(th(13)+2*pi.08*(1+sin(.T). plot(th(:.x.2).8:9).2)) subplot(2. lh=lh.*t sig=ct(:.6)) subplot(2.2.*t)).*th(ones(1.31+2*pi.T). mu=dt*sum(sig.T) Returns components of complete-data likelihood function sig=zeros(T.3).1:2).2).*sig./mu).2).5*mu).3). plot(th(:.1)).*sig.2).*t)).subplot(2.2)=sum(x.3)) subplot(2.4). sig(:.*th(ones(1.2.7)) % attenuation parameters figure subplot(2.*th(ones(1.^2).ones(2.2)./sqrt(mu). function [lh. %ct=.2). plot(th(:.T). plot(th(:.4).2. lh=exp(-0.th.1).2.8)) subplot(2.tT.9)) In the routine for the Gibbs sampler.*(th(10)-exp(-sum(x.

Working Paper. Clewlow. Kwok. [10] Deng. Journal of Econometrics 75. Sydney. S. Energy Risk. 353–88. “Stochastic modeling of ﬁnancial electricity contracts”. “Piecewise-deterministic Markov processes: a general class of non-diﬀusion stochastic models”. 60-64. Energy Economics 30. & Strickland. 577-586. C. [5] Chib. C. QFRC Research Paper Series 28. [2] Breslin. C. 79-97.”. L. (1984). (1999). B. C. April. B. [6] Chib. C. & Kang. & Koekebakker. (1995). (2008). 65 . S. M. Working Paper. J. Journal of Royal Statistical Society B. 1116-1157.“Gaining from complexity: MFMC models”. Journal of the American Statistical Association 90. Proceedings of the 33rd Hawaii International Conference on System Sciences. (1996). University of Technology. N. F.Bibliography [1] Benth. [4] Chiarella. “Marginal likelihood from the Gibbs output”. & R. S. (2009) “Modelling and estimating the forward price curve in the energy market”. “A multi-factor model for energy derivatives”. & Polson. [3] Carlin. L. (1992). Clewlow. “Option formulas for mean-reverting power prices with spikes. (2000). Bayesian Statistics 4. 46. Rotterdam School of Management at Erasmus University... [7] Clewlow. S.. [9] de Jong. & Strickland. (2008). “Calculating posterior distributions and modal estimates in Markov Mixture models”. Huisman (2002). 1313-1321. “Monte Carlo Bayesian methods for discrete regression models and categorical time series”. “Pricing electricity derivatives under alternative stochastic spot price models. L. [8] Davis.”.

[20] Hamilton. R. [16] Gilks. R. 409-29. Theory of Probability and its Applications 39. Springer. [19] Hamilton. Journal of Finance 48. “MCMC methods for continuous-time ﬁnancial econometrics”. Chapman & Hall. G. S.. A. 357-384. D.J.[11] Di Masi. London. (1994). [14] Fr¨hwirth-Schnatter. R. & Wilson. Working Paper.E. [21] Hansen. (1993). 77–105. Journal of Econometrics 45. V. (2002). 66 . applications of mathematics”. Linz 2007-09. L.S. “Stochastic convience yield and the pricing of oil contingent claims. (1992). [15] Gibson. R. E.“Analysis of time series subject to changes in regime”. “A Markov model for switching regressions”. Econometrica 60. S. “Markov Chain Monte Carlo in Practice”. & Sass. Jarrow. 172-182. “Hidden Markov Models: estimation and control. Finance and Stochastics 4. “Bond pricing and the term structure of interest rates: a new methodology”.D. “A simple regime switching term structure model”. & Moore. “The term structure of interest rates when a Markov chain is driving drift and volatility parameters of the short rate diﬀusion process”. & Morton. S. [13] Elliott. & Quandt. Handbook of Financial Econometrics.. “A New approach to the economic analysis of nonstationary time series and the business cycle”. J.J.M. Econometrica 57. [18] Hahn. Kabanov. [12] Elliott. & Runggaldier W. (2000). (2006). M. 39-70. (1973).Journal of Econometrics 1. J.“Mean-variance hedging of options on stocks with Markov volatilities”. S. (1995). 1969-1984.T. (2007). & Poulsen. (1998). Springer-Verlag. J. (1989). (2001). Aggoun.D..R. (1990). ” The Journal of Finance 45. [22] Heath. “Markov Chain Monte u Carlo methods for parameter estimation in multidimensional continuous time Markov switching models”. Yu. 959-976. M. 3-15. M. R. [17] Goldfeld. “Finite Mixture and Markov Switching Modu els”. R. & Schwartz. New York. C. [23] Johannes.“Option valuation and hedging strategies with jumps in the volatility of asset returns”. N. RICAM. J. Richardson.. Fr¨hwirth-Schnatter. W. [24] Naik. New York. & Spiegelhalter D. & Polson.B. A. (1990).

S. “Stochastic volatility Gaussian Heath-Jarrow-Morton models”. & Uhrig-Homburg. The Journal of the American Statisctical Association 97..R. & Seppi. [28] Seifert.J. J. Review of Derivatives Research 10. (2005). (2007). S. McGraw-Hill. D. (2002). [26] Rambharat. [27] Scott. (2007). “Bayesian methods for Hidden Markov models”. “A threshold autoregressive model for wholesale electricity prices”. 337-351.E. 59-85. [29] Valchev. 347-368. Second edition. 54. Journal of the Royal Statistical Society C. B. 287-299. 67 . Applied Mathematical Finance 11. “Energy risk: valuing and managing energy derivatives”.[25] Pilipovic. “ Modelling jumps in electricity prices: theory and empirical evidence”. Brockwel A. (2004). D. M.

- Read and print without ads
- Download to keep your version
- Edit, email or read offline

Are you sure?

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

CANCEL

OK

You've been reading!

NO, THANKS

OK

scribd

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->