schwartz2 factor implementation in r

Upload: abhi-suri

Post on 04-Jun-2018

224 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/13/2019 Schwartz2 factor Implementation in r

    1/34

    Commodity Modelling

    Schwartz two-factor model

    Philipp Erb IDP Winterthur David Lthi Clariden Leu Zrich

    July 2, 2009

    School ofEngineering

    IDP Institute ofData Analysis andProcess Design

    Zurich University

    of Applied Sciences

  • 8/13/2019 Schwartz2 factor Implementation in r

    2/34

  • 8/13/2019 Schwartz2 factor Implementation in r

    3/34

    Commodity Modelling 2 / 33

    Motivation

    Motivation and Context

    CTI project between IDP and FRSGlobal

    Extending FRSGlobals 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 Zrich

  • 8/13/2019 Schwartz2 factor Implementation in r

    4/34

    Commodity Modelling 3 / 33

    Commodity model types

    Outline

    1 Motivation2 Commodity model types

    3 Schwartz two-factor model in a nutshell

    Model dynamicsJoint distribution of state variables

    Pricing of basic derivatives

    Risk measures

    4 Using schwartz97

    Parameter Estimation

    Examples

    IDP Winterthur, Clariden Leu Zrich

  • 8/13/2019 Schwartz2 factor Implementation in r

    5/34

    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 Zrich

    C di M d lli 5 / 33

  • 8/13/2019 Schwartz2 factor Implementation in r

    6/34

    Commodity Modelling 5 / 33

    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 Zrich

    C dit M d lli 6 / 33

  • 8/13/2019 Schwartz2 factor Implementation in r

    7/34

    Commodity Modelling 6 / 33

    Schwartz two-factor model in a nutshell

    Outline

    1 Motivation

    2 Commodity model types

    3 Schwartz two-factor model in a nutshell

    Model dynamicsJoint distribution of state variablesPricing of basic derivativesRisk measures

    4 Using schwartz97Parameter EstimationExamples

    IDP Winterthur, Clariden Leu Zrich

    Commodity Modelling 7 / 33

  • 8/13/2019 Schwartz2 factor Implementation in r

    8/34

    Commodity Modelling 7 / 33

    Schwartz two-factor model in a nutshell

    Model dynamics: Two-factor model

    The P-dynamics:

    dSt= ( t) Stdt+ SStdWS

    dt= ( t) dt+ dW

    dWSdW =dt

    The Q-dynamics:

    dSt= (r t) Stdt+ SStdWS

    dt= [ ( t) ] dt+ dW

    dWSdW =dt

    IDP Winterthur, Clariden Leu Zrich

    Commodity Modelling 8 / 33

  • 8/13/2019 Schwartz2 factor Implementation in r

    9/34

    Commodity Modelling 8 / 33

    Schwartz two-factor model in a nutshell

    Outline

    1 Motivation2 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 Zrich

    Commodity Modelling 9 / 33

  • 8/13/2019 Schwartz2 factor Implementation in r

    10/34

    Commodity Modelling 9 / 33

    Schwartz two-factor model in a nutshell

    Joint distribution of state variables

    Log-priceX :=log Sand convenience yield joint normal

    Solve SDE under P and Q and compute first two moments: Distribution underP and Q

    X

    = N

    P

    =

    X

    , =

    2X XX

    2

    ,

    X

    = N

    Q

    =

    X

    , =

    2X XX

    2

    Basic tool for all computations(pricing, simulation, risk measures, calibration)

    IDP Winterthur, Clariden Leu Zrich

    Commodity Modelling 10 / 33

  • 8/13/2019 Schwartz2 factor Implementation in r

    11/34

    Commodity Modelling 10 / 33

    Schwartz two-factor model in a nutshell

    Outline

    1 Motivation

    2 Commodity model types

    3 Schwartz two-factor model in a nutshell

    Model dynamicsJoint distribution of state variablesPricing of basic derivativesRisk measures

    4 Using schwartz97Parameter EstimationExamples

    IDP Winterthur, Clariden Leu Zrich

    Commodity Modelling 11 / 33

  • 8/13/2019 Schwartz2 factor Implementation in r

    12/34

    y g /

    Schwartz two-factor model in a nutshell

    Futures

    Futures prices:

    G(S0, 0, T) =EQ [ST] =e

    X+122

    X

    =S0eA(T)+B(T)0

    with

    A(T) = r + 1

    2

    2

    2

    S

    T+ 1

    4

    2

    1 e2T

    3

    +

    + S

    2

    1 e

    T

    2 ,

    B(T) = eT

    1

    IDP Winterthur, Clariden Leu Zrich

    Commodity Modelling 12 / 33

  • 8/13/2019 Schwartz2 factor Implementation in r

    13/34

    y g /

    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 Zrich

    Commodity Modelling 13 / 33

  • 8/13/2019 Schwartz2 factor Implementation in r

    14/34

    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 Zrich

  • 8/13/2019 Schwartz2 factor Implementation in r

    15/34

    Commodity Modelling 15 / 33

  • 8/13/2019 Schwartz2 factor Implementation in r

    16/34

    Schwartz two-factor model in a nutshell

    Outline

    1 Motivation

    2 Commodity model types

    3 Schwartz two-factor model in a nutshell

    Model dynamicsJoint distribution of state variables

    Pricing of basic derivatives

    Risk measures

    4 Using schwartz97

    Parameter Estimation

    Examples

    IDP Winterthur, Clariden Leu Zrich

    Commodity Modelling 16 / 33

  • 8/13/2019 Schwartz2 factor Implementation in r

    17/34

    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 NG, 2G

    Losses (negative log-returns) Gaussian

    Closed formulas for value at risk (VaR) and expected

    shortfall (ES) for futures contracts

    IDP Winterthur, Clariden Leu Zrich

    Commodity Modelling 17 / 33

  • 8/13/2019 Schwartz2 factor Implementation in r

    18/34

    Using schwartz97

    Outline1

    Motivation2 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 Zrich

    Commodity Modelling 18 / 33

  • 8/13/2019 Schwartz2 factor Implementation in r

    19/34

    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 Zrich

    Commodity Modelling 19 / 33

    U i h 97

  • 8/13/2019 Schwartz2 factor Implementation in r

    20/34

    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 Zrich

    Commodity Modelling 20 / 33

    U i h t 97

  • 8/13/2019 Schwartz2 factor Implementation in r

    21/34

    Using schwartz97

    Object Orientation

    Problem: Many parameters involvedThe 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 Zrich

    Commodity Modelling 21 / 33

    Using schwartz97

  • 8/13/2019 Schwartz2 factor Implementation in r

    22/34

    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 Zrich

    Commodity Modelling 22 / 33

    Using schwartz97

  • 8/13/2019 Schwartz2 factor Implementation in r

    23/34

    Using schwartz97

    Outline

    1 Motivation

    2 Commodity model types

    3 Schwartz two-factor model in a nutshell

    Model dynamicsJoint distribution of state variables

    Pricing of basic derivatives

    Risk measures

    4 Using schwartz97Parameter Estimation

    Examples

    IDP Winterthur, Clariden Leu Zrich

    Commodity Modelling 23 / 33

    Using schwartz97

  • 8/13/2019 Schwartz2 factor Implementation in r

    24/34

    Using schwartz97

    State Space Representation

    Transition equation:

    The state variables arelog-spot priceandconvenience yield.

    t+1 = dt+Ttt+Htt, 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+Ztt+Gtt, t N(0, In) (4.2)

    IDP Winterthur, Clariden Leu Zrich

    Commodity Modelling 24 / 33

    Using schwartz97

  • 8/13/2019 Schwartz2 factor Implementation in r

    25/34

    Using schwartz97

    State Space Model: Transition Equation

    t+1 = dt+Ttt+Htt, t N(0, I2) (4.3)

    t+t =

    Xt+tt+t

    (4.4)

    Tt =

    1 1

    et 1

    0 et

    (4.5)

    dt = 12

    2S

    t+

    1 et

    1 e

    t (4.6)

    HtH

    t =

    2X(t) X(t)X(t)

    2 (t),

    (4.7)

    where Xt=log St and t=tk+1 tk.

    IDP Winterthur, Clariden Leu Zrich

    Commodity Modelling 25 / 33

    Using schwartz97

  • 8/13/2019 Schwartz2 factor Implementation in r

    26/34

    g

    State Space Model: Measurement Equation

    yt = ct+Ztt+Gtt, t N(0, In) (4.8)

    yt=

    log Gt(1)

    ...

    log Gt(n)

    Zt= 1 B(mt(1))

    ... ...

    1 B(mt(n))

    (4.9)

    ct=

    A(mt(1))...

    A(mt(n))

    GtG

    t=

    g211. .

    .g2nn

    (4.10)

    where mt(i) denotes the remaining time to maturityof the i-th

    closest to maturity futures Gt(i).

    IDP Winterthur, Clariden Leu Zrich

  • 8/13/2019 Schwartz2 factor Implementation in r

    27/34

    Commodity Modelling 27 / 33Using schwartz97

  • 8/13/2019 Schwartz2 factor Implementation in r

    28/34

    Outline

    1 Motivation2 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

    ExamplesIDP Winterthur, Clariden Leu Zrich

    Commodity Modelling 28 / 33Using schwartz97

  • 8/13/2019 Schwartz2 factor Implementation in r

    29/34

    Function fit2factor

    > library(schwartz97)

    Loading required package: FKF

    Loading required package: mvtnorm

    > data(futures)

    > na.idx copper.fit

    IDP Winterthur, Clariden Leu Zrich

    Commodity Modelling 29 / 33Using schwartz97

  • 8/13/2019 Schwartz2 factor Implementation in r

    30/34

    Function fit2factor> copper.fit----------------------------------------------------------------Fitted Schwartz97 2 factor model:

    d S_t = S_t * (mu - delta_t) * dt + S_t * sigmaS * dW_1d delta_t = kappa * (alpha - delta_t) * dt + sigmaE * dW_2E(dW_1 * dW_2) = rho * dt

    s0 : 109.375364269883delta0: 0

    mu : 0.212827842930593

    sigmaS: 0.37460428511304kappa : 1.10747274866091alpha : 0.0595560374598207sigmaE: 0.474809676990843rho : 0.813002684142751r : 0.05lambda: 0.0402214875501909alphaT: 0.0232377735577751

    ----------------------------------------------------------------Optimization informationConverged: TRUEFitted parameters: mu, sigmaS, kappa, alpha, sigmaE, rho, lambda, meas.sd1; (Nulog-Likelihood: 112485.1Nbr. of iterations: 75---------------------------------------------------------------->

    IDP Winterthur, Clariden Leu Zrich

    Commodity Modelling 30 / 33Using schwartz97

  • 8/13/2019 Schwartz2 factor Implementation in r

    31/34

    Function filter2factor> filter2factor(copper$futures[!na.idx,], copper$ttm[!na.idx,], copper.fit)

    >

    0 1000 2000 3000 4000 5000

    50

    200

    350

    Index

    Spot priceClosest to maturity futures

    0 1000 2000 3000 4000 5000

    0.1

    0.2

    0.5

    Index

    Convenience yield

    IDP Winterthur, Clariden Leu Zrich

    Commodity Modelling 31 / 33Using schwartz97

  • 8/13/2019 Schwartz2 factor Implementation in r

    32/34

    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 Zrich

    Commodity Modelling 32 / 33Using schwartz97

  • 8/13/2019 Schwartz2 factor Implementation in r

    33/34

    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 Zrich

    Commodity Modelling 33 / 33Using schwartz97

  • 8/13/2019 Schwartz2 factor Implementation in r

    34/34

    References

    Rajna Gibson and Eduardo S. Schwartz.

    Stochastic convenience yield and the pricing of oil contingent claims.

    The Journal of Finance, 45(3):959976, 1990.

    Eduardo S. Schwartz.

    The stochastic behavior of commodity prices: Implications for valuation andhedging.

    Journal of Finance, 52(3):923973, 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:3359, 1998.

    IDP Winterthur, Clariden Leu Zrich