QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
libor.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2007 Ferdinando Ametrano
5 Copyright (C) 2007 Chiara Fornarola
6 Copyright (C) 2005, 2006, 2008 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/indexes/ibor/libor.hpp>
23#include <ql/time/calendars/jointcalendar.hpp>
24#include <ql/time/calendars/unitedkingdom.hpp>
25#include <ql/currencies/europe.hpp>
26
27namespace QuantLib {
28
29 namespace {
30
31 BusinessDayConvention liborConvention(const Period& p) {
32 switch (p.units()) {
33 case Days:
34 case Weeks:
35 return Following;
36 case Months:
37 case Years:
38 return ModifiedFollowing;
39 default:
40 QL_FAIL("invalid time units");
41 }
42 }
43
44 bool liborEOM(const Period& p) {
45 switch (p.units()) {
46 case Days:
47 case Weeks:
48 return false;
49 case Months:
50 case Years:
51 return true;
52 default:
53 QL_FAIL("invalid time units");
54 }
55 }
56
57 }
58
59
60 Libor::Libor(const std::string& familyName,
61 const Period& tenor,
62 Natural settlementDays,
63 const Currency& currency,
64 const Calendar& financialCenterCalendar,
65 const DayCounter& dayCounter,
67 : IborIndex(familyName, tenor, settlementDays, currency,
68 // http://www.bba.org.uk/bba/jsp/polopoly.jsp?d=225&a=1412 :
69 // UnitedKingdom::Exchange is the fixing calendar for
70 // a) all currencies but EUR
71 // b) all indexes but o/n and s/n
73 liborConvention(tenor), liborEOM(tenor),
74 dayCounter, h),
75 financialCenterCalendar_(financialCenterCalendar),
76 jointCalendar_(JointCalendar(UnitedKingdom(UnitedKingdom::Exchange),
77 financialCenterCalendar,
78 JoinHolidays)) {
79 QL_REQUIRE(this->tenor().units()!=Days,
80 "for daily tenors (" << this->tenor() <<
81 ") dedicated DailyTenor constructor must be used");
82 QL_REQUIRE(currency!=EURCurrency(),
83 "for EUR Libor dedicated EurLibor constructor must be used");
84 }
85
86 Date Libor::valueDate(const Date& fixingDate) const {
87
88 QL_REQUIRE(isValidFixingDate(fixingDate),
89 "Fixing date " << fixingDate << " is not valid");
90
91 // http://www.bba.org.uk/bba/jsp/polopoly.jsp?d=225&a=1412 :
92 // For all currencies other than EUR and GBP the period between
93 // Fixing Date and Value Date will be two London business days
94 // after the Fixing Date, or if that day is not both a London
95 // business day and a business day in the principal financial centre
96 // of the currency concerned, the next following day which is a
97 // business day in both centres shall be the Value Date.
99 return jointCalendar_.adjust(d);
100 }
101
102 Date Libor::maturityDate(const Date& valueDate) const {
103 // Where a deposit is made on the final business day of a
104 // particular calendar month, the maturity of the deposit shall
105 // be on the final business day of the month in which it matures
106 // (not the corresponding date in the month of maturity). Or in
107 // other words, in line with market convention, BBA LIBOR rates
108 // are dealt on an end-end basis. For instance a one month
109 // deposit for value 28th February would mature on 31st March,
110 // not the 28th of March.
112 endOfMonth());
113 }
114
116 return jointCalendar_;
117 }
118
119 ext::shared_ptr<IborIndex> Libor::clone(
120 const Handle<YieldTermStructure>& h) const {
121 return ext::shared_ptr<IborIndex>(new Libor(familyName(),
122 tenor(),
123 fixingDays(),
124 currency(),
126 dayCounter(),
127 h));
128 }
129
130
132 const std::string& familyName,
133 Natural settlementDays,
134 const Currency& currency,
135 const Calendar& financialCenterCalendar,
136 const DayCounter& dayCounter,
138 : IborIndex(familyName, 1*Days, settlementDays, currency,
139 // http://www.bba.org.uk/bba/jsp/polopoly.jsp?d=225&a=1412 :
140 // no o/n or s/n fixings (as the case may be) will take place
141 // when the principal centre of the currency concerned is
142 // closed but London is open on the fixing day.
144 financialCenterCalendar,
146 liborConvention(1*Days), liborEOM(1*Days),
147 dayCounter, h) {
148 QL_REQUIRE(currency!=EURCurrency(),
149 "for EUR Libor dedicated EurLibor constructor must be used");
150 }
151
152}
calendar class
Definition: calendar.hpp:61
Date adjust(const Date &, BusinessDayConvention convention=Following) const
Definition: calendar.cpp:84
Date advance(const Date &, Integer n, TimeUnit unit, BusinessDayConvention convention=Following, bool endOfMonth=false) const
Definition: calendar.cpp:130
Currency specification
Definition: currency.hpp:36
DailyTenorLibor(const std::string &familyName, Natural settlementDays, const Currency &currency, const Calendar &financialCenterCalendar, const DayCounter &dayCounter, const Handle< YieldTermStructure > &h={})
Definition: libor.cpp:131
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
European Euro.
Definition: europe.hpp:123
Shared handle to an observable.
Definition: handle.hpp:41
base class for Inter-Bank-Offered-Rate indexes (e.g. Libor, etc.)
Definition: iborindex.hpp:35
bool endOfMonth() const
Definition: iborindex.hpp:54
BusinessDayConvention convention_
Definition: iborindex.hpp:65
const DayCounter & dayCounter() const
Calendar fixingCalendar() const override
returns the calendar defining valid fixing dates
const Currency & currency() const
bool isValidFixingDate(const Date &fixingDate) const override
returns TRUE if the fixing date is a valid one
Date fixingDate(const Date &valueDate) const
std::string familyName() const
base class for all ICE LIBOR indexes but the EUR, O/N, and S/N ones
Definition: libor.hpp:38
Libor(const std::string &familyName, const Period &tenor, Natural settlementDays, const Currency &currency, const Calendar &financialCenterCalendar, const DayCounter &dayCounter, const Handle< YieldTermStructure > &h={})
Definition: libor.cpp:60
Date valueDate(const Date &fixingDate) const override
Definition: libor.cpp:86
Date maturityDate(const Date &valueDate) const override
Definition: libor.cpp:102
Calendar jointCalendar_
Definition: libor.hpp:65
Calendar jointCalendar() const
Definition: libor.cpp:115
Calendar financialCenterCalendar_
Definition: libor.hpp:64
ext::shared_ptr< IborIndex > clone(const Handle< YieldTermStructure > &h) const override
returns a copy of itself linked to a different forwarding curve
Definition: libor.cpp:119
United Kingdom calendars.
BusinessDayConvention
Business Day conventions.
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
Definition: any.hpp:35