Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
spreadedcorrelationcurve.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
26SpreadedCorrelationCurve::SpreadedCorrelationCurve(const Handle<CorrelationTermStructure>& referenceCorrelation,
27 const std::vector<Time>& times,
28 const std::vector<Handle<Quote>>& corrSpreads,
29 const bool useAtmReferenceCorrsOnly)
30 : CorrelationTermStructure(referenceCorrelation->dayCounter()), referenceCorrelation_(referenceCorrelation),
31 times_(times), corrSpreads_(corrSpreads), useAtmReferenceCorrsOnly_(useAtmReferenceCorrsOnly) {
32 QL_REQUIRE(!times_.empty(), "SpreadedCorrelationCurve: times are empty");
33 QL_REQUIRE(times_.size() == corrSpreads_.size(),
34 "SpreadedCorrelationCurve: size of times and quote vectors do not match");
35 if (times.size() == 1) {
36 times_.push_back(times_.back() + 1.0);
37 corrSpreads_.push_back(corrSpreads_.back());
38 }
39 data_.resize(times_.size(), 1.0);
40 for (auto const& q : corrSpreads_)
41 registerWith(q);
42 interpolation_ = QuantLib::ext::make_shared<FlatExtrapolation>(
43 QuantLib::ext::make_shared<LinearInterpolation>(times_.begin(), times_.end(), data_.begin()));
44 interpolation_->enableExtrapolation();
45 registerWith(referenceCorrelation_);
46}
47
49const Date& SpreadedCorrelationCurve::referenceDate() const { return referenceCorrelation_->referenceDate(); }
50Calendar SpreadedCorrelationCurve::calendar() const { return referenceCorrelation_->calendar(); }
51Natural SpreadedCorrelationCurve::settlementDays() const { return referenceCorrelation_->settlementDays(); }
53
55 LazyObject::update();
56 CorrelationTermStructure::update();
57}
58
59Real SpreadedCorrelationCurve::correlationImpl(Time t, Real strike) const {
60 calculate();
61 return referenceCorrelation_->correlation(t, useAtmReferenceCorrsOnly_ ? Null<Real>() : strike) +
62 (*interpolation_)(t);
63}
64
66 for (Size i = 0; i < times_.size(); ++i) {
67 QL_REQUIRE(!corrSpreads_[i].empty(), "SpreadedCorrelationCurve: quote at index " << i << " is empty");
68 data_[i] = corrSpreads_[i]->value();
69 }
70 interpolation_->update();
71}
72
73} // namespace QuantExt
Real correlationImpl(Time t, Real strike) const override
Correlation calculation.
Time minTime() const override
The minimum time for which the curve can return values.
const Date & referenceDate() const override
QuantLib::ext::shared_ptr< Interpolation > interpolation_
SpreadedCorrelationCurve(const Handle< CorrelationTermStructure > &referenceCorrelation, const std::vector< Time > &times, const std::vector< Handle< Quote > > &corrSpreads, const bool useAtmReferenceVolsOnly=false)
Handle< CorrelationTermStructure > referenceCorrelation_
std::vector< Handle< Quote > > corrSpreads_
flat interpolation decorator
Spreaded correlation curve.