Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
commodityschwartzmodelbuilder.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 ored/model/commodityschwartzmodelbuilder.hpp
20 \brief Builder for a Lognormal COM model component
21 \ingroup models
22*/
23
24#pragma once
25
26#include <map>
27#include <ostream>
28#include <vector>
29
34
36
37namespace ore {
38namespace data {
39using namespace QuantLib;
40
41//! Builder for a COM model component
42/*!
43 This class is a utility to turn a COM model component's description
44 into a COM model parametrization which can be used to ultimately
45 instantiate a CrossAssetModel.
46h
47 \ingroup models
48 */
50public:
51 //! Constructor
52 CommoditySchwartzModelBuilder( //! Market object
53 const QuantLib::ext::shared_ptr<ore::data::Market>& market,
54 //! EQ model parameters/description
55 const QuantLib::ext::shared_ptr<CommoditySchwartzData>& data,
56 //! base currency for calibration
57 const QuantLib::Currency& baseCcy,
58 //! Market configuration to use
59 const std::string& configuration = Market::defaultConfiguration,
60 //! the reference calibration grid
61 const std::string& referenceCalibrationGrid = "");
62
63 //! Return calibration error
64 Real error() const;
65
66 //! \name Inspectors
67 //@{
68 std::string name() { return data_->name(); }
69 QuantLib::ext::shared_ptr<QuantExt::CommoditySchwartzParametrization> parametrization() const;
70 QuantLib::ext::shared_ptr<QuantExt::CommoditySchwartzModel> model() const;
71 std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>> optionBasket() const;
72 //@}
73
74 //! \name ModelBuilder interface
75 //@{
76 void forceRecalculate() override;
77 bool requiresRecalibration() const override;
78 //@}
79
80private:
81 void performCalculations() const override;
82 Real optionStrike(const Size j) const;
83 Date optionExpiry(const Size j) const;
84 void buildOptionBasket() const;
85 // checks whether vols have changed compared to cache and updates the cache if requested
86 bool volSurfaceChanged(const bool updateCache) const;
87
88 // input data
89 const QuantLib::ext::shared_ptr<ore::data::Market> market_;
90 const std::string configuration_;
91 const QuantLib::ext::shared_ptr<CommoditySchwartzData> data_;
92 const std::string referenceCalibrationGrid_;
93 const QuantLib::Currency baseCcy_;
94
95 // computed
96 mutable Real error_;
97 mutable QuantLib::ext::shared_ptr<QuantExt::CommoditySchwartzParametrization> parametrization_;
98 mutable QuantLib::ext::shared_ptr<QuantExt::CommoditySchwartzModel> model_;
99
100 // which options in data->optionExpiries() are actually in the basket?
101 mutable std::vector<bool> optionActive_;
102 mutable std::vector<QuantLib::ext::shared_ptr<BlackCalibrationHelper>> optionBasket_;
103 mutable Array optionExpiries_;
104
105 // relevant market data
106 Handle<Quote> fxSpot_;
107 Handle<QuantExt::PriceTermStructure> curve_;
108 Handle<BlackVolTermStructure> vol_;
109
110 // Cache the volatilities
111 mutable std::vector<QuantLib::Real> volCache_;
112
113 // helper flag to process forRecalculate()
114 bool forceCalibration_ = false;
115
116 // market observer
117 QuantLib::ext::shared_ptr<QuantExt::MarketObserver> marketObserver_;
118
119 mutable std::vector<Real> calibrationErrors_;
120
121 mutable Array params_;
122};
123} // namespace data
124} // namespace ore
bool volSurfaceChanged(const bool updateCache) const
QuantLib::ext::shared_ptr< QuantExt::MarketObserver > marketObserver_
QuantLib::ext::shared_ptr< QuantExt::CommoditySchwartzModel > model_
std::vector< QuantLib::ext::shared_ptr< BlackCalibrationHelper > > optionBasket() const
std::vector< QuantLib::ext::shared_ptr< BlackCalibrationHelper > > optionBasket_
const QuantLib::ext::shared_ptr< ore::data::Market > market_
const QuantLib::ext::shared_ptr< CommoditySchwartzData > data_
Handle< QuantExt::PriceTermStructure > curve_
QuantLib::ext::shared_ptr< QuantExt::CommoditySchwartzParametrization > parametrization() const
QuantLib::ext::shared_ptr< QuantExt::CommoditySchwartzParametrization > parametrization_
QuantLib::ext::shared_ptr< QuantExt::CommoditySchwartzModel > model() const
static const string defaultConfiguration
Default configuration label.
Definition: market.hpp:296
COM component data for the cross asset model.
@ data
Definition: log.hpp:77
Base Market class.
Serializable Credit Default Swap.
Definition: namespaces.docs:23