QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
swaptionvolstructure.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) 2002, 2003 RiskMap srl
6 Copyright (C) 2003, 2004, 2005, 2006 StatPro Italia srl
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
22#include <ql/termstructures/volatility/swaption/swaptionvolstructure.hpp>
23#include <ql/math/rounding.hpp>
24
25namespace QuantLib {
26
29 const DayCounter& dc)
30 : VolatilityTermStructure(bdc, dc) {}
31
33 const Date& referenceDate,
34 const Calendar& calendar,
36 const DayCounter& dc)
37 : VolatilityTermStructure(referenceDate, calendar, bdc, dc) {}
38
40 Natural settlementDays,
41 const Calendar& calendar,
43 const DayCounter& dc)
44 : VolatilityTermStructure(settlementDays, calendar, bdc, dc) {}
45
46
48 QL_REQUIRE(p.length()>0,
49 "non-positive swap tenor (" << p << ") given");
50 switch (p.units()) {
51 case Months:
52 return p.length()/12.0;
53 case Years:
54 return static_cast<Time>(p.length());
55 default:
56 QL_FAIL("invalid Time Unit (" << p.units() << ") for swap length");
57 }
58 }
59
61 const Date& end) const {
62 QL_REQUIRE(end>start, "swap end date (" << end <<
63 ") must be greater than start (" << start << ")");
64 Time result = (end-start)/365.25*12.0; // month unit
65 result = ClosestRounding(0)(result);
66 result /= 12.0; // year unit
67 return result;
68 }
69
71 bool extrapolate) const {
72 QL_REQUIRE(swapTenor.length() > 0,
73 "non-positive swap tenor (" << swapTenor << ") given");
74 QL_REQUIRE(extrapolate || allowsExtrapolation() ||
75 swapTenor <= maxSwapTenor(),
76 "swap tenor (" << swapTenor << ") is past max tenor ("
77 << maxSwapTenor() << ")");
78 }
79
81 bool extrapolate) const {
82 QL_REQUIRE(swapLength > 0.0,
83 "non-positive swap length (" << swapLength << ") given");
84 QL_REQUIRE(extrapolate || allowsExtrapolation() ||
86 "swap tenor (" << swapLength << ") is past max tenor ("
87 << maxSwapLength() << ")");
88 }
89
90}
calendar class
Definition: calendar.hpp:61
Closest rounding.
Definition: rounding.hpp:106
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
bool allowsExtrapolation() const
tells whether extrapolation is enabled
TimeUnit units() const
Definition: period.hpp:51
Integer length() const
Definition: period.hpp:50
virtual const Period & maxSwapTenor() const =0
the largest length for which the term structure can return vols
void checkSwapTenor(const Period &swapTenor, bool extrapolate) const
SwaptionVolatilityStructure(BusinessDayConvention bdc, const DayCounter &dc=DayCounter())
Time swapLength(const Period &swapTenor) const
implements the conversion between swap tenor and swap (time) length
Time maxSwapLength() const
the largest swapLength for which the term structure can return vols
Volatility term structure.
BusinessDayConvention
Business Day conventions.
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
Definition: any.hpp:35