Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
commodityschwartzparametrization.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2022 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19/*! \file commodityschwartzparametrization.hpp
20 \brief Schwartz commodity model parametrization
21 \ingroup models
22*/
23
24#ifndef quantext_com_schwartz_parametrization_hpp
25#define quantext_com_schwartz_parametrization_hpp
26
27#include <ql/handle.hpp>
30
31namespace QuantExt {
32//! COM Schwartz parametrization
33/*! COM parametrization for the Schwartz (1997) mean-reverting one-factor model
34 with log-normal forward price dynamics and forward volatility sigma * exp(-kappa*(T-t)):
35 dF(t,T) / F(t,T) = sigma * exp(-kappa * (T-t)) * dW
36
37 The model can be propagated in terms of an artificial spot price process of the form
38 S(t) = A(t) * exp(B(t) * X(t))
39 where
40 dX(t) = -kappa * X(t) * dt + sigma * dW(t)
41 X(t) - X(s) = -X(s) * (1 - exp(-kappa*(t-s)) + int_s^t sigma * exp(-kappa*(t-u)) dW(u)
42 E[X(t)|s] = X(s) * exp(-kappa*(t-s))
43 Var[X(t)-X(s)|s] = sigma^2 * (1 - exp(-2*kappa*(t-s))) / (2*kappa)
44
45 The stochastic future price curve in terms of X(t) is
46 F(t,T) = F(0,T) * exp( X(t) * exp(-kappa*(T-t) - 1/2 * (V(0,T) - V(t,T))
47 with
48 V(t,T) = sigma^2 * (1 - exp(-2*kappa*(T-t))) / (2*kappa)
49 and
50 Var[ln F(T,T)] = VaR[X(T)]
51
52 Instead of state variable X we can use
53 Y(t) = exp(kappa * t) * X(t)
54 with drift-free
55 dY(t) = sigma * exp(kappa * t) * dW
56 Y(t) = int_0^t sigma * exp(kappa * s) * dW(s)
57 Var[Y(t)] = sigma^2 * (exp(2*kappa*t) - 1) / (2*kappa)
58 Var[Y(t)-Y(s)|s] = int_s^t sigma * exp(kappa * u) * dW(u) = Var[Y(t)] - Var[Y(s)]
59 The stochastic future price curve in terms of Y(t) is
60 F(t,T) = F(0,t) * exp( Y(t) * exp(-kappa*T) - 1/2 * (V(0,T) - V(t,T))
61
62 \ingroup models
63*/
65public:
66 /*! The currency refers to the commodity currency, the
67 fx spot is as of today (i.e. the discounted spot) */
68 CommoditySchwartzParametrization(const Currency& currency, const std::string& name,
69 const Handle<QuantExt::PriceTermStructure>& priceCurve,
70 const Handle<Quote>& fxSpotToday, const Real sigma, const Real kappa,
71 bool driftFreeState = false);
72
73 Size numberOfParameters() const override { return 2; }
74 //! State variable variance on [0, t]
75 Real variance(const Time t) const;
76 //! State variable Y's diffusion at time t: sigma * exp(kappa * t)
77 Real sigma(const Time t) const;
78 //! Inspector for the current value of model parameter sigma (direct)
79 Real sigmaParameter() const;
80 //! Inspector for the current value of model parameter kappa (direct)
81 Real kappaParameter() const;
82 //! Inspector for current value of the model parameter vector (inverse values)
83 const QuantLib::ext::shared_ptr<Parameter> parameter(const Size) const override;
84 //! Inspector for today's price curve
85 Handle<QuantExt::PriceTermStructure> priceCurve() { return priceCurve_; }
86 //! Variance V(t,T) used in the computation of F(t,T)
87 Real VtT(Real t, Real T);
88
89 bool driftFreeState() const { return driftFreeState_; }
90
91protected:
92 Real direct(const Size i, const Real x) const override;
93 Real inverse(const Size i, const Real y) const override;
94
95private:
96
97 const Handle<QuantExt::PriceTermStructure> priceCurve_;
98 const Handle<Quote> fxSpotToday_;
99 std::string comName_;
100 const QuantLib::ext::shared_ptr<PseudoParameter> sigma_;
101 const QuantLib::ext::shared_ptr<PseudoParameter> kappa_;
103};
104
105// inline
106
107inline Real CommoditySchwartzParametrization::direct(const Size, const Real x) const { return x * x; }
108
109inline Real CommoditySchwartzParametrization::inverse(const Size, const Real y) const { return std::sqrt(y); }
110
111inline Real CommoditySchwartzParametrization::variance(const Time t) const {
112 Real sig = direct(0, sigma_->params()[0]);
113 Real kap = direct(0, kappa_->params()[0]);
114 if (kap < QL_EPSILON)
115 return sig * sig * t;
116 else if (driftFreeState_)
117 return sig * sig * (std::exp(2.0 * kap * t) - 1.0) / (2.0 * kap);
118 else
119 return sig * sig * (1.0 - std::exp(-2.0 * kap * t)) / (2.0 * kap);
120}
121
122inline Real CommoditySchwartzParametrization::sigma(const Time u) const {
123 Real sig = direct(0, sigma_->params()[0]);
124 Real kap = direct(0, kappa_->params()[0]);
125 if (driftFreeState_)
126 return sig * std::exp(kap * u);
127 else
128 return sig;
129}
130
132 return direct(0, sigma_->params()[0]);
133}
134
136 return direct(0, kappa_->params()[0]);
137}
138
139inline const QuantLib::ext::shared_ptr<Parameter> CommoditySchwartzParametrization::parameter(const Size i) const {
140 QL_REQUIRE(i < 2, "parameter " << i << " does not exist, only have 0 and 1");
141 if (i == 0)
142 return sigma_;
143 else
144 return kappa_;
145}
146
147} // namespace QuantExt
148
149#endif
Real inverse(const Size i, const Real y) const override
Real VtT(Real t, Real T)
Variance V(t,T) used in the computation of F(t,T)
Real variance(const Time t) const
State variable variance on [0, t].
Handle< QuantExt::PriceTermStructure > priceCurve()
Inspector for today's price curve.
const Handle< QuantExt::PriceTermStructure > priceCurve_
Real direct(const Size i, const Real x) const override
const QuantLib::ext::shared_ptr< PseudoParameter > sigma_
Real sigmaParameter() const
Inspector for the current value of model parameter sigma (direct)
Real kappaParameter() const
Inspector for the current value of model parameter kappa (direct)
const QuantLib::ext::shared_ptr< PseudoParameter > kappa_
const QuantLib::ext::shared_ptr< Parameter > parameter(const Size) const override
Inspector for current value of the model parameter vector (inverse values)
Real sigma(const Time t) const
State variable Y's diffusion at time t: sigma * exp(kappa * t)
const std::string & name() const
virtual const Currency & currency() const
base class for model parametrizations
Term structure of prices.