Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
commodityschwartzmodel.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
21
22namespace QuantExt {
23
24CommoditySchwartzModel::CommoditySchwartzModel(const QuantLib::ext::shared_ptr<CommoditySchwartzParametrization>& parametrization,
25 const Discretization discretization)
26 : parametrization_(parametrization), discretization_(discretization) {
27 QL_REQUIRE(parametrization_ != nullptr, "CommoditySchwartzModel: parametrization is null");
28 arguments_.resize(2);
29 arguments_[0] = parametrization_->parameter(0);
30 arguments_[1] = parametrization_->parameter(1);
31 stateProcess_ = QuantLib::ext::make_shared<CommoditySchwartzStateProcess>(parametrization_, discretization_);
32}
33
34QuantLib::Real CommoditySchwartzModel::forwardPrice(const QuantLib::Time t, const QuantLib::Time T, const QuantLib::Array& state,
35 const QuantLib::Handle<QuantExt::PriceTermStructure>& priceCurve) const {
36 QL_REQUIRE(T >= t && t >= 0.0, "T(" << T << ") >= t(" << t << ") >= 0 required in CommoditySchwartzModel::forwardPrice");
37 Real f0T = priceCurve.empty() ? parametrization_->priceCurve()->price(T) : priceCurve->price(T);
38 Real VtT = parametrization_->VtT(t, T);
39 Real V0T = parametrization_->VtT(0, T);
40 Real k = parametrization_->kappaParameter();
41 if (parametrization_->driftFreeState())
42 return f0T * std::exp(-state[0] * std::exp(-k*T) - 0.5 * (V0T - VtT));
43 else
44 return f0T * std::exp(-state[0] * std::exp(-k*(T-t)) - 0.5 * (V0T - VtT));
45}
46
48 parametrization_->update();
49 notifyObservers();
50}
51
53
54} // namespace QuantExt
QuantLib::ext::shared_ptr< CommoditySchwartzParametrization > parametrization_
void update() override
observer and linked calibrated model interface
QuantLib::ext::shared_ptr< StochasticProcess > stateProcess_
QuantLib::Real forwardPrice(const QuantLib::Time t, const QuantLib::Time T, const QuantLib::Array &x, const QuantLib::Handle< QuantExt::PriceTermStructure > &priceCurve=QuantLib::Handle< QuantExt::PriceTermStructure >()) const override
CommoditySchwartzModel(const QuantLib::ext::shared_ptr< CommoditySchwartzParametrization > &parametrization, const Discretization discretization=Discretization::Euler)
std::vector< QuantLib::ext::shared_ptr< Parameter > > arguments_
Schwartz (1997) one-factor model of the commodity price termstructure.
COM state process for the one-factor Schwartz model.