QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
optionletstripper.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 Ferdinando Ametrano
5 Copyright (C) 2007 Giorgio Facchinetti
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
24#include <utility>
25
26using std::vector;
27
28namespace QuantLib {
29
31 const ext::shared_ptr<CapFloorTermVolSurface>& termVolSurface,
32 ext::shared_ptr<IborIndex> iborIndex,
34 const VolatilityType type,
35 const Real displacement)
36 : termVolSurface_(termVolSurface), iborIndex_(std::move(iborIndex)),
37 discount_(std::move(discount)), nStrikes_(termVolSurface->strikes().size()),
38 volatilityType_(type), displacement_(displacement) {
39
40 if (volatilityType_ == Normal) {
42 "non-null displacement is not allowed with Normal model");
43 }
44
48 registerWith(Settings::instance().evaluationDate());
49
50 Period indexTenor = iborIndex_->tenor();
51 Period maxCapFloorTenor = termVolSurface->optionTenors().back();
52
53 // optionlet tenors and capFloor lengths
54 optionletTenors_.push_back(indexTenor);
55 capFloorLengths_.push_back(optionletTenors_.back()+indexTenor);
56 QL_REQUIRE(maxCapFloorTenor>=capFloorLengths_.back(),
57 "too short (" << maxCapFloorTenor <<
58 ") capfloor term vol termVolSurface");
59 Period nextCapFloorLength = capFloorLengths_.back()+indexTenor;
60 while (nextCapFloorLength<=maxCapFloorTenor) {
61 optionletTenors_.push_back(capFloorLengths_.back());
62 capFloorLengths_.push_back(nextCapFloorLength);
63 nextCapFloorLength += indexTenor;
64 }
66
68 vector<vector<Volatility> >(nOptionletTenors_,
69 vector<Volatility>(nStrikes_));
70 optionletStrikes_ = vector<vector<Rate> >(nOptionletTenors_,
71 termVolSurface->strikes());
72 optionletDates_ = vector<Date>(nOptionletTenors_);
73 optionletTimes_ = vector<Time>(nOptionletTenors_);
77 }
78
79 const vector<Rate>& OptionletStripper::optionletStrikes(Size i) const {
80 calculate();
82 "index (" << i <<
83 ") must be less than optionletStrikes size (" <<
84 optionletStrikes_.size() << ")");
85 return optionletStrikes_[i];
86 }
87
88 const vector<Volatility>&
90 calculate();
92 "index (" << i <<
93 ") must be less than optionletVolatilities size (" <<
94 optionletVolatilities_.size() << ")");
95 return optionletVolatilities_[i];
96 }
97
98 const vector<Period>& OptionletStripper::optionletFixingTenors() const {
99 return optionletTenors_;
100 }
101
102 const vector<Date>& OptionletStripper::optionletFixingDates() const {
103 calculate();
104 return optionletDates_;
105 }
106
107 const vector<Time>& OptionletStripper::optionletFixingTimes() const {
108 calculate();
109 return optionletTimes_;
110 }
111
113 return optionletTenors_.size();
114 }
115
116 const vector<Date>& OptionletStripper::optionletPaymentDates() const {
117 calculate();
119 }
120
121 const vector<Time>& OptionletStripper::optionletAccrualPeriods() const {
122 calculate();
124 }
125
126 const vector<Rate>& OptionletStripper::atmOptionletRates() const {
127 calculate();
128 return atmOptionletRate_;
129 }
130
131
133 return termVolSurface_->dayCounter();
134 }
135
137 return termVolSurface_->calendar();
138 }
139
141 return termVolSurface_->settlementDays();
142 }
143
145 return termVolSurface_->businessDayConvention();
146 }
147
148 ext::shared_ptr<CapFloorTermVolSurface>
150 return termVolSurface_;
151 }
152
153 ext::shared_ptr<IborIndex> OptionletStripper::iborIndex() const {
154 return iborIndex_;
155 }
156
158 return displacement_;
159 }
160
162 return volatilityType_;
163 }
164
165}
calendar class
Definition: calendar.hpp:61
day counter class
Definition: daycounter.hpp:44
Shared handle to an observable.
Definition: handle.hpp:41
virtual void calculate() const
Definition: lazyobject.hpp:253
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
Calendar calendar() const override
std::vector< Rate > atmOptionletRate_
std::vector< std::vector< Volatility > > optionletVolatilities_
const std::vector< Date > & optionletFixingDates() const override
std::vector< Period > capFloorLengths_
ext::shared_ptr< CapFloorTermVolSurface > termVolSurface() const
Handle< YieldTermStructure > discount_
const std::vector< Rate > & optionletStrikes(Size i) const override
ext::shared_ptr< IborIndex > iborIndex_
std::vector< Date > optionletPaymentDates_
std::vector< Time > optionletAccrualPeriods_
const std::vector< Time > & optionletFixingTimes() const override
const std::vector< Date > & optionletPaymentDates() const
const std::vector< Volatility > & optionletVolatilities(Size i) const override
const std::vector< Rate > & atmOptionletRates() const override
std::vector< Period > optionletTenors_
VolatilityType volatilityType() const override
ext::shared_ptr< IborIndex > iborIndex() const
std::vector< Time > optionletTimes_
std::vector< Date > optionletDates_
Natural settlementDays() const override
DayCounter dayCounter() const override
const std::vector< Period > & optionletFixingTenors() const
const VolatilityType volatilityType_
BusinessDayConvention businessDayConvention() const override
std::vector< std::vector< Rate > > optionletStrikes_
Real displacement() const override
OptionletStripper(const ext::shared_ptr< CapFloorTermVolSurface > &, ext::shared_ptr< IborIndex > iborIndex_, Handle< YieldTermStructure > discount={}, VolatilityType type=ShiftedLognormal, Real displacement=0.0)
ext::shared_ptr< CapFloorTermVolSurface > termVolSurface_
const std::vector< Time > & optionletAccrualPeriods() const
Size optionletMaturities() const override
static Settings & instance()
access to the unique instance
Definition: singleton.hpp:104
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
BusinessDayConvention
Business Day conventions.
QL_REAL Real
real number
Definition: types.hpp:50
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
std::size_t Size
size of a container
Definition: types.hpp:58
base class for Inter-Bank-Offered-Rate indexes
Definition: any.hpp:35
STL namespace.
optionlet (caplet/floorlet) volatility stripper