Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
commodityapomodelbuilder.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/quotes/simplequote.hpp>
22#include <ql/termstructures/yield/flatforward.hpp>
23
24namespace ore {
25namespace data {
26
27CommodityApoModelBuilder::CommodityApoModelBuilder(const Handle<YieldTermStructure>& curve,
28 const QuantLib::Handle<QuantLib::BlackVolTermStructure>& vol,
29 const QuantLib::ext::shared_ptr<QuantExt::CommodityAveragePriceOption>& apo,
30 const bool dontCalibrate)
31 : BlackScholesModelBuilderBase(curve, QuantLib::ext::make_shared<GeneralizedBlackScholesProcess>(
32 Handle<Quote>(QuantLib::ext::make_shared<SimpleQuote>(1.0)),
33 Handle<YieldTermStructure>(QuantLib::ext::make_shared<QuantLib::FlatForward>(
34 0, NullCalendar(), 0.0, Actual365Fixed())),
35 Handle<YieldTermStructure>(QuantLib::ext::make_shared<QuantLib::FlatForward>(
36 0, NullCalendar(), 0.0, Actual365Fixed())),
37 vol)),
38 apo_(apo), dontCalibrate_(dontCalibrate) {}
39
41 // we don't need the simulation dates or timegrid and we populate the curve / vol times directly below
42 return;
43}
44
45std::vector<QuantLib::ext::shared_ptr<GeneralizedBlackScholesProcess>>
47 // nothing to do, return original processes
48 return processes_;
49}
50
51std::vector<std::vector<Real>> CommodityApoModelBuilder::getCurveTimes() const {
52 // collect times relevant on the discount curve
53 std::vector<Real> times;
55 return {times};
56 if (apo_->underlyingFlow()->date() > curves_.front()->referenceDate())
57 times.push_back(curves_.front()->timeFromReference(apo_->underlyingFlow()->date()));
58 return {times};
59}
60
61std::vector<std::vector<std::pair<Real, Real>>> CommodityApoModelBuilder::getVolTimesStrikes() const {
62 // collect times relevant on the vol surface
63 std::vector<std::pair<Real, Real>> result;
65 return {result};
66 auto vol = processes_.front()->blackVolatility();
67 std::set<QuantLib::Date> expiries;
68 Real effectiveStrike = apo_->effectiveStrike();
69 try {
70 effectiveStrike -= apo_->accrued(curves_.front()->referenceDate());
71 } catch (...) {
72 // The accrued calculation might fail due to missing fixings and this will cause an error in the
73 // instrument pricing. We don't throw an error here since the apo might actually be expired so
74 // that no pricing is required at all.
75 }
76 for (auto const& p : apo_->underlyingFlow()->indices()) {
77 if (p.first > curves_.front()->referenceDate()) {
78 if (apo_->underlyingFlow()->useFuturePrice()) {
79 Date expiry = p.second->expiryDate();
80 if (expiries.find(expiry) == expiries.end()) {
81 result.push_back(std::make_pair(vol->timeFromReference(expiry), effectiveStrike));
82 expiries.insert(expiry);
83 }
84 } else {
85 if (expiries.find(p.first) == expiries.end()) {
86 result.push_back(std::make_pair(vol->timeFromReference(p.first), effectiveStrike));
87 expiries.insert(p.first);
88 }
89 }
90 }
91 }
92 return {result};
93}
94
95} // namespace data
96} // namespace ore
const std::vector< QuantLib::ext::shared_ptr< GeneralizedBlackScholesProcess > > processes_
const std::vector< Handle< YieldTermStructure > > curves_
std::vector< QuantLib::ext::shared_ptr< GeneralizedBlackScholesProcess > > getCalibratedProcesses() const override
QuantLib::ext::shared_ptr< QuantExt::CommodityAveragePriceOption > apo_
std::vector< std::vector< std::pair< Real, Real > > > getVolTimesStrikes() const override
std::vector< std::vector< Real > > getCurveTimes() const override
CommodityApoModelBuilder(const Handle< YieldTermStructure > &curve, const QuantLib::Handle< QuantLib::BlackVolTermStructure > &vol, const QuantLib::ext::shared_ptr< QuantExt::CommodityAveragePriceOption > &apo, const bool dontCalibrate)
model builder for commodityapos
@ data
Definition: log.hpp:77
Serializable Credit Default Swap.
Definition: namespaces.docs:23