Logo Search packages:      
Sourcecode: quantlib version File versions  Download package


/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

 Copyright (C) 2007 Roland Lichters

 This file is part of QuantLib, a free-software/open-source library
 for financial quantitative analysts and developers - http://quantlib.org/

 QuantLib is free software: you can redistribute it and/or modify it
 under the terms of the QuantLib license.  You should have received a
 copy of the license along with this program; if not, please email
 <quantlib-dev@lists.sf.net>. The license is also available online at

 This program is distributed in the hope that it will be useful, but WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 FOR A PARTICULAR PURPOSE.  See the license for more details.

#include <ql/indexes/bmaindex.hpp>
#include <ql/currencies/america.hpp>
#include <ql/time/calendars/unitedstates.hpp>
#include <ql/time/daycounters/actualactual.hpp>

namespace QuantLib {

    namespace {

        Date previousWednesday(const Date& date) {
            Weekday w = date.weekday();
            if (w >= 4) // roll back w-4 days
                return date - (w - 4) * Days;
            else // roll forward 4-w days and back one week
                return date + (4 - w - 7) * Days;

        Date nextWednesday(const Date& date) {
            return previousWednesday(date+7);


    BMAIndex::BMAIndex(const Handle<YieldTermStructure>& h)
    : InterestRateIndex("BMA",
                        1 * Weeks,
      termStructure_(h) {
        registerWith (h);

00055     std::string BMAIndex::name() const {
        return "BMA";

00059     bool BMAIndex::isValidFixingDate(const Date& fixingDate) const {
        // either the fixing date is last Wednesday, or all days
        // between last Wednesday included and the fixing date are
        // holidays
        for (Date d = previousWednesday(fixingDate); d < fixingDate; ++d) {
            if (fixingCalendar_.isBusinessDay(d))
                return false;
        // also, the fixing date itself must be a business day
        return fixingCalendar_.isBusinessDay(fixingDate);

    Handle<YieldTermStructure> BMAIndex::forwardingTermStructure() const {
        return termStructure_;

    Date BMAIndex::maturityDate(const Date& valueDate) const {
        Date fixingDate = fixingCalendar_.advance(valueDate,-1,Days);
        Date nextWednesday = previousWednesday(fixingDate+7);
        return fixingCalendar_.advance(nextWednesday,1,Days);

00081     Schedule BMAIndex::fixingSchedule(const Date& start, const Date& end) {
        return MakeSchedule().from(previousWednesday(start))

    Rate BMAIndex::forecastFixing(const Date& fixingDate) const {
                   "null term structure set to this instance of " << name());
        Date start = fixingCalendar_.advance(fixingDate,1,Days);
        Date end = maturityDate(start);
        return termStructure_->forwardRate(start, end,


Generated by  Doxygen 1.6.0   Back to index