Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
datedstrippedoptionletadapter.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 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
21
22#include <ql/math/interpolations/linearinterpolation.hpp>
23#include <ql/termstructures/volatility/interpolatedsmilesection.hpp>
24
25#include <algorithm>
26#include <boost/make_shared.hpp>
27
28using std::max;
29using std::min;
30
31namespace QuantExt {
32
33DatedStrippedOptionletAdapter::DatedStrippedOptionletAdapter(const QuantLib::ext::shared_ptr<DatedStrippedOptionletBase>& s,
34 const bool flatExtrapolation)
35 : OptionletVolatilityStructure(s->referenceDate(), s->calendar(), s->businessDayConvention(), s->dayCounter()),
36 optionletStripper_(s), nInterpolations_(s->optionletMaturities()), strikeInterpolations_(nInterpolations_),
37 flatExtrapolation_(flatExtrapolation) {
38 registerWith(optionletStripper_);
39}
40
41QuantLib::ext::shared_ptr<SmileSection> DatedStrippedOptionletAdapter::smileSectionImpl(Time t) const {
42
43 // Arbitrarily choose the first row of strikes for the smile section independent variable
44 // Generally a reasonable choice since:
45 // 1) OptionletStripper1: all strike rows are the same
46 // 2) OptionletStripper2: optionletStrikes(i) is a decreasing sequence
47 // Still possibility of arbitrary externally provided strike rows where (0) does not include all
48 vector<Rate> optionletStrikes = optionletStripper_->optionletStrikes(0);
49 vector<Real> stdDevs(optionletStrikes.size());
50 Real tEff = flatExtrapolation_ ? std::min(t, optionletStripper_->optionletFixingTimes().back()) : t;
51 for (Size i = 0; i < optionletStrikes.size(); ++i) {
52 stdDevs[i] = volatilityImpl(tEff, optionletStrikes[i]) * sqrt(tEff);
53 }
54
55 // Use a linear interpolated smile section.
56 // TODO: possibly make this configurable?
58 return QuantLib::ext::make_shared<InterpolatedSmileSection<LinearFlat> >(t, optionletStrikes, stdDevs, Null<Real>(),
59 LinearFlat(), Actual365Fixed(),
61 else
62 return QuantLib::ext::make_shared<InterpolatedSmileSection<Linear> >(
63 t, optionletStrikes, stdDevs, Null<Real>(), Linear(), Actual365Fixed(), volatilityType(), displacement());
64}
65
66Volatility DatedStrippedOptionletAdapter::volatilityImpl(Time length, Rate strike) const {
67 calculate();
68
69 vector<Volatility> vol(nInterpolations_);
70 for (Size i = 0; i < nInterpolations_; ++i)
71 vol[i] = strikeInterpolations_[i]->operator()(strike, true);
72
73 const vector<Time>& optionletTimes = optionletStripper_->optionletFixingTimes();
74 QuantLib::ext::shared_ptr<LinearInterpolation> timeInterpolator =
75 QuantLib::ext::make_shared<LinearInterpolation>(optionletTimes.begin(), optionletTimes.end(), vol.begin());
76 Real lengthEff = flatExtrapolation_ ? std::max(std::min(length, optionletStripper_->optionletFixingTimes().back()),
77 optionletStripper_->optionletFixingTimes().front())
78 : length;
79 return timeInterpolator->operator()(lengthEff, true);
80}
81
83 for (Size i = 0; i < nInterpolations_; ++i) {
84 const vector<Rate>& optionletStrikes = optionletStripper_->optionletStrikes(i);
85 const vector<Volatility>& optionletVolatilities = optionletStripper_->optionletVolatilities(i);
86 QuantLib::ext::shared_ptr<Interpolation> tmp = QuantLib::ext::make_shared<LinearInterpolation>(
87 optionletStrikes.begin(), optionletStrikes.end(), optionletVolatilities.begin());
89 strikeInterpolations_[i] = QuantLib::ext::make_shared<FlatExtrapolation>(tmp);
90 else
91 strikeInterpolations_[i] = tmp;
92 }
93}
94
96 Rate minStrike = optionletStripper_->optionletStrikes(0).front();
97 for (Size i = 1; i < nInterpolations_; ++i) {
98 minStrike = min(optionletStripper_->optionletStrikes(i).front(), minStrike);
99 }
100 return minStrike;
101}
102
104 Rate maxStrike = optionletStripper_->optionletStrikes(0).back();
105 for (Size i = 1; i < nInterpolations_; ++i) {
106 maxStrike = max(optionletStripper_->optionletStrikes(i).back(), maxStrike);
107 }
108 return maxStrike;
109}
110
111Date DatedStrippedOptionletAdapter::maxDate() const { return optionletStripper_->optionletFixingDates().back(); }
112
113VolatilityType DatedStrippedOptionletAdapter::volatilityType() const { return optionletStripper_->volatilityType(); }
114
116} // namespace QuantExt
const QuantLib::ext::shared_ptr< DatedStrippedOptionletBase > optionletStripper_
Volatility volatilityImpl(Time length, Rate strike) const override
vector< QuantLib::ext::shared_ptr< Interpolation > > strikeInterpolations_
QuantLib::ext::shared_ptr< SmileSection > smileSectionImpl(Time optionTime) const override
DatedStrippedOptionletAdapter(const QuantLib::ext::shared_ptr< DatedStrippedOptionletBase > &s, const bool flatExtrapolation)
Linear-interpolation and flat extrapolation factory and traits
StrippedOptionlet Adapter.
flat interpolation decorator
RandomVariable sqrt(RandomVariable x)
CompiledFormula min(CompiledFormula x, const CompiledFormula &y)
CompiledFormula max(CompiledFormula x, const CompiledFormula &y)