/src/quantlib/ql/experimental/callablebonds/callablebondvolstructure.cpp
Line | Count | Source |
1 | | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* |
4 | | Copyright (C) 2008 Allen Kuo |
5 | | |
6 | | This file is part of QuantLib, a free-software/open-source library |
7 | | for financial quantitative analysts and developers - http://quantlib.org/ |
8 | | |
9 | | QuantLib is free software: you can redistribute it and/or modify it |
10 | | under the terms of the QuantLib license. You should have received a |
11 | | copy of the license along with this program; if not, please email |
12 | | <quantlib-dev@lists.sf.net>. The license is also available online at |
13 | | <https://www.quantlib.org/license.shtml>. |
14 | | |
15 | | This program is distributed in the hope that it will be useful, but WITHOUT |
16 | | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
17 | | FOR A PARTICULAR PURPOSE. See the license for more details. |
18 | | */ |
19 | | |
20 | | #include <ql/experimental/callablebonds/callablebondvolstructure.hpp> |
21 | | #include <ql/time/period.hpp> |
22 | | |
23 | | namespace QuantLib { |
24 | | |
25 | | CallableBondVolatilityStructure::CallableBondVolatilityStructure( |
26 | | const DayCounter& dc, |
27 | | BusinessDayConvention bdc) |
28 | 0 | : TermStructure(dc), bdc_(bdc) {} |
29 | | |
30 | | CallableBondVolatilityStructure::CallableBondVolatilityStructure( |
31 | | const Date& referenceDate, |
32 | | const Calendar& calendar, |
33 | | const DayCounter& dc, |
34 | | BusinessDayConvention bdc) |
35 | 0 | : TermStructure(referenceDate, calendar, dc), bdc_(bdc) {} |
36 | | |
37 | | CallableBondVolatilityStructure::CallableBondVolatilityStructure( |
38 | | Natural settlementDays, |
39 | | const Calendar& calendar, |
40 | | const DayCounter& dc, |
41 | | BusinessDayConvention bdc) |
42 | 0 | : TermStructure(settlementDays, calendar, dc), bdc_(bdc) {} |
43 | | |
44 | 0 | Time CallableBondVolatilityStructure::maxBondLength() const { |
45 | 0 | return timeFromReference(referenceDate()+maxBondTenor()); |
46 | 0 | } |
47 | | |
48 | | std::pair<Time,Time> |
49 | | CallableBondVolatilityStructure::convertDates( |
50 | | const Date& optionDate, |
51 | 0 | const Period& bondTenor) const { |
52 | 0 | Date end = optionDate + bondTenor; |
53 | 0 | QL_REQUIRE(end>optionDate, |
54 | 0 | "negative bond tenor (" << bondTenor << ") given"); |
55 | 0 | Time optionTime = timeFromReference(optionDate); |
56 | 0 | Time timeLength = dayCounter().yearFraction(optionDate, end); |
57 | 0 | return std::make_pair(optionTime, timeLength); |
58 | 0 | } |
59 | | |
60 | | void CallableBondVolatilityStructure::checkRange(const Date& optionDate, |
61 | | const Period& bondTenor, |
62 | | Rate k, |
63 | 0 | bool extrapolate) const { |
64 | 0 | TermStructure::checkRange(timeFromReference(optionDate), |
65 | 0 | extrapolate); |
66 | 0 | QL_REQUIRE(bondTenor.length() > 0, |
67 | 0 | "negative bond tenor (" << bondTenor << ") given"); |
68 | 0 | QL_REQUIRE(extrapolate || allowsExtrapolation() || |
69 | 0 | bondTenor <= maxBondTenor(), |
70 | 0 | "bond tenor (" << bondTenor << ") is past max tenor (" |
71 | 0 | << maxBondTenor() << ")"); |
72 | 0 | QL_REQUIRE(extrapolate || allowsExtrapolation() || |
73 | 0 | (k >= minStrike() && k <= maxStrike()), |
74 | 0 | "strike (" << k << ") is outside the curve domain [" |
75 | 0 | << minStrike() << "," << maxStrike()<< "]"); |
76 | 0 | } |
77 | | |
78 | | } |
79 | | |