Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
spreadedcpivolatilitysurface.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
21#include <ql/math/interpolations/bilinearinterpolation.hpp>
22#include <ql/math/interpolations/flatextrapolation2d.hpp>
23#include <ql/termstructures/inflationtermstructure.hpp>
25
26namespace QuantExt {
27
28SpreadedCPIVolatilitySurface::SpreadedCPIVolatilitySurface(const Handle<QuantExt::CPIVolatilitySurface>& baseVol,
29 const std::vector<Date>& optionDates,
30 const std::vector<Real>& strikes,
31 const std::vector<std::vector<Handle<Quote>>>& volSpreads)
32 : QuantExt::CPIVolatilitySurface(baseVol->settlementDays(), baseVol->calendar(), baseVol->businessDayConvention(),
33 baseVol->dayCounter(), baseVol->observationLag(), baseVol->frequency(),
34 baseVol->indexIsInterpolated(), baseVol->capFloorStartDate(),
35 baseVol->volatilityType(), baseVol->displacement()),
36 baseVol_(baseVol), optionDates_(optionDates), strikes_(strikes), volSpreads_(volSpreads) {
37 registerWith(baseVol_);
38 optionTimes_.resize(optionDates_.size());
39 volSpreadValues_ = Matrix(strikes_.size(), optionDates_.size());
40 for (auto const& v : volSpreads)
41 for (auto const& q : v)
42 registerWith(q);
43}
44
45Date SpreadedCPIVolatilitySurface::maxDate() const { return baseVol_->maxDate(); }
46Time SpreadedCPIVolatilitySurface::maxTime() const { return baseVol_->maxTime(); }
47const Date& SpreadedCPIVolatilitySurface::referenceDate() const { return baseVol_->referenceDate(); }
48Rate SpreadedCPIVolatilitySurface::minStrike() const { return baseVol_->minStrike(); }
49Rate SpreadedCPIVolatilitySurface::maxStrike() const { return baseVol_->maxStrike(); }
50
51Volatility SpreadedCPIVolatilitySurface::volatilityImpl(Time length, Rate strike) const {
52 calculate();
53 return baseVol_->volatility(length, strike) + volSpreadInterpolation_(length, strike);
54}
55
57 for (Size i = 0; i < optionDates_.size(); ++i) {
59 }
60 for (Size k = 0; k < strikes_.size(); ++k) {
61 for (Size i = 0; i < optionDates_.size(); ++i) {
62 volSpreadValues_(k, i) = volSpreads_[i][k]->value();
63 }
64 }
65 volSpreadInterpolation_ = FlatExtrapolator2D(QuantLib::ext::make_shared<BilinearInterpolation>(
66 optionTimes_.begin(), optionTimes_.end(), strikes_.begin(), strikes_.end(), volSpreadValues_));
67 volSpreadInterpolation_.enableExtrapolation();
68}
69
71 CPIVolatilitySurface::update();
72 LazyObject::update();
73}
74
76 baseVol_->update();
77 update();
78}
79
80QuantLib::Real SpreadedCPIVolatilitySurface::atmStrike(const QuantLib::Date& maturity,
81 const QuantLib::Period& obsLag) const {
82 // Not relevant for constantCPIVolatiltiy;
83 return baseVol_->atmStrike(maturity, obsLag);
84};
85
86} // namespace QuantExt
virtual double fixingTime(const QuantLib::Date &maturityDate) const
Computes the expiry time from the capFloorStartDate()
Handle< QuantExt::CPIVolatilitySurface > baseVol_
SpreadedCPIVolatilitySurface(const Handle< QuantExt::CPIVolatilitySurface > &baseVol, const std::vector< Date > &optionDates, const std::vector< Real > &strikes, const std::vector< std::vector< Handle< Quote > > > &volSpreads)
Volatility volatilityImpl(Time length, Rate strike) const override
std::vector< std::vector< Handle< Quote > > > volSpreads_
QuantLib::Real atmStrike(const QuantLib::Date &maturity, const QuantLib::Period &obsLag=QuantLib::Period(-1, QuantLib::Days)) const override
some inflation related utilities.
vector< Real > strikes