QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
swaptionvoldiscrete.cpp
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
21#include <ql/termstructures/volatility/swaption/swaptionvoldiscrete.hpp>
22#include <ql/math/interpolations/linearinterpolation.hpp>
23#include <ql/utilities/dataformatters.hpp>
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) {
129 QL_REQUIRE(optionDates_[i]>optionDates_[i-1],
130 "non increasing option dates: " << io::ordinal(i) <<
131 " is " << optionDates_[i-1] << ", " << io::ordinal(i+1) <<
132 " is " << optionDates_[i]);
133 }
134 }
135
137 QL_REQUIRE(optionTenors_[0]>0*Days,
138 "first option tenor is negative (" <<
139 optionTenors_[0] << ")");
140 for (Size i=1; i<nOptionTenors_; ++i)
141 QL_REQUIRE(optionTenors_[i]>optionTenors_[i-1],
142 "non increasing option tenor: " << io::ordinal(i) <<
143 " is " << optionTenors_[i-1] << ", " << io::ordinal(i+1) <<
144 " is " << optionTenors_[i]);
145 }
146
148 QL_REQUIRE(swapTenors_[0]>0*Days,
149 "first swap tenor is negative (" <<
150 swapTenors_[0] << ")");
151 for (Size i=1; i<nSwapTenors_; ++i)
152 QL_REQUIRE(swapTenors_[i]>swapTenors_[i-1],
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
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
Definition: any.hpp:35