/src/quantlib/ql/termstructures/volatility/swaption/swaptionvolstructure.cpp
Line | Count | Source |
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 | | <https://www.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 | | |
25 | | namespace QuantLib { |
26 | | |
27 | | SwaptionVolatilityStructure::SwaptionVolatilityStructure( |
28 | | BusinessDayConvention bdc, |
29 | | const DayCounter& dc) |
30 | 0 | : VolatilityTermStructure(bdc, dc) {} |
31 | | |
32 | | SwaptionVolatilityStructure::SwaptionVolatilityStructure( |
33 | | const Date& referenceDate, |
34 | | const Calendar& calendar, |
35 | | BusinessDayConvention bdc, |
36 | | const DayCounter& dc) |
37 | 0 | : VolatilityTermStructure(referenceDate, calendar, bdc, dc) {} |
38 | | |
39 | | SwaptionVolatilityStructure::SwaptionVolatilityStructure( |
40 | | Natural settlementDays, |
41 | | const Calendar& calendar, |
42 | | BusinessDayConvention bdc, |
43 | | const DayCounter& dc) |
44 | 0 | : VolatilityTermStructure(settlementDays, calendar, bdc, dc) {} |
45 | | |
46 | | |
47 | 0 | Time SwaptionVolatilityStructure::swapLength(const Period& p) const { |
48 | 0 | QL_REQUIRE(p.length()>0, |
49 | 0 | "non-positive swap tenor (" << p << ") given"); |
50 | 0 | switch (p.units()) { |
51 | 0 | case Months: |
52 | 0 | return p.length()/12.0; |
53 | 0 | case Years: |
54 | 0 | return static_cast<Time>(p.length()); |
55 | 0 | default: |
56 | 0 | QL_FAIL("invalid Time Unit (" << p.units() << ") for swap length"); |
57 | 0 | } |
58 | 0 | } |
59 | | |
60 | | Time SwaptionVolatilityStructure::swapLength(const Date& start, |
61 | 0 | const Date& end) const { |
62 | 0 | QL_REQUIRE(end>start, "swap end date (" << end << |
63 | 0 | ") must be greater than start (" << start << ")"); |
64 | 0 | Time result = (end-start)/365.25*12.0; // month unit |
65 | 0 | result = ClosestRounding(0)(result); |
66 | 0 | result /= 12.0; // year unit |
67 | 0 | return result; |
68 | 0 | } |
69 | | |
70 | | void SwaptionVolatilityStructure::checkSwapTenor(const Period& swapTenor, |
71 | 0 | bool extrapolate) const { |
72 | 0 | QL_REQUIRE(swapTenor.length() > 0, |
73 | 0 | "non-positive swap tenor (" << swapTenor << ") given"); |
74 | 0 | QL_REQUIRE(extrapolate || allowsExtrapolation() || |
75 | 0 | swapTenor <= maxSwapTenor(), |
76 | 0 | "swap tenor (" << swapTenor << ") is past max tenor (" |
77 | 0 | << maxSwapTenor() << ")"); |
78 | 0 | } |
79 | | |
80 | | void SwaptionVolatilityStructure::checkSwapTenor(Time swapLength, |
81 | 0 | bool extrapolate) const { |
82 | 0 | QL_REQUIRE(swapLength > 0.0, |
83 | 0 | "non-positive swap length (" << swapLength << ") given"); |
84 | 0 | QL_REQUIRE(extrapolate || allowsExtrapolation() || |
85 | 0 | swapLength <= maxSwapLength(), |
86 | 0 | "swap tenor (" << swapLength << ") is past max tenor (" |
87 | 0 | << maxSwapLength() << ")"); |
88 | 0 | } |
89 | | |
90 | | } |