Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
spreadedyoyvolsurface.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>
24
25namespace QuantExt {
26
27SpreadedYoYVolatilitySurface::SpreadedYoYVolatilitySurface(const Handle<YoYOptionletVolatilitySurface>& baseVol,
28 const std::vector<Date>& optionDates,
29 const std::vector<Real>& strikes,
30 const std::vector<std::vector<Handle<Quote>>>& volSpreads)
31 : YoYOptionletVolatilitySurface(baseVol->settlementDays(), baseVol->calendar(), baseVol->businessDayConvention(),
32 baseVol->dayCounter(), baseVol->observationLag(), baseVol->frequency(),
33 baseVol->indexIsInterpolated(), baseVol->volatilityType(), baseVol->displacement()),
34 baseVol_(baseVol), optionDates_(optionDates), strikes_(strikes), volSpreads_(volSpreads) {
35 registerWith(baseVol_);
36 optionTimes_.resize(optionDates_.size());
37 volSpreadValues_ = Matrix(strikes_.size(), optionDates_.size());
38 for (auto const& v : volSpreads)
39 for (auto const& q : v)
40 registerWith(q);
41}
42
43Date SpreadedYoYVolatilitySurface::maxDate() const { return baseVol_->maxDate(); }
44Time SpreadedYoYVolatilitySurface::maxTime() const { return baseVol_->maxTime(); }
45const Date& SpreadedYoYVolatilitySurface::referenceDate() const { return baseVol_->referenceDate(); }
46Rate SpreadedYoYVolatilitySurface::minStrike() const { return baseVol_->minStrike(); }
47Rate SpreadedYoYVolatilitySurface::maxStrike() const { return baseVol_->maxStrike(); }
48
49Volatility SpreadedYoYVolatilitySurface::volatilityImpl(Time length, Rate strike) const {
50 calculate();
51 return baseVol_->volatility(length, strike) + volSpreadInterpolation_(length, strike);
52}
53
55 for (Size i = 0; i < optionDates_.size(); ++i) {
56 // we can not support a custom obsLag here
57 if (indexIsInterpolated())
58 optionTimes_[i] = timeFromReference(optionDates_[i] - observationLag());
59 else
60 optionTimes_[i] = timeFromReference(inflationPeriod(optionDates_[i] - observationLag(), frequency()).first);
61 }
62 for (Size k = 0; k < strikes_.size(); ++k) {
63 for (Size i = 0; i < optionDates_.size(); ++i) {
64 volSpreadValues_(k, i) = volSpreads_[i][k]->value();
65 }
66 }
67 volSpreadInterpolation_ = FlatExtrapolator2D(QuantLib::ext::make_shared<BilinearInterpolation>(
68 optionTimes_.begin(), optionTimes_.end(), strikes_.begin(), strikes_.end(), volSpreadValues_));
69 volSpreadInterpolation_.enableExtrapolation();
70}
71
73 YoYOptionletVolatilitySurface::update();
74 LazyObject::update();
75}
76
78 baseVol_->update();
79 update();
80}
81
82} // namespace QuantExt
Handle< YoYOptionletVolatilitySurface > baseVol_
const Date & referenceDate() const override
Volatility volatilityImpl(Time length, Rate strike) const override
std::vector< std::vector< Handle< Quote > > > volSpreads_
SpreadedYoYVolatilitySurface(const Handle< YoYOptionletVolatilitySurface > &baseVol, const std::vector< Date > &optionDates, const std::vector< Real > &strikes, const std::vector< std::vector< Handle< Quote > > > &volSpreads)
vector< Real > strikes