QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
strippedoptionletadapter.cpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2007 Giorgio Facchinetti
5 Copyright (C) 2007 Katiuscia Manzoni
6 Copyright (C) 2015 Peter Caspers
7
8 This file is part of QuantLib, a free-software/open-source library
9 for financial quantitative analysts and developers - http://quantlib.org/
10
11 QuantLib is free software: you can redistribute it and/or modify it
12 under the terms of the QuantLib license. You should have received a
13 copy of the license along with this program; if not, please email
14 <quantlib-dev@lists.sf.net>. The license is also available online at
15 <http://quantlib.org/license.shtml>.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the license for more details.
20*/
21
29
30namespace QuantLib {
31
33 const ext::shared_ptr<StrippedOptionletBase>& s)
34 : OptionletVolatilityStructure(s->settlementDays(),
35 s->calendar(),
36 s->businessDayConvention(),
37 s->dayCounter()),
38 optionletStripper_(s),
39 nInterpolations_(s->optionletMaturities()),
40 strikeInterpolations_(nInterpolations_) {
42 }
43
44 ext::shared_ptr<SmileSection>
46 std::vector< Rate > optionletStrikes =
47 optionletStripper_->optionletStrikes(
48 0); // strikes are the same for all times ?!
49 std::vector< Real > stddevs;
50 stddevs.reserve(optionletStrikes.size());
51 for (Real optionletStrike : optionletStrikes) {
52 stddevs.push_back(volatilityImpl(t, optionletStrike) * std::sqrt(t));
53 }
54 // Extrapolation may be a problem with splines, but since minStrike()
55 // and maxStrike() are set, we assume that no one will use stddevs for
56 // strikes outside these strikes
58 optionletStrikes.size() >= 4 ? CubicInterpolation::Lagrange
60 return ext::make_shared< InterpolatedSmileSection< Cubic > >(
61 t, optionletStrikes, stddevs, Null< Real >(),
62 Cubic(CubicInterpolation::Spline, false, bc, 0.0, bc, 0.0),
64 }
65
67 Rate strike) const {
68 calculate();
69
70 std::vector<Volatility> vol(nInterpolations_);
71 for (Size i=0; i<nInterpolations_; ++i)
72 vol[i] = (*strikeInterpolations_[i])(strike, true);
73
74 const std::vector<Time>& optionletTimes =
75 optionletStripper_->optionletFixingTimes();
76 ext::shared_ptr<LinearInterpolation> timeInterpolator(new
77 LinearInterpolation(optionletTimes.begin(), optionletTimes.end(),
78 vol.begin()));
79 return (*timeInterpolator)(length, true);
80 }
81
83
84 //const std::vector<Rate>& atmForward = optionletStripper_->atmOptionletRate();
85 //const std::vector<Time>& optionletTimes = optionletStripper_->optionletTimes();
86
87 for (Size i=0; i<nInterpolations_; ++i) {
88 const std::vector<Rate>& optionletStrikes =
89 optionletStripper_->optionletStrikes(i);
90 const std::vector<Volatility>& optionletVolatilities =
91 optionletStripper_->optionletVolatilities(i);
92 //strikeInterpolations_[i] = ext::shared_ptr<SABRInterpolation>(new
93 // SABRInterpolation(optionletStrikes.begin(), optionletStrikes.end(),
94 // optionletVolatilities.begin(),
95 // optionletTimes[i], atmForward[i],
96 // 0.02,0.5,0.2,0.,
97 // false, true, false, false
98 // //alphaGuess_, betaGuess_,
99 // //nuGuess_, rhoGuess_,
100 // //isParameterFixed_[0],
101 // //isParameterFixed_[1],
102 // //isParameterFixed_[2],
103 // //isParameterFixed_[3]
104 // ////,
105 // //vegaWeightedSmileFit_,
106 // //endCriteria_,
107 // //optMethod_
108 // ));
109 strikeInterpolations_[i] = ext::make_shared<LinearInterpolation>(optionletStrikes.begin(),
110 optionletStrikes.end(),
111 optionletVolatilities.begin());
112
113 //QL_ENSURE(strikeInterpolations_[i]->endCriteria()!=EndCriteria::MaxIterations,
114 // "section calibration failed: "
115 // "option time " << optionletTimes[i] <<
116 // ": " <<
117 // ", alpha " << strikeInterpolations_[i]->alpha()<<
118 // ", beta " << strikeInterpolations_[i]->beta() <<
119 // ", nu " << strikeInterpolations_[i]->nu() <<
120 // ", rho " << strikeInterpolations_[i]->rho() <<
121 // ", error " << strikeInterpolations_[i]->interpolationError()
122 // );
123
124 }
125 }
126
128 return optionletStripper_->optionletStrikes(0).front(); //FIX
129 }
130
132 return optionletStripper_->optionletStrikes(0).back(); //FIX
133 }
134
136 return optionletStripper_->optionletFixingDates().back();
137 }
138
140 return optionletStripper_->volatilityType();
141 }
142
144 return optionletStripper_->displacement();
145 }
146}
Cap/floor smile volatility surface.
Actual/365 (Fixed) day count convention.
Cubic interpolation factory and traits
@ SecondDerivative
Match value of second derivative at end.
Concrete date class.
Definition: date.hpp:125
virtual void calculate() const
Definition: lazyobject.hpp:253
Linear interpolation between discrete points
template class providing a null value for a given type.
Definition: null.hpp:76
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
Optionlet (caplet/floorlet) volatility structure.
const ext::shared_ptr< StrippedOptionletBase > optionletStripper_
Rate maxStrike() const override
the maximum strike for which the term structure can return vols
Rate minStrike() const override
the minimum strike for which the term structure can return vols
ext::shared_ptr< SmileSection > smileSectionImpl(Time optionTime) const override
implements the actual smile calculation in derived classes
VolatilityType volatilityType() const override
StrippedOptionletAdapter(const ext::shared_ptr< StrippedOptionletBase > &)
Volatility volatilityImpl(Time length, Rate strike) const override
implements the actual volatility calculation in derived classes
Date maxDate() const override
the latest date for which the curve can return values
std::vector< ext::shared_ptr< Interpolation > > strikeInterpolations_
cubic interpolation between discrete points
const DefaultType & t
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
Real Volatility
volatility
Definition: types.hpp:78
Real Rate
interest rates
Definition: types.hpp:70
std::size_t Size
size of a container
Definition: types.hpp:58
Interpolated smile section class.
linear interpolation between discrete points
Definition: any.hpp:35
optionlet (caplet/floorlet) volatility stripper
SABR interpolation interpolation between discrete points.
StrippedOptionlet Adapter.