QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
callablebondvolstructure.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) 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 <http://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
21#include <ql/time/period.hpp>
22
23namespace QuantLib {
24
26 const DayCounter& dc,
28 : TermStructure(dc), bdc_(bdc) {}
29
31 const Date& referenceDate,
32 const Calendar& calendar,
33 const DayCounter& dc,
35 : TermStructure(referenceDate, calendar, dc), bdc_(bdc) {}
36
38 Natural settlementDays,
39 const Calendar& calendar,
40 const DayCounter& dc,
42 : TermStructure(settlementDays, calendar, dc), bdc_(bdc) {}
43
46 }
47
48 std::pair<Time,Time>
50 const Date& optionDate,
51 const Period& bondTenor) const {
52 Date end = optionDate + bondTenor;
53 QL_REQUIRE(end>optionDate,
54 "negative bond tenor (" << bondTenor << ") given");
55 Time optionTime = timeFromReference(optionDate);
56 Time timeLength = dayCounter().yearFraction(optionDate, end);
57 return std::make_pair(optionTime, timeLength);
58 }
59
61 const Period& bondTenor,
62 Rate k,
63 bool extrapolate) const {
65 extrapolate);
66 QL_REQUIRE(bondTenor.length() > 0,
67 "negative bond tenor (" << bondTenor << ") given");
68 QL_REQUIRE(extrapolate || allowsExtrapolation() ||
69 bondTenor <= maxBondTenor(),
70 "bond tenor (" << bondTenor << ") is past max tenor ("
71 << maxBondTenor() << ")");
72 QL_REQUIRE(extrapolate || allowsExtrapolation() ||
73 (k >= minStrike() && k <= maxStrike()),
74 "strike (" << k << ") is outside the curve domain ["
75 << minStrike() << "," << maxStrike()<< "]");
76 }
77
78}
79
Callable-bond volatility structure.
calendar class
Definition: calendar.hpp:61
virtual const Period & maxBondTenor() const =0
the largest length for which the term structure can return vols
virtual Time maxBondLength() const
the largest bondLength for which the term structure can return vols
virtual Rate maxStrike() const =0
the maximum strike for which the term structure can return vols
virtual std::pair< Time, Time > convertDates(const Date &optionDate, const Period &bondTenor) const
implements the conversion between dates and times
virtual Rate minStrike() const =0
the minimum strike for which the term structure can return vols
void checkRange(Time, Time, Rate strike, bool extrapolate) const
CallableBondVolatilityStructure(const DayCounter &dc=DayCounter(), BusinessDayConvention bdc=Following)
default constructor
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
Time yearFraction(const Date &, const Date &, const Date &refPeriodStart=Date(), const Date &refPeriodEnd=Date()) const
Returns the period between two dates as a fraction of year.
Definition: daycounter.hpp:128
bool allowsExtrapolation() const
tells whether extrapolation is enabled
Integer length() const
Definition: period.hpp:50
Basic term-structure functionality.
virtual const Date & referenceDate() const
the date at which discount = 1.0 and/or variance = 0.0
Time timeFromReference(const Date &date) const
date/time conversion
void checkRange(const Date &d, bool extrapolate) const
date-range check
virtual DayCounter dayCounter() const
the day counter used for date/time conversion
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
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
Real Rate
interest rates
Definition: types.hpp:70
Definition: any.hpp:35
period- and frequency-related classes and enumerations