QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
swaptionvoldiscrete.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 François du Vignaud
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
25namespace QuantLib {
26
28 const std::vector<Period>& optionTenors,
29 const std::vector<Period>& swapTenors,
30 Natural settlementDays,
31 const Calendar& cal,
33 const DayCounter& dc)
34 : SwaptionVolatilityStructure(settlementDays, cal, bdc, dc),
35 nOptionTenors_(optionTenors.size()),
36 optionTenors_(optionTenors),
37 optionDates_(nOptionTenors_),
38 optionTimes_(nOptionTenors_),
39 optionDatesAsReal_(nOptionTenors_),
40 optionInterpolatorTimes_(nOptionTenors_ + 1),
41 optionInterpolatorDatesAsReal_(nOptionTenors_ + 1),
42 nSwapTenors_(swapTenors.size()),
43 swapTenors_(swapTenors),
44 swapLengths_(nSwapTenors_) {
45
48
51
58 }
59
61 const std::vector<Period>& optionTenors,
62 const std::vector<Period>& swapTenors,
63 const Date& referenceDate,
64 const Calendar& cal,
66 const DayCounter& dc)
67 : SwaptionVolatilityStructure(referenceDate, cal, bdc, dc),
68 nOptionTenors_(optionTenors.size()),
69 optionTenors_(optionTenors),
70 optionDates_(nOptionTenors_),
71 optionTimes_(nOptionTenors_),
72 optionDatesAsReal_(nOptionTenors_),
73 optionInterpolatorTimes_(nOptionTenors_ + 1),
74 optionInterpolatorDatesAsReal_(nOptionTenors_ + 1),
75 nSwapTenors_(swapTenors.size()),
76 swapTenors_(swapTenors),
77 swapLengths_(nSwapTenors_) {
78
81
84
90 }
91
93 const std::vector<Date>& optionDates,
94 const std::vector<Period>& swapTenors,
95 const Date& referenceDate,
96 const Calendar& cal,
98 const DayCounter& dc)
99 : SwaptionVolatilityStructure(referenceDate, cal, bdc, dc),
100 nOptionTenors_(optionDates.size()),
101 optionTenors_(nOptionTenors_),
102 optionDates_(optionDates),
103 optionTimes_(nOptionTenors_),
104 optionDatesAsReal_(nOptionTenors_),
105 optionInterpolatorTimes_(nOptionTenors_ + 1),
106 optionInterpolatorDatesAsReal_(nOptionTenors_ + 1),
107 nSwapTenors_(swapTenors.size()),
108 swapTenors_(swapTenors),
109 swapLengths_(nSwapTenors_) {
110
113
116
122 }
123
125 QL_REQUIRE(optionDates_[0] > reference,
126 "first option date (" << optionDates_[0] <<
127 ") must be greater than reference date (" << reference << ")");
128 for (Size i=1; i<nOptionTenors_; ++i) {
130 "non increasing option dates: " << io::ordinal(i) <<
131 " is " << optionDates_[i-1] << ", " << io::ordinal(i+1) <<
132 " is " << optionDates_[i]);
133 }
134 }
135
138 "first option tenor is negative (" <<
139 optionTenors_[0] << ")");
140 for (Size i=1; i<nOptionTenors_; ++i)
142 "non increasing option tenor: " << io::ordinal(i) <<
143 " is " << optionTenors_[i-1] << ", " << io::ordinal(i+1) <<
144 " is " << optionTenors_[i]);
145 }
146
149 "first swap tenor is negative (" <<
150 swapTenors_[0] << ")");
151 for (Size i=1; i<nSwapTenors_; ++i)
153 "non increasing swap tenor: " << io::ordinal(i) <<
154 " is " << swapTenors_[i-1] << ", " << io::ordinal(i+1) <<
155 " is " << swapTenors_[i]);
156 }
157
160 for (Size i=0; i<nOptionTenors_; ++i) {
163 static_cast<Real>(optionDates_[i].serialNumber());
164 }
166 }
167
170 for (Size i = 0; i < nOptionTenors_; ++i) {
172 }
173 }
174
176 for (Size i=0; i<nSwapTenors_; ++i)
178 }
179
181 // recalculate dates if necessary...
182 if (moving_) {
188 }
189 }
190 }
191
195 }
196
197}
calendar class
Definition: calendar.hpp:61
Concrete date class.
Definition: date.hpp:125
Date::serial_type serialNumber() const
Definition: date.hpp:408
day counter class
Definition: daycounter.hpp:44
void enableExtrapolation(bool b=true)
enable extrapolation in subsequent calls
void update() override
Definition: lazyobject.hpp:188
Linear interpolation between discrete points
SwaptionVolatilityDiscrete(const std::vector< Period > &optionTenors, const std::vector< Period > &swapTenors, Natural settlementDays, const Calendar &cal, BusinessDayConvention bdc, const DayCounter &dc)
void checkOptionDates(const Date &reference) const
Time swapLength(const Period &swapTenor) const
implements the conversion between swap tenor and swap (time) length
virtual const Date & referenceDate() const
the date at which discount = 1.0 and/or variance = 0.0
void update() override
Time timeFromReference(const Date &date) const
date/time conversion
Date optionDateFromTenor(const Period &) const
period/date conversion
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::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
std::size_t Size
size of a container
Definition: types.hpp:58
linear interpolation between discrete points
Definition: any.hpp:35
Discretized swaption volatility.