Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
bmaindexwrapper.hpp
Go to the documentation of this file.
1/*
2Copyright (C) 2018 Quaternion Risk Management Ltd
3All rights reserved.
4
5This file is part of ORE, a free-software/open-source library
6for transparent pricing and risk analysis - http://opensourcerisk.org
7
8ORE is free software: you can redistribute it and/or modify it
9under the terms of the Modified BSD License. You should have received a
10copy of the license along with this program.
11The license is also available online at <http://opensourcerisk.org>
12
13This program is distributed on the basis that it will form a useful
14contribution to risk analytics and model standardisation, but WITHOUT
15ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19/*! \file bmaindexwrapper.hpp
20\brief wrapper class for bmaindex, for the purpose of providing iborindex inheritance.
21\ingroup indexes
22*/
23
24#ifndef quantext_bma_index_wrapper_hpp
25#define quantext_bma_index_wrapper_hpp
26
27#include <ql/indexes/bmaindex.hpp>
28#include <ql/indexes/iborindex.hpp>
29
30namespace QuantExt {
31using namespace QuantLib;
32
33/*! Wrapper that adapts the quantlib BMAIndex into a class inheriting from IborIndex
34 The purpose of this is twofold:
35 1) we can use Market::iborIndex() to retrieve a BMA index
36 2) we can set up an IborCoupon using this index wrapper to approximate an AveragedBMACoupon
37 at places where a pricer only supports an IborCoupon, e.g. for cap/floors or swaptions on
38 BMA underlyings
39 To make 2) work we tweak the implementations of isValidFixingDate(), maturityDate() and pastFixing()
40 to make sure an Ibor coupon on this index class will behave gracefully. */
41/*!
42\ingroup indexes
43*/
44class BMAIndexWrapper : public IborIndex {
45public:
46 // TODO: fix the day count convention
47 // TODO: fix the end of month
48 BMAIndexWrapper(const QuantLib::ext::shared_ptr<QuantLib::BMAIndex>& bma)
49 : IborIndex(bma->name(), bma->tenor(), bma->fixingDays(), bma->currency(), bma->fixingCalendar(),
50 ModifiedFollowing, false, bma->dayCounter(), bma->forwardingTermStructure()),
51 bma_(bma) {}
52
53 BMAIndexWrapper(const QuantLib::ext::shared_ptr<QuantLib::BMAIndex>& bma, const Handle<YieldTermStructure>& h)
54 : IborIndex(bma->name(), bma->tenor(), bma->fixingDays(), bma->currency(), bma->fixingCalendar(),
55 ModifiedFollowing, false, bma->dayCounter(), h),
56 bma_(new BMAIndex(h)) {}
57
58 // overwrite all the virtual methods
59 std::string name() const override { return bma_->name(); }
60 bool isValidFixingDate(const Date& date) const override {
61 // this is not the original BMA behaviour!
62 return fixingCalendar().isBusinessDay(date);
63 }
64 Handle<YieldTermStructure> forwardingTermStructure() const { return bma_->forwardingTermStructure(); }
65 Date maturityDate(const Date& valueDate) const override {
66 Date d = bma_->maturityDate(valueDate);
67 // make sure that d > valueDate to avoid problems in IborCoupon, this is not the original
68 // BMAIndex behaviour!
69 return std::max<Date>(d, valueDate + 1);
70 }
71 Schedule fixingSchedule(const Date& start, const Date& end) { return bma_->fixingSchedule(start, end); }
72 Rate forecastFixing(const Date& fixingDate) const override {
73 QL_REQUIRE(!termStructure_.empty(), "null term structure set to this instance of " << name());
74 Date start = fixingCalendar().advance(fixingDate, 1, Days);
75 Date end = maturityDate(start);
76 return termStructure_->forwardRate(start, end, dayCounter_, Simple);
77 }
78 // return the last valid BMA fixing date before or on the given fixingDate
79 Date adjustedFixingDate(const Date& fixingDate) const {
80 Date tmp = fixingDate;
81 while (!bma_->isValidFixingDate(tmp) && tmp > Date::minDate())
82 tmp--;
83 return tmp;
84 }
85 Rate pastFixing(const Date& fixingDate) const override {
86 // we allow for fixing dates that are not valid BMA fixing dates, so we need to make sure that we
87 // read a past fixing from a valid BMA fixing date
88 return bma_->fixing(adjustedFixingDate(fixingDate));
89 }
90 QuantLib::ext::shared_ptr<IborIndex> clone(const Handle<YieldTermStructure>& h) const override {
91 return QuantLib::ext::shared_ptr<BMAIndexWrapper>(new BMAIndexWrapper(bma(), h));
92 }
93
94 // do we need these?
95 QuantLib::ext::shared_ptr<QuantLib::BMAIndex> bma() const { return bma_; }
96
97 operator QuantLib::BMAIndex &() { return *bma_; }
98 operator QuantLib::BMAIndex *() { return &*bma_; }
99
100private:
101 QuantLib::ext::shared_ptr<QuantLib::BMAIndex> bma_;
102};
103} // namespace QuantExt
104
105#endif
BMAIndexWrapper(const QuantLib::ext::shared_ptr< QuantLib::BMAIndex > &bma)
Rate pastFixing(const Date &fixingDate) const override
Handle< YieldTermStructure > forwardingTermStructure() const
bool isValidFixingDate(const Date &date) const override
Date maturityDate(const Date &valueDate) const override
QuantLib::ext::shared_ptr< QuantLib::BMAIndex > bma() const
std::string name() const override
BMAIndexWrapper(const QuantLib::ext::shared_ptr< QuantLib::BMAIndex > &bma, const Handle< YieldTermStructure > &h)
QuantLib::ext::shared_ptr< IborIndex > clone(const Handle< YieldTermStructure > &h) const override
Date adjustedFixingDate(const Date &fixingDate) const
Rate forecastFixing(const Date &fixingDate) const override
QuantLib::ext::shared_ptr< QuantLib::BMAIndex > bma_
Schedule fixingSchedule(const Date &start, const Date &end)