QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
swaptionvolcube.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) 2006 Ferdinando Ametrano
5 Copyright (C) 2006 Katiuscia Manzoni
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
24#include <utility>
25
26namespace QuantLib {
27
30 const std::vector<Period>& optionTenors,
31 const std::vector<Period>& swapTenors,
32 const std::vector<Spread>& strikeSpreads,
33 std::vector<std::vector<Handle<Quote> > > volSpreads,
34 ext::shared_ptr<SwapIndex> swapIndexBase,
35 ext::shared_ptr<SwapIndex> shortSwapIndexBase,
36 bool vegaWeightedSmileFit)
37 : SwaptionVolatilityDiscrete(optionTenors,
38 swapTenors,
39 0,
40 atmVol->calendar(),
41 atmVol->businessDayConvention(),
42 atmVol->dayCounter()),
43 atmVol_(atmVol), nStrikes_(strikeSpreads.size()), strikeSpreads_(strikeSpreads),
44 localStrikes_(nStrikes_), localSmile_(nStrikes_), volSpreads_(std::move(volSpreads)),
45 swapIndexBase_(std::move(swapIndexBase)), shortSwapIndexBase_(std::move(shortSwapIndexBase)),
46 vegaWeightedSmileFit_(vegaWeightedSmileFit) {
47 QL_REQUIRE(!atmVol_.empty(), "atm vol handle not linked to anything");
48 for (Size i=1; i<nStrikes_; ++i)
50 "non increasing strike spreads: " <<
51 io::ordinal(i) << " is " << strikeSpreads_[i-1] << ", " <<
52 io::ordinal(i+1) << " is " << strikeSpreads_[i]);
53
54 QL_REQUIRE(!volSpreads_.empty(), "empty vol spreads matrix");
55
57 "mismatch between number of option tenors * swap tenors (" <<
58 nOptionTenors_*nSwapTenors_ << ") and number of rows (" <<
59 volSpreads_.size() << ")");
60
61 for (Size i=0; i<volSpreads_.size(); i++)
63 "mismatch between number of strikes (" << nStrikes_ <<
64 ") and number of columns (" << volSpreads_[i].size() <<
65 ") in the " << io::ordinal(i+1) << " row");
66
68 atmVol_->enableExtrapolation();
69
72
74 "short index tenor (" << shortSwapIndexBase_->tenor() <<
75 ") is not less or equal than index tenor (" <<
76 swapIndexBase_->tenor() << ")");
77
79 }
80
82 {
83 for (Size i=0; i<nStrikes_; i++)
84 for (Size j=0; j<nOptionTenors_; j++)
85 for (Size k=0; k<nSwapTenors_; k++)
87 }
88
90 const Period& swapTenor) const {
91
92 // FIXME use a familyName-based index factory
93 if (swapTenor > shortSwapIndexBase_->tenor()) {
94 if (swapIndexBase_->exogenousDiscount()) {
95 return SwapIndex(swapIndexBase_->familyName(),
96 swapTenor,
97 swapIndexBase_->fixingDays(),
98 swapIndexBase_->currency(),
99 swapIndexBase_->fixingCalendar(),
100 swapIndexBase_->fixedLegTenor(),
101 swapIndexBase_->fixedLegConvention(),
102 swapIndexBase_->dayCounter(),
103 swapIndexBase_->iborIndex(),
104 swapIndexBase_->discountingTermStructure())
105 .fixing(optionD);
106 } else {
107 return SwapIndex(swapIndexBase_->familyName(),
108 swapTenor,
109 swapIndexBase_->fixingDays(),
110 swapIndexBase_->currency(),
111 swapIndexBase_->fixingCalendar(),
112 swapIndexBase_->fixedLegTenor(),
113 swapIndexBase_->fixedLegConvention(),
114 swapIndexBase_->dayCounter(),
115 swapIndexBase_->iborIndex())
116 .fixing(optionD);
117 }
118 } else {
119 if (shortSwapIndexBase_->exogenousDiscount()) {
120 return SwapIndex(shortSwapIndexBase_->familyName(),
121 swapTenor,
122 shortSwapIndexBase_->fixingDays(),
123 shortSwapIndexBase_->currency(),
124 shortSwapIndexBase_->fixingCalendar(),
125 shortSwapIndexBase_->fixedLegTenor(),
126 shortSwapIndexBase_->fixedLegConvention(),
127 shortSwapIndexBase_->dayCounter(),
128 shortSwapIndexBase_->iborIndex(),
129 shortSwapIndexBase_->discountingTermStructure())
130 .fixing(optionD);
131 } else {
132 return SwapIndex(shortSwapIndexBase_->familyName(),
133 swapTenor,
134 shortSwapIndexBase_->fixingDays(),
135 shortSwapIndexBase_->currency(),
136 shortSwapIndexBase_->fixingCalendar(),
137 shortSwapIndexBase_->fixedLegTenor(),
138 shortSwapIndexBase_->fixedLegConvention(),
139 shortSwapIndexBase_->dayCounter(),
140 shortSwapIndexBase_->iborIndex())
141 .fixing(optionD);
142 }
143 }
144 }
145
146}
Concrete date class.
Definition: date.hpp:125
Shared handle to an observable.
Definition: handle.hpp:41
Rate fixing(const Date &fixingDate, bool forecastTodaysFixing=false) const override
returns the fixing at the given date
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
base class for swap-rate indexes
Definition: swapindex.hpp:41
Rate atmStrike(const Date &optionDate, const Period &swapTenor) const
ext::shared_ptr< SwapIndex > swapIndexBase_
std::vector< Spread > strikeSpreads_
Handle< SwaptionVolatilityStructure > atmVol_
SwaptionVolatilityCube(const Handle< SwaptionVolatilityStructure > &atmVolStructure, const std::vector< Period > &optionTenors, const std::vector< Period > &swapTenors, const std::vector< Spread > &strikeSpreads, std::vector< std::vector< Handle< Quote > > > volSpreads, ext::shared_ptr< SwapIndex > swapIndexBase, ext::shared_ptr< SwapIndex > shortSwapIndexBase, bool vegaWeightedSmileFit)
ext::shared_ptr< SwapIndex > shortSwapIndexBase_
std::vector< std::vector< Handle< Quote > > > volSpreads_
output manipulators
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
detail::ordinal_holder ordinal(Size)
outputs naturals as 1st, 2nd, 3rd...
Real Rate
interest rates
Definition: types.hpp:70
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
STL namespace.
swap-rate indexes
Swaption volatility cube.