Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
spreadedbasecorrelationcurve.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
20
22
23namespace QuantExt {
24using namespace QuantLib;
25
26SpreadedBaseCorrelationCurve::SpreadedBaseCorrelationCurve(const Handle<BaseCorrelationTermStructure>& baseCurve,
27 const std::vector<Period>& tenors,
28 const std::vector<double>& detachmentPoints,
29 const std::vector<std::vector<Handle<Quote>>>& corrSpreads,
30 const Date& startDate,
31 boost::optional<DateGeneration::Rule> rule)
32 : BaseCorrelationTermStructure(baseCurve->settlementDays(), baseCurve->calendar(),
33 baseCurve->businessDayConvention(), tenors, detachmentPoints,
34 baseCurve->dayCounter(), startDate, rule),
35 baseCurve_(baseCurve), corrSpreads_(corrSpreads), data_(detachmentPoints_.size(), tenors.size(), 0.0) {
36 // Check times and detachment points
37
38 QL_REQUIRE(!times_.empty(), "SpreadedCorrelationCurve: time points are empty");
39 QL_REQUIRE(!detachmentPoints_.empty(), "SpreadedBaseCorrelationCurve: detachmentPoints are empty");
40
41 QL_REQUIRE(corrSpreads_.size() == detachmentPoints_.size(), "Mismatch between tenors and correlation quotes");
42 for (const auto& row : this->corrSpreads_) {
43 QL_REQUIRE(row.size() == tenors_.size(), "Mismatch between number of detachment points and quotes");
44 }
45
46 for (auto const& row : corrSpreads_)
47 for (auto const& q : row)
48 registerWith(q);
49
52 interpolation_.enableExtrapolation();
53 registerWith(baseCurve_);
54}
55
57 LazyObject::update();
58 BaseCorrelationTermStructure::update();
59}
60
61Real SpreadedBaseCorrelationCurve::correlationImpl(Time t, Real detachmentPoint) const {
62 calculate();
63 return std::min(
64 1.0 - QL_EPSILON,
65 std::max(baseCurve_->correlation(t, detachmentPoint) + interpolation_(t, detachmentPoint), QL_EPSILON));
66}
67
69 for (Size i = 0; i < this->detachmentPoints_.size(); ++i)
70 for (Size j = 0; j < this->times_.size(); ++j)
71 this->data_[i][j] = corrSpreads_[i][j]->value();
72 interpolation_.update();
73}
74
75} // namespace QuantExt
BiLinear-interpolation and flat extrapolation factory
Interpolation2D interpolate(const I1 &xBegin, const I1 &xEnd, const I2 &yBegin, const I2 &yEnd, const M &z) const
Real correlationImpl(Time t, Real strike) const override
Correlation calculation.
SpreadedBaseCorrelationCurve(const Handle< BaseCorrelationTermStructure > &baseCurve, const std::vector< Period > &tenors, const std::vector< double > &detachmentPoints, const std::vector< std::vector< Handle< Quote > > > &corrSpreads, const Date &startDate=Date(), boost::optional< DateGeneration::Rule > rule=boost::none)
std::vector< std::vector< Handle< Quote > > > corrSpreads_
Handle< BaseCorrelationTermStructure > baseCurve_