QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
bmaindex.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2007 Roland Lichters
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
20#include <ql/indexes/bmaindex.hpp>
21#include <ql/currencies/america.hpp>
22#include <ql/time/calendars/unitedstates.hpp>
23#include <ql/time/daycounters/actualactual.hpp>
24
25namespace QuantLib {
26
27 namespace {
28
29 Date previousWednesday(const Date& date) {
30 Weekday w = date.weekday();
31 if (w >= 4) // roll back w-4 days
32 return date - (w - 4) * Days;
33 else // roll forward 4-w days and back one week
34 return date + (4 - w - 7) * Days;
35 }
36
37 Date nextWednesday(const Date& date) {
38 return previousWednesday(date+7);
39 }
40
41 }
42
44 : InterestRateIndex("BMA",
45 1 * Weeks,
46 1,
48 UnitedStates(UnitedStates::GovernmentBond),
50 termStructure_(h) {
51 registerWith (h);
52 }
53
54 bool BMAIndex::isValidFixingDate(const Date& date) const {
56 // either the fixing date is last Wednesday, or all days
57 // between last Wednesday included and the fixing date are
58 // holidays
59 for (Date d = previousWednesday(date); d<date; ++d) {
60 if (cal.isBusinessDay(d))
61 return false;
62 }
63 // also, the fixing date itself must be a business day
64 return cal.isBusinessDay(date);
65 }
66
68 return termStructure_;
69 }
70
71 Date BMAIndex::maturityDate(const Date& valueDate) const {
74 Date nextWednesday = previousWednesday(fixingDate+7);
75 return cal.advance(nextWednesday, 1, Days);
76 }
77
78 Schedule BMAIndex::fixingSchedule(const Date& start, const Date& end) {
79 return MakeSchedule().from(previousWednesday(start))
80 .to(nextWednesday(end))
84 .forwards();
85 }
86
87 Rate BMAIndex::forecastFixing(const Date& fixingDate) const {
88 QL_REQUIRE(!termStructure_.empty(),
89 "null term structure set to this instance of " << name());
91 Date end = maturityDate(start);
92 return termStructure_->forwardRate(start, end,
94 Simple);
95 }
96
97}
Actual/Actual day count.
Handle< YieldTermStructure > forwardingTermStructure() const
Definition: bmaindex.cpp:67
Date maturityDate(const Date &valueDate) const override
Definition: bmaindex.cpp:71
bool isValidFixingDate(const Date &fixingDate) const override
Definition: bmaindex.cpp:54
Handle< YieldTermStructure > termStructure_
Definition: bmaindex.hpp:64
BMAIndex(const Handle< YieldTermStructure > &h={})
Definition: bmaindex.cpp:43
Rate forecastFixing(const Date &fixingDate) const override
It can be overridden to implement particular conventions.
Definition: bmaindex.cpp:87
Schedule fixingSchedule(const Date &start, const Date &end)
Definition: bmaindex.cpp:78
calendar class
Definition: calendar.hpp:61
bool isBusinessDay(const Date &d) const
Definition: calendar.hpp:223
Date advance(const Date &, Integer n, TimeUnit unit, BusinessDayConvention convention=Following, bool endOfMonth=false) const
Definition: calendar.cpp:130
Concrete date class.
Definition: date.hpp:125
Shared handle to an observable.
Definition: handle.hpp:41
base class for interest rate indexes
Calendar fixingCalendar() const override
returns the calendar defining valid fixing dates
std::string name() const override
Returns the name of the index.
virtual Date valueDate(const Date &fixingDate) const
Date fixingDate(const Date &valueDate) const
MakeSchedule & withConvention(BusinessDayConvention)
Definition: schedule.cpp:557
MakeSchedule & to(const Date &terminationDate)
Definition: schedule.cpp:537
MakeSchedule & from(const Date &effectiveDate)
Definition: schedule.cpp:532
MakeSchedule & withFrequency(Frequency)
Definition: schedule.cpp:547
MakeSchedule & forwards()
Definition: schedule.cpp:573
MakeSchedule & withCalendar(const Calendar &)
Definition: schedule.cpp:552
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
Payment schedule.
Definition: schedule.hpp:40
U.S. dollar.
Definition: america.hpp:162
United States calendars.
@ Weekly
once a week
Definition: frequency.hpp:47
Real Rate
interest rates
Definition: types.hpp:70
Definition: any.hpp:35