Zurich University
of Applied Sciences
School of
Engineering
IDP Institute of
Data Analysis and
Process Design
Commodity Modelling
Schwartz two-factor model
Philipp Erb – IDP Winterthur
July 2, 2009
David Lüthi – Clariden Leu Zürich
Commodity Modelling
Outline
1
Motivation
2
Commodity model types
3
Schwartz two-factor model in a nutshell
Model dynamics
Joint distribution of state variables
Pricing of basic derivatives
Risk measures
4
Using schwartz97
Parameter Estimation
Examples
IDP Winterthur, Clariden Leu Zürich
1 / 33
Commodity Modelling
2 / 33
Motivation
Motivation and Context
CTI project between IDP and FRSGlobal
Extending FRSGlobal’s softwaretool riskpro with commodity models
Schwartz fator model: Basic model
A Hinz model: More advanced model
Implementation of protoype models in R
No commodity models on CRAN so far
⇒ Launching commodity model package ’schwartz97’
IDP Winterthur, Clariden Leu Zürich
Commodity Modelling
Commodity model types
Outline
1
Motivation
2
Commodity model types
3
Schwartz two-factor model in a nutshell
Model dynamics
Joint distribution of state variables
Pricing of basic derivatives
Risk measures
4
Using schwartz97
Parameter Estimation
Examples
IDP Winterthur, Clariden Leu Zürich
3 / 33
Commodity Modelling
4 / 33
Commodity model types
Commodity model types
Spot price models: E.g. Schwartz factor models
Few parameters
Inflexible term sturcutre of futures prices
Futures price models: E.g. HJM type model by Juri Hinz
Numerous parameters
Flexible term sturcture generic
IDP Winterthur, Clariden Leu Zürich
Commodity Modelling
Commodity model types
Schwartz factor models
One-factor model
Spot price Log-price mean-reverting (Ornstein-Uhlenbeck)
Two-factor model
Spot price Log-normal (Geometric Brownian motion)
Convenience yield Mean-reverting (Ornstein-Uhlenbeck)
Three-factor model
Spot price Log-normal (Geometric Brownian motion)
Convenience yield Mean-reverting (Ornstein-Uhlenbeck)
Interest rate Mean-reverting (Vasicek)
Empirical study: Two-factor model most-parsimonious choice
IDP Winterthur, Clariden Leu Zürich
5 / 33
Commodity Modelling
Schwartz two-factor model in a nutshell
Outline
1
Motivation
2
Commodity model types
3
Schwartz two-factor model in a nutshell
Model dynamics
Joint distribution of state variables
Pricing of basic derivatives
Risk measures
4
Using schwartz97
Parameter Estimation
Examples
IDP Winterthur, Clariden Leu Zürich
6 / 33
Commodity Modelling
7 / 33
Schwartz two-factor model in a nutshell
Model dynamics: Two-factor model
The P-dynamics:
dSt = (µ − δt ) St dt + σS St dWS
dδt = κ (α − δt ) dt + σ dW
dWS dW = ρdt
The Q-dynamics:
dSt = (r − δt ) St dt + σS St d W̃S
dδt = [κ (α − δt ) − λ] dt + σ d W̃
d W̃S d W̃ = ρdt
IDP Winterthur, Clariden Leu Zürich
Commodity Modelling
Schwartz two-factor model in a nutshell
Outline
1
Motivation
2
Commodity model types
3
Schwartz two-factor model in a nutshell
Model dynamics
Joint distribution of state variables
Pricing of basic derivatives
Risk measures
4
Using schwartz97
Parameter Estimation
Examples
IDP Winterthur, Clariden Leu Zürich
8 / 33
Commodity Modelling
9 / 33
Schwartz two-factor model in a nutshell
Joint distribution of state variables
Log-price X := log S and convenience yield δ joint normal
⇒ Solve SDE under P and Q and compute first two moments:
I
Distribution under P and Q
2
X
µX
σX
P
=N ∼ µ=
,Σ =
δ
µδ
σX δ
2
X
µ̃X
σX
Q
= N ∼ µ̃ =
,Σ =
δ
µ̃δ
σX δ
Basic tool for all computations
(pricing, simulation, risk measures, calibration)
IDP Winterthur, Clariden Leu Zürich
σX δ
σδ2
σX δ
σδ2
,
Commodity Modelling
Schwartz two-factor model in a nutshell
Outline
1
Motivation
2
Commodity model types
3
Schwartz two-factor model in a nutshell
Model dynamics
Joint distribution of state variables
Pricing of basic derivatives
Risk measures
4
Using schwartz97
Parameter Estimation
Examples
IDP Winterthur, Clariden Leu Zürich
10 / 33
Commodity Modelling
11 / 33
Schwartz two-factor model in a nutshell
Futures
Futures prices:
1
2
G(S0 , δ0 , T ) = EQ [ST ] = e µ̃X + 2 σ̃X
= S0 e A(T )+B(T )δ0
with
r − α̃ +
A(T ) =
1 σ2
σS σ ρ
−
2 κ2
κ
+
B(T ) =
IDP Winterthur, Clariden Leu Zürich
κα̃ + σS σ ρ −
e −κT − 1
κ
σ2
κ
T+
1 2 1 − e −2κT
σ
4
κ3
1 − e −κT
,
κ2
Commodity Modelling
Schwartz two-factor model in a nutshell
Futures
Affine term structure of futures prices:
log G(T ) = X0 + B(T )δ0 + A(T )
⇒ Model can be cast in state space form
Both state variables (factors: Xt , δt ) unobservable
⇒ Kalman filter
IDP Winterthur, Clariden Leu Zürich
12 / 33
Commodity Modelling
Schwartz two-factor model in a nutshell
European Options
Affine term structure of futures prices:
log G(T ) = X0 + B(T )δ0 + A(T )
⇒ Futures prices log-normal
⇒ BS-type formulas for European options on futures
IDP Winterthur, Clariden Leu Zürich
13 / 33
Commodity Modelling
14 / 33
Schwartz two-factor model in a nutshell
European Options
European call option:
C G = EQ e −r t (G(St , δt , T − t) − K )+
= P(0, t) {G(0, T )Φ(d+ ) − K Φ(d− )}
with
log
d± =
2
G(0,T )
K
± 21 σ 2
σ
2
σ = σS t +
2σS σ ρ
κ
,
1 −κT
e
κ
e
κt
−1
−t
+
σ2
κ2
t+
1
2κ
e
−2κT
e
2κt
−1
−
2 −κT
e
κ
Put-call parity:
C G − P G = P(0, t) {G(0, t) − K }
European put option:
P G = P(0, t) {K Φ(−d− ) − G(0, T )Φ(−d+ )}
IDP Winterthur, Clariden Leu Zürich
e
κt
−1
Commodity Modelling
Schwartz two-factor model in a nutshell
Outline
1
Motivation
2
Commodity model types
3
Schwartz two-factor model in a nutshell
Model dynamics
Joint distribution of state variables
Pricing of basic derivatives
Risk measures
4
Using schwartz97
Parameter Estimation
Examples
IDP Winterthur, Clariden Leu Zürich
15 / 33
Commodity Modelling
16 / 33
Schwartz two-factor model in a nutshell
Risk Measures
Affine term structure of futures prices:
log G(T ) = X0 + B(T )δ0 + A(T )
⇒ Futures log-price Gaussian: log G ∼ N µG , σG2
⇒ Losses (negative log-returns) Gaussian
⇒ Closed formulas for value at risk (VaR) and expected
shortfall (ES) for futures contracts
IDP Winterthur, Clariden Leu Zürich
Commodity Modelling
Using schwartz97
Outline
1
Motivation
2
Commodity model types
3
Schwartz two-factor model in a nutshell
Model dynamics
Joint distribution of state variables
Pricing of basic derivatives
Risk measures
4
Using schwartz97
Parameter Estimation
Examples
IDP Winterthur, Clariden Leu Zürich
17 / 33
Commodity Modelling
18 / 33
Using schwartz97
Function Overview: Usual d/p/q/r style
If all parameters are known, the transition density is known.
⇒ For a fixed point in time, the distribution is defined.
d/p/q/r-state d/p/q/r functions for the bivariate state variables.
simstate Generate trajectories from the state variables.
d/p/q/r-futures d/p/q/r functions for the log-normal futures prices.
IDP Winterthur, Clariden Leu Zürich
Commodity Modelling
19 / 33
Using schwartz97
Function Overview: Estimation, pricing, risk
fit2factor Fit parameters to data.
pricefutures Calculate futures prices.
priceoption Price a European call or put option written on a futures
contract.
VaR/ES-futures Value-at-risk and Expected-shortfall of futures prices.
filter2factor Filter a futures price series and obtain the state
variables.
IDP Winterthur, Clariden Leu Zürich
Commodity Modelling
20 / 33
Using schwartz97
Object Orientation
Problem: Many parameters involved
The transition density of the state variables depends on 8 parameter:
(s0 , δ0 , µ, σS , κ, α, σ , ρ)
The transition density of the futures price depends on 10 parameter:
(s0 , δ0 , µ, σS , κ, α, σ , ρ, λ, r )
Idea: 3 levels of encapsulation
Raw parameters.
schwartz2factor-class
fit.schwartz2factor-class
IDP Winterthur, Clariden Leu Zürich
Commodity Modelling
21 / 33
Using schwartz97
Example: dfutures
dfutures(x, ttm = 1, s0 = 50, delta0 = 0,
mu = 0.1, sigmaS = 0.3, kappa = 1, alpha = 0,
sigmaE = 0.5, rho = 0.75, r = 0.05, lambda = 0,
alphaT = NULL, ...)
## S4 method for signature ’ANY, ANY, schwartz2factor’:
dfutures(x, ttm = 1, s0, r = 0.05, lambda = 0,
alphaT = NULL, ...)
## S4 method for signature ’ANY, ANY, fit.schwartz2factor’:
dfutures(x, ttm = 1, s0, ...)
IDP Winterthur, Clariden Leu Zürich
Commodity Modelling
Using schwartz97
Outline
1
Motivation
2
Commodity model types
3
Schwartz two-factor model in a nutshell
Model dynamics
Joint distribution of state variables
Pricing of basic derivatives
Risk measures
4
Using schwartz97
Parameter Estimation
Examples
IDP Winterthur, Clariden Leu Zürich
22 / 33
Commodity Modelling
23 / 33
Using schwartz97
State Space Representation
Transition equation:
The state variables are log-spot price and convenience yield.
αt+1 = dt + Tt αt + Ht t ,
t ∼ N (0, I2 )
(4.1)
Measurement equation:
Futures prices are measured. The log-futures price are an affine
function of the log-spot price and the convenience yield.
yt
= ct + Zt αt + Gt η t ,
IDP Winterthur, Clariden Leu Zürich
η t ∼ N (0, In )
(4.2)
Commodity Modelling
24 / 33
Using schwartz97
State Space Model: Transition Equation
t ∼ N (0, I2 )
αt+1 = dt + Tt αt + Ht t ,
αt+∆t
Tt
=
Xt+∆t
δt+∆t
=
1
0
dt
0
Ht Ht
=
=
1
κ
!
(4.4)
!
e −κ∆t − 1
e −κ∆t
(4.5)
α 1−
α
κ 1
e −κ∆t
µ − 12 σS2 − α ∆t +
σX2 (∆t) σX δ (∆t)
σX δ (∆t) σδ2 (∆t),
where Xt = log St and ∆t = tk+1 − tk .
IDP Winterthur, Clariden Leu Zürich
(4.3)
− e −κ∆t
(4.6)
!
(4.7)
Commodity Modelling
25 / 33
Using schwartz97
State Space Model: Measurement Equation
yt
= ct + Zt αt + Gt η t ,
log Gt (1)
..
yt =
.
log Gt (n)
η t ∼ N (0, In )
1 B(mt (1))
.
..
.
Zt =
.
.
1 B(mt (n))
2
g11
A(mt (1))
0
.
Gt G =
..
ct =
t
A(mt (n))
(4.9)
..
.
2
gnn
where mt (i) denotes the remaining time to maturity of the i-th
closest to maturity futures Gt (i).
IDP Winterthur, Clariden Leu Zürich
(4.8)
(4.10)
Commodity Modelling
26 / 33
Using schwartz97
Function fit2factor
fit2factor(data, ttm, deltat = 1 / 260,
s0 = data[1,1], delta0 = 0,
mu = 0.1, sigmaS = 0.3, kappa = 1, alpha = 0, sigmaE = 0.5,
rho = 0.75, lambda = 0,
meas.sd = rep(0.02, ncol(data)),
opt.pars = c(s0 = FALSE, delta0 = FALSE, mu = TRUE, sigmaS = TRUE,
kappa = TRUE, alpha = TRUE, sigmaE = TRUE,
rho = TRUE, lambda = TRUE),
opt.meas.sd = c("scalar", "all", "none"),
r = 0.05, silent = FALSE, ...)
IDP Winterthur, Clariden Leu Zürich
Commodity Modelling
Using schwartz97
Outline
1
Motivation
2
Commodity model types
3
Schwartz two-factor model in a nutshell
Model dynamics
Joint distribution of state variables
Pricing of basic derivatives
Risk measures
4
Using schwartz97
Parameter Estimation
Examples
IDP Winterthur, Clariden Leu Zürich
27 / 33
Commodity Modelling
28 / 33
Using schwartz97
Function fit2factor
> library(schwartz97)
Loading required package: FKF
Loading required package: mvtnorm
> data(futures)
> na.idx <- apply(is.na(copper$futures), 1, any)
> copper.fit <- fit2factor(copper$futures[!na.idx,], copper$ttm[!na.idx,],
+
control = list(maxit = 100, reltol = 1e-3),
+
silent = TRUE)
>
IDP Winterthur, Clariden Leu Zürich
Commodity Modelling
29 / 33
Using schwartz97
Function fit2factor
> copper.fit
---------------------------------------------------------------Fitted Schwartz97 2 factor model:
d S_t
= S_t
* (mu - delta_t)
* dt + S_t * sigmaS * dW_1
d delta_t = kappa * (alpha - delta_t) * dt + sigmaE * dW_2
E(dW_1 * dW_2) = rho * dt
s0
: 109.375364269883
delta0: 0
mu
: 0.212827842930593
sigmaS: 0.37460428511304
kappa : 1.10747274866091
alpha : 0.0595560374598207
sigmaE: 0.474809676990843
rho
: 0.813002684142751
r
: 0.05
lambda: 0.0402214875501909
alphaT: 0.0232377735577751
---------------------------------------------------------------Optimization information
Converged:
TRUE
Fitted parameters: mu, sigmaS, kappa, alpha, sigmaE, rho, lambda, meas.sd1; (Num
log-Likelihood:
112485.1
Nbr. of iterations: 75
--------------------------------------------------------------->
IDP Winterthur, Clariden Leu Zürich
Commodity Modelling
30 / 33
Using schwartz97
Function filter2factor
350
> filter2factor(copper$futures[!na.idx,], copper$ttm[!na.idx,], copper.fit)
>
50
200
Spot price
Closest to maturity futures
0
1000
2000
3000
4000
5000
4000
5000
0.5
Index
−0.1
0.2
Convenience yield
0
1000
2000
3000
Index
IDP Winterthur, Clariden Leu Zürich
Commodity Modelling
31 / 33
Using schwartz97
Derivatives
> pricefutures(ttm = 3, copper.fit)
[1] 107.1682
> priceoption("call", time = 2, Time = 3, K = 110, copper.fit)
[1] 12.33399
>
IDP Winterthur, Clariden Leu Zürich
Commodity Modelling
32 / 33
Using schwartz97
Conclusion & Outlook
Conclusion
(Optimal??) trade-off: Statistical tractability vs. sophistication.
Stylized model.
First step towards commodity modelling in R.
Outlook
Implementing term-structure models (Juri Hinz & Max Fehr, 2007).
IDP Winterthur, Clariden Leu Zürich
Commodity Modelling
Using schwartz97
References
Rajna Gibson and Eduardo S. Schwartz.
Stochastic convenience yield and the pricing of oil contingent claims.
The Journal of Finance, 45(3):959–976, 1990.
Eduardo S. Schwartz.
The stochastic behavior of commodity prices: Implications for valuation and
hedging.
Journal of Finance, 52(3):923–973, 1997.
Kristian R. Miltersen and Eduardo S. Schwartz.
Pricing of options on commodity futures with stochastic term structures of
convenience yields and interest rates.
Journal of Financial and Quantitative Analysis, 33:33–59, 1998.
IDP Winterthur, Clariden Leu Zürich
33 / 33
© Copyright 2026 Paperzz