Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
strippedyoyinflationoptionletvol.cpp
Go to the documentation of this file.
1/*
2Copyright (C) 2019 Quaternion Risk Management Ltd
3All rights reserved.
4
5This file is part of ORE, a free-software/open-source library
6for transparent pricing and risk analysis - http://opensourcerisk.org
7
8ORE is free software: you can redistribute it and/or modify it
9under the terms of the Modified BSD License. You should have received a
10copy of the license along with this program.
11The license is also available online at <http://opensourcerisk.org>
12
13This program is distributed on the basis that it will form a useful
14contribution to risk analytics and model standardisation, but WITHOUT
15ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
21
22#include <ql/math/interpolations/cubicinterpolation.hpp>
23#include <ql/math/interpolations/linearinterpolation.hpp>
24#include <ql/math/interpolations/sabrinterpolation.hpp>
25#include <ql/termstructures/volatility/interpolatedsmilesection.hpp>
26
27using namespace QuantLib;
28using std::vector;
29
30namespace QuantExt {
31
33 Natural settlementDays, const Calendar& calendar, BusinessDayConvention bdc, const DayCounter& dc,
34 const Period& observationLag, Frequency frequency, bool indexIsInterpolated,
35 const std::vector<Date>& yoyoptionletDates, const std::vector<Rate>& strikes,
36 const std::vector<std::vector<Handle<Quote> > >& v, VolatilityType type, Real displacement)
37 : YoYOptionletVolatilitySurface(settlementDays, calendar, bdc, dc, observationLag, frequency, indexIsInterpolated),
38 calendar_(calendar), settlementDays_(settlementDays), businessDayConvention_(bdc), dc_(dc), type_(type),
39 displacement_(displacement), nYoYOptionletDates_(yoyoptionletDates.size()), yoyoptionletDates_(yoyoptionletDates),
40 yoyoptionletTimes_(nYoYOptionletDates_), yoyoptionletStrikes_(nYoYOptionletDates_, strikes),
41 nStrikes_(strikes.size()), yoyoptionletVolQuotes_(v),
42 yoyoptionletVolatilities_(nYoYOptionletDates_, vector<Volatility>(nStrikes_)) {
43
45 registerWith(Settings::instance().evaluationDate());
47
48 for (Size i = 0; i < nYoYOptionletDates_; ++i)
49 yoyoptionletTimes_[i] = dc_.yearFraction(Settings::instance().evaluationDate(), yoyoptionletDates_[i]);
50}
51
53 if (type_ == Normal) {
54 QL_REQUIRE(displacement_ == 0.0, "non-null displacement is not allowed with Normal model");
55 }
56
57 QL_REQUIRE(!yoyoptionletDates_.empty(), "empty yoy optionlet tenor vector");
58 QL_REQUIRE(nYoYOptionletDates_ == yoyoptionletVolQuotes_.size(), "mismatch between number of option tenors ("
60 << ") and number of volatility rows ("
61 << yoyoptionletVolQuotes_.size() << ")");
62 QL_REQUIRE(yoyoptionletDates_[0] > Settings::instance().evaluationDate(),
63 "first option date (" << yoyoptionletDates_[0] << ") is in the past");
64 for (Size i = 1; i < nYoYOptionletDates_; ++i)
65 QL_REQUIRE(yoyoptionletDates_[i] > yoyoptionletDates_[i - 1],
66 "non increasing option dates: " << io::ordinal(i) << " is " << yoyoptionletDates_[i - 1] << ", "
67 << io::ordinal(i + 1) << " is " << yoyoptionletDates_[i]);
68
69 QL_REQUIRE(nStrikes_ == yoyoptionletVolQuotes_[0].size(),
70 "mismatch between strikes(" << yoyoptionletStrikes_[0].size() << ") and vol columns ("
71 << yoyoptionletVolQuotes_[0].size() << ")");
72 for (Size j = 1; j < nStrikes_; ++j)
73 QL_REQUIRE(yoyoptionletStrikes_[0][j - 1] < yoyoptionletStrikes_[0][j],
74 "non increasing strikes: " << io::ordinal(j) << " is " << io::rate(yoyoptionletStrikes_[0][j - 1])
75 << ", " << io::ordinal(j + 1) << " is "
76 << io::rate(yoyoptionletStrikes_[0][j]));
77}
78
80 for (Size i = 0; i < nYoYOptionletDates_; ++i)
81 for (Size j = 0; j < nStrikes_; ++j)
82 registerWith(yoyoptionletVolQuotes_[i][j]);
83}
84
85Volatility StrippedYoYInflationOptionletVol::volatilityImpl(Time length, Rate strike) const {
86 calculate();
87
88 std::vector<Volatility> vol(nYoYOptionletDates_);
89 for (Size i = 0; i < nYoYOptionletDates_; ++i) {
91 const std::vector<Volatility>& yoyoptionletVolatilities =
93 QuantLib::ext::shared_ptr<LinearInterpolation> tmp(new LinearInterpolation(
95 vol[i] = tmp->operator()(strike, true);
96 }
97
98 const std::vector<Time>& yoyoptionletTimes = yoyoptionletFixingTimes();
99 QuantLib::ext::shared_ptr<LinearInterpolation> timeVolInterpolator(
100 new LinearInterpolation(yoyoptionletTimes.begin(), yoyoptionletTimes.end(), vol.begin()));
101 return timeVolInterpolator->operator()(length, true);
102}
103
105 for (Size i = 0; i < nYoYOptionletDates_; ++i)
106 for (Size j = 0; j < nStrikes_; ++j)
108}
109
111
113
115
117 QL_REQUIRE(i < yoyoptionletStrikes_.size(), "index (" << i << ") must be less than yoyoptionletStrikes size ("
118 << yoyoptionletStrikes_.size() << ")");
119 return yoyoptionletStrikes_[i];
120}
121
122const vector<Volatility>& StrippedYoYInflationOptionletVol::yoyoptionletVolatilities(Size i) const {
123 QL_REQUIRE(i < yoyoptionletVolatilities_.size(), "index (" << i
124 << ") must be less than yoyoptionletVolatilities size ("
125 << yoyoptionletVolatilities_.size() << ")");
127}
128
130
132
134
136
138
140
142
144
145} // namespace QuantExt
QuantLib::Volatility volatilityImpl(Time length, QuantLib::Rate strike) const override
const std::vector< Volatility > & yoyoptionletVolatilities(Size i) const
QuantLib::VolatilityType volatilityType() const override
const std::vector< Rate > & yoyoptionletStrikes(Size i) const
BusinessDayConvention businessDayConvention() const override
std::vector< std::vector< Volatility > > yoyoptionletVolatilities_
std::vector< std::vector< Handle< Quote > > > yoyoptionletVolQuotes_
StrippedYoYInflationOptionletVol(Natural settlementDays, const Calendar &calendar, BusinessDayConvention bdc, const DayCounter &dc, const Period &observationLag, Frequency frequency, bool indexIsInterpolated, const std::vector< Date > &yoyoptionletDates, const std::vector< Rate > &strikes, const std::vector< std::vector< Handle< Quote > > > &, VolatilityType type=ShiftedLognormal, Real displacement=0.0)
flat interpolation decorator
Stripped YoYInfaltion Optionlet Vol Adapter (with a deeper update method, linear interpolation and op...
vector< Real > strikes