QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
strippedoptionlet.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) 2008 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
26#include <utility>
27
28using std::vector;
29
30namespace QuantLib {
31
33 const Calendar& calendar,
35 ext::shared_ptr<IborIndex> iborIndex,
36 const vector<Date>& optionletDates,
37 const vector<Rate>& strikes,
38 vector<vector<Handle<Quote>>> v,
39 DayCounter dc,
40 VolatilityType type,
41 Real displacement)
42 : StrippedOptionlet(settlementDays,
43 calendar,
44 bdc,
45 std::move(iborIndex),
46 optionletDates,
47 vector<vector<Rate>>(optionletDates.size(), strikes),
48 std::move(v),
49 std::move(dc),
50 type,
51 displacement) {}
52
54 const Calendar& calendar,
56 ext::shared_ptr<IborIndex> iborIndex,
57 const vector<Date>& optionletDates,
58 const vector<vector<Rate>>& strikes,
59 vector<vector<Handle<Quote>>> v,
60 DayCounter dc,
61 VolatilityType type,
62 Real displacement)
63 : calendar_(calendar), settlementDays_(settlementDays), businessDayConvention_(bdc),
64 dc_(std::move(dc)), iborIndex_(std::move(iborIndex)), type_(type),
65 displacement_(displacement), nOptionletDates_(optionletDates.size()),
66 optionletDates_(optionletDates), optionletTimes_(nOptionletDates_),
67 optionletAtmRates_(nOptionletDates_), optionletStrikes_(strikes),
68 optionletVolQuotes_(std::move(v)) {
70
71 for (Size i = 0; i < nOptionletDates_; ++i)
72 optionletVolatilities_.emplace_back(strikes[i].size());
73
74 registerWith(Settings::instance().evaluationDate());
76
77 Date refDate = calendar.advance(Settings::instance().evaluationDate(),
79
80 for (Size i=0; i<nOptionletDates_; ++i)
82 }
83
85
86 QL_REQUIRE(!optionletDates_.empty(), "empty optionlet tenor vector");
88 "mismatch between number of option tenors (" <<
89 nOptionletDates_ << ") and number of volatility rows (" <<
90 optionletVolQuotes_.size() << ")");
91 QL_REQUIRE(optionletDates_[0]>Settings::instance().evaluationDate(),
92 "first option date (" << optionletDates_[0] << ") is in the past");
93 for (Size i=1; i<nOptionletDates_; ++i)
95 "non increasing option dates: " << io::ordinal(i) <<
96 " is " << optionletDates_[i-1] << ", " <<
97 io::ordinal(i+1) << " is " << optionletDates_[i]);
99 "mismatch between number of option tenors (" << nOptionletDates_
100 << ") and number of strikes ("
101 << optionletStrikes_.size() << ")");
102 for (Size i = 0; i < nOptionletDates_; ++i) {
103 QL_REQUIRE(optionletStrikes_[i].size() == optionletVolQuotes_[i].size(),
104 "mismatch between number of option tenors ("
105 << nOptionletDates_ << ") and number of vol columns at date " << i
106 << " (" << optionletVolQuotes_[i].size());
107 for (Size j = 1; j < optionletStrikes_[i].size(); ++j)
109 "non increasing strikes at date "
110 << i << ": " << io::ordinal(j) << " is "
111 << io::rate(optionletStrikes_[0][j - 1]) << ", "
112 << io::ordinal(j + 1) << " is "
113 << io::rate(optionletStrikes_[0][j]));
114 }
115 }
116
118 for (Size i = 0; i < nOptionletDates_; ++i)
119 for (auto& j : optionletVolQuotes_[i])
120 registerWith(j);
121 }
122
124 for (Size i = 0; i < nOptionletDates_; ++i)
125 for (Size j = 0; j < optionletVolQuotes_[i].size(); ++j)
126 optionletVolatilities_[i][j] = optionletVolQuotes_[i][j]->value();
127 }
128
129 const vector<Rate>& StrippedOptionlet::optionletStrikes(Size i) const{
131 "index (" << i <<
132 ") must be less than optionletStrikes size (" <<
133 optionletStrikes_.size() << ")");
134 return optionletStrikes_[i];
135 }
136
137 const vector<Volatility>&
139 calculate();
141 "index (" << i <<
142 ") must be less than optionletVolatilities size (" <<
143 optionletVolatilities_.size() << ")");
144 return optionletVolatilities_[i];
145 }
146
147 const vector<Date>& StrippedOptionlet::optionletFixingDates() const {
148 calculate();
149 return optionletDates_;
150 }
151
152 const vector<Time>& StrippedOptionlet::optionletFixingTimes() const {
153 calculate();
154 return optionletTimes_;
155 }
156
158 return nOptionletDates_;
159 }
160
161 const vector<Time>& StrippedOptionlet::atmOptionletRates() const {
162 calculate();
163 for (Size i=0; i<nOptionletDates_; ++i)
164 optionletAtmRates_[i] = iborIndex_->fixing(optionletDates_[i], true);
165 return optionletAtmRates_;
166 }
167
169 return dc_;
170 }
171
173 return calendar_;
174 }
175
177 return settlementDays_;
178 }
179
182 }
183
185 return type_;
186 }
187
189 return displacement_;
190 }
191
192}
Black-formula cap/floor engine.
calendar class
Definition: calendar.hpp:61
Date advance(const Date &, Integer n, TimeUnit unit, BusinessDayConvention convention=Following, bool endOfMonth=false) const
Definition: calendar.cpp:130
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
Time yearFraction(const Date &, const Date &, const Date &refPeriodStart=Date(), const Date &refPeriodEnd=Date()) const
Returns the period between two dates as a fraction of year.
Definition: daycounter.hpp:128
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
static Settings & instance()
access to the unique instance
Definition: singleton.hpp:104
void performCalculations() const override
Calendar calendar() const override
std::vector< std::vector< Volatility > > optionletVolatilities_
const std::vector< Date > & optionletFixingDates() const override
const std::vector< Rate > & optionletStrikes(Size i) const override
ext::shared_ptr< IborIndex > iborIndex_
const std::vector< Time > & optionletFixingTimes() const override
const std::vector< Volatility > & optionletVolatilities(Size i) const override
VolatilityType volatilityType() const override
std::vector< Rate > optionletAtmRates_
std::vector< Time > optionletTimes_
std::vector< Date > optionletDates_
StrippedOptionlet(Natural settlementDays, const Calendar &calendar, BusinessDayConvention bdc, ext::shared_ptr< IborIndex > iborIndex, const std::vector< Date > &optionletDates, const std::vector< Rate > &strikes, std::vector< std::vector< Handle< Quote > > >, DayCounter dc, VolatilityType type=ShiftedLognormal, Real displacement=0.0)
Natural settlementDays() const override
DayCounter dayCounter() const override
std::vector< std::vector< Handle< Quote > > > optionletVolQuotes_
const std::vector< Rate > & atmOptionletRates() const override
BusinessDayConvention businessDayConvention() const override
std::vector< std::vector< Rate > > optionletStrikes_
Real displacement() const override
Size optionletMaturities() const override
BusinessDayConvention businessDayConvention_
output manipulators
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
BusinessDayConvention
Business Day conventions.
detail::percent_holder rate(Rate)
output rates and spreads as percentages
detail::ordinal_holder ordinal(Size)
outputs naturals as 1st, 2nd, 3rd...
QL_REAL Real
real number
Definition: types.hpp:50
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
Real Rate
interest rates
Definition: types.hpp:70
std::size_t Size
size of a container
Definition: types.hpp:58
Helper class to instantiate standard market cap/floor.
Definition: any.hpp:35
STL namespace.
ext::shared_ptr< BlackVolTermStructure > v