/src/quantlib/ql/indexes/ibor/eurlibor.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | |
7 | | This file is part of QuantLib, a free-software/open-source library |
8 | | for financial quantitative analysts and developers - http://quantlib.org/ |
9 | | |
10 | | QuantLib is free software: you can redistribute it and/or modify it |
11 | | under the terms of the QuantLib license. You should have received a |
12 | | copy of the license along with this program; if not, please email |
13 | | <quantlib-dev@lists.sf.net>. The license is also available online at |
14 | | <http://quantlib.org/license.shtml>. |
15 | | |
16 | | This program is distributed in the hope that it will be useful, but WITHOUT |
17 | | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
18 | | FOR A PARTICULAR PURPOSE. See the license for more details. |
19 | | */ |
20 | | |
21 | | #include <ql/indexes/ibor/eurlibor.hpp> |
22 | | #include <ql/time/calendars/jointcalendar.hpp> |
23 | | #include <ql/time/calendars/target.hpp> |
24 | | #include <ql/time/calendars/unitedkingdom.hpp> |
25 | | #include <ql/time/daycounters/actual360.hpp> |
26 | | #include <ql/currencies/europe.hpp> |
27 | | |
28 | | namespace QuantLib { |
29 | | |
30 | | namespace { |
31 | | |
32 | 0 | BusinessDayConvention eurliborConvention(const Period& p) { |
33 | 0 | switch (p.units()) { |
34 | 0 | case Days: |
35 | 0 | case Weeks: |
36 | 0 | return Following; |
37 | 0 | case Months: |
38 | 0 | case Years: |
39 | 0 | return ModifiedFollowing; |
40 | 0 | default: |
41 | 0 | QL_FAIL("invalid time units"); |
42 | 0 | } |
43 | 0 | } |
44 | | |
45 | 0 | bool eurliborEOM(const Period& p) { |
46 | 0 | switch (p.units()) { |
47 | 0 | case Days: |
48 | 0 | case Weeks: |
49 | 0 | return false; |
50 | 0 | case Months: |
51 | 0 | case Years: |
52 | 0 | return true; |
53 | 0 | default: |
54 | 0 | QL_FAIL("invalid time units"); |
55 | 0 | } |
56 | 0 | } |
57 | | |
58 | | } |
59 | | |
60 | | EURLibor::EURLibor(const Period& tenor, |
61 | | const Handle<YieldTermStructure>& h) |
62 | 0 | : IborIndex("EURLibor", tenor, |
63 | 0 | 2, |
64 | 0 | EURCurrency(), |
65 | | // http://www.bba.org.uk/bba/jsp/polopoly.jsp?d=225&a=1412 : |
66 | | // JoinHolidays is the fixing calendar for |
67 | | // all indexes but o/n |
68 | 0 | JointCalendar(UnitedKingdom(UnitedKingdom::Exchange), |
69 | 0 | TARGET(), |
70 | 0 | JoinHolidays), |
71 | 0 | eurliborConvention(tenor), eurliborEOM(tenor), |
72 | 0 | Actual360(), h), |
73 | 0 | target_(TARGET()) { |
74 | 0 | QL_REQUIRE(this->tenor().units()!=Days, |
75 | 0 | "for daily tenors (" << this->tenor() << |
76 | 0 | ") dedicated DailyTenor constructor must be used"); |
77 | 0 | } |
78 | | |
79 | 0 | Date EURLibor::fixingDate(const Date& valueDate) const { |
80 | 0 | return fixingCalendar().adjust( |
81 | 0 | target_.advance(valueDate, -static_cast<Integer>(fixingDays_), Days), |
82 | 0 | Preceding); |
83 | 0 | } |
84 | | |
85 | 0 | Date EURLibor::valueDate(const Date& fixingDate) const { |
86 | |
|
87 | 0 | QL_REQUIRE(isValidFixingDate(fixingDate), |
88 | 0 | "Fixing date " << fixingDate << " is not valid"); |
89 | | |
90 | | // http://www.bba.org.uk/bba/jsp/polopoly.jsp?d=225&a=1412 : |
91 | | // In the case of EUR the Value Date shall be two TARGET |
92 | | // business days after the Fixing Date. |
93 | 0 | return target_.advance(fixingDate, fixingDays_, Days); |
94 | 0 | } |
95 | | |
96 | 0 | Date EURLibor::maturityDate(const Date& valueDate) const { |
97 | | // http://www.bba.org.uk/bba/jsp/polopoly.jsp?d=225&a=1412 : |
98 | | // In the case of EUR only, maturity dates will be based on days in |
99 | | // which the Target system is open. |
100 | 0 | return target_.advance(valueDate, tenor_, convention_, endOfMonth()); |
101 | 0 | } |
102 | | |
103 | 0 | ext::shared_ptr<IborIndex> EURLibor::clone(const Handle<YieldTermStructure>& h) const { |
104 | 0 | return ext::make_shared<EURLibor>(tenor(), h); |
105 | 0 | } |
106 | | |
107 | | DailyTenorEURLibor::DailyTenorEURLibor(Natural settlementDays, |
108 | | const Handle<YieldTermStructure>& h) |
109 | 0 | : IborIndex("EURLibor", 1*Days, |
110 | 0 | settlementDays, |
111 | 0 | EURCurrency(), |
112 | | // http://www.bba.org.uk/bba/jsp/polopoly.jsp?d=225&a=1412 : |
113 | | // no o/n or s/n fixings (as the case may be) will take place |
114 | | // when the principal centre of the currency concerned is |
115 | | // closed but London is open on the fixing day. |
116 | 0 | TARGET(), |
117 | 0 | eurliborConvention(1*Days), eurliborEOM(1*Days), |
118 | 0 | Actual360(), h) {} |
119 | | |
120 | | } |