Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
blackscholesmodelbuilder.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2020 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 ore {
23namespace data {
24
26 const std::vector<Handle<YieldTermStructure>>& curves,
27 const std::vector<QuantLib::ext::shared_ptr<GeneralizedBlackScholesProcess>>& processes,
28 const std::set<Date>& simulationDates, const std::set<Date>& addDates, const Size timeStepsPerYear,
29 const std::string& calibration, const std::vector<std::vector<Real>>& calibrationStrikes)
30 : BlackScholesModelBuilderBase(curves, processes, simulationDates, addDates, timeStepsPerYear),
31 calibration_(calibration),
32 calibrationStrikes_(calibrationStrikes.empty() ? std::vector<std::vector<Real>>(processes.size())
33 : calibrationStrikes) {
34 QL_REQUIRE(calibrationStrikes_.size() == processes.size(),
35 "calibrationStrikes size (" << calibrationStrikes_.size() << ") must match processes size ("
36 << processes.size() << ")");
37}
38
39BlackScholesModelBuilder::BlackScholesModelBuilder(const Handle<YieldTermStructure>& curve,
40 const QuantLib::ext::shared_ptr<GeneralizedBlackScholesProcess>& process,
41 const std::set<Date>& simulationDates,
42 const std::set<Date>& addDates, const Size timeStepsPerYear,
43 const std::string& calibration,
44 const std::vector<Real>& calibrationStrikes)
45 : BlackScholesModelBuilderBase(curve, process, simulationDates, addDates, timeStepsPerYear),
46 calibration_(calibration), calibrationStrikes_(1, calibrationStrikes) {}
47
48std::vector<QuantLib::ext::shared_ptr<GeneralizedBlackScholesProcess>>
50 // nothing to do, return original processes
51 return processes_;
52}
53
54std::vector<std::vector<Real>> BlackScholesModelBuilder::getCurveTimes() const {
55 std::vector<Real> timesExt(discretisationTimeGrid_.begin() + 1, discretisationTimeGrid_.end());
56 for (auto const& d : addDates_) {
57 if (d > curves_.front()->referenceDate()) {
58 timesExt.push_back(curves_.front()->timeFromReference(d));
59 }
60 }
61 std::sort(timesExt.begin(), timesExt.end());
62 auto it = std::unique(timesExt.begin(), timesExt.end(),
63 [](const Real x, const Real y) { return QuantLib::close_enough(x, y); });
64 timesExt.resize(std::distance(timesExt.begin(), it));
65 return std::vector<std::vector<Real>>(allCurves_.size(), timesExt);
66}
67
68std::vector<std::vector<std::pair<Real, Real>>> BlackScholesModelBuilder::getVolTimesStrikes() const {
69 std::vector<std::vector<std::pair<Real, Real>>> volTimesStrikes;
70 for (Size i = 0; i < processes_.size(); ++i) {
71 Real strike;
72 if (calibration_ == "ATM") {
73 strike = Null<Real>();
74 } else if (calibration_ == "Deal") {
75 strike = calibrationStrikes_[i].empty() ? Null<Real>() : calibrationStrikes_[i][0];
76 } else {
77 QL_FAIL("BlackScholesModelBuilder: calibration '" << calibration_ << "' not known, expected ATM or Deal");
78 }
79 volTimesStrikes.push_back(std::vector<std::pair<Real, Real>>());
80 for (Size j = 1; j < discretisationTimeGrid_.size(); ++j) {
81 volTimesStrikes.back().push_back(std::make_pair(discretisationTimeGrid_[j], strike));
82 }
83 }
84 return volTimesStrikes;
85}
86
87} // namespace data
88} // namespace ore
const std::vector< Real > calibrationStrikes_
builder for an array of black scholes processes
std::vector< Handle< YieldTermStructure > > allCurves_
const std::vector< QuantLib::ext::shared_ptr< GeneralizedBlackScholesProcess > > processes_
const std::vector< Handle< YieldTermStructure > > curves_
const std::vector< std::vector< Real > > calibrationStrikes_
std::vector< QuantLib::ext::shared_ptr< GeneralizedBlackScholesProcess > > getCalibratedProcesses() const override
std::vector< std::vector< std::pair< Real, Real > > > getVolTimesStrikes() const override
std::vector< std::vector< Real > > getCurveTimes() const override
BlackScholesModelBuilder(const std::vector< Handle< YieldTermStructure > > &curves, const std::vector< QuantLib::ext::shared_ptr< GeneralizedBlackScholesProcess > > &processes, const std::set< Date > &simulationDates, const std::set< Date > &addDates, const Size timeStepsPerYear=0, const std::string &calibration="ATM", const std::vector< std::vector< Real > > &calibrationStrikes={})
@ data
Definition: log.hpp:77
Shared utilities for model building and calibration.
Size size(const ValueType &v)
Definition: value.cpp:145
Serializable Credit Default Swap.
Definition: namespaces.docs:23