Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
commodityschwartzstateprocess.cpp
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
20
21#include <ql/processes/eulerdiscretization.hpp>
22
23namespace QuantExt {
24
26 const QuantLib::ext::shared_ptr<CommoditySchwartzParametrization>& parametrization,
27 const CommoditySchwartzModel::Discretization discretization)
28 : StochasticProcess1D(discretization == CommoditySchwartzModel::Discretization::Euler
29 ? QuantLib::ext::make_shared<EulerDiscretization>()
30 : QuantLib::ext::static_pointer_cast<StochasticProcess1D::discretization>(
31 QuantLib::ext::make_shared<ExactDiscretization>(parametrization))),
32 p_(parametrization) {}
33
34Real CommoditySchwartzStateProcess::drift(Time t, Real x0) const {
35 if (p_->driftFreeState())
36 return 0.0;
37 else
38 return -x0 * p_->kappaParameter();
39}
40
41Real CommoditySchwartzStateProcess::diffusion(Time t, Real) const { return p_->sigma(t); }
42
44 Time dt) const {
45 if (p_->driftFreeState())
46 return 0.0;
47 else {
48 // Ornstein-Uhlenbeck expectation
49 return x0 * (exp(-p_->kappaParameter() * dt) - 1.0);
50 }
51}
52
54 Time dt) const {
55 if (p_->driftFreeState())
56 return p_->variance(t0 + dt) - p_->variance(t0);
57 else {
58 // Ornstein-Uhlenbeck variance
59 Real kappa = p_->kappaParameter();
60 Real sigma = p_->sigmaParameter();
61 return sigma * sigma * (1.0 - std::exp(-2.0 * kappa * dt)) / (2.0 * kappa);
62 }
63}
64
66 Time dt) const {
67 return std::sqrt(variance(p, t0, x0, dt));
68}
69
70} // namespace QuantExt
Real drift(const StochasticProcess1D &p, Time t0, Real x0, Time dt) const override
const QuantLib::ext::shared_ptr< CommoditySchwartzParametrization > p_
Real diffusion(const StochasticProcess1D &p, Time t0, Real x0, Time dt) const override
Real variance(const StochasticProcess1D &p, Time t0, Real x0, Time dt) const override
const QuantLib::ext::shared_ptr< CommoditySchwartzParametrization > p_
CommoditySchwartzStateProcess(const QuantLib::ext::shared_ptr< CommoditySchwartzParametrization > &parametrization, const CommoditySchwartzModel::Discretization discretization)
COM state process for the one-factor Schwartz model.
RandomVariable variance(const RandomVariable &r)
CompiledFormula exp(CompiledFormula x)