Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
indexedcoupon.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2020 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19/*! \file qle/cashflows/indexedcoupon.hpp
20 \brief coupon with an indexed notional
21 \ingroup cashflows
22*/
23
24#ifndef quantext_indexed_coupon_hpp
25#define quantext_indexed_coupon_hpp
26
27#include <ql/cashflows/coupon.hpp>
28#include <ql/index.hpp>
29#include <ql/time/schedule.hpp>
30
31namespace QuantExt {
32using namespace QuantLib;
33
34//! indexed coupon
35/*!
36 \ingroup cashflows
37*/
38class IndexedCoupon : public Coupon, public Observer {
39public:
40 /*! pays c->amount() * qty * index(fixingDate) */
41 IndexedCoupon(const QuantLib::ext::shared_ptr<Coupon>& c, const Real qty, const QuantLib::ext::shared_ptr<Index>& index,
42 const Date& fixingDate);
43 /*! pays c->amount() * qty * initialFixing */
44 IndexedCoupon(const QuantLib::ext::shared_ptr<Coupon>& c, const Real qty, const Real initialFixing);
45
46 //! \name Observer interface
47 //@{
48 void update() override;
49 //@}
50
51 //! \name Coupon interface
52 //@{
53 Real amount() const override;
54 Real nominal() const override;
55 Real rate() const override;
56 DayCounter dayCounter() const override;
57 Real accruedAmount(const Date& d) const override;
58 //@}
59
60 //! \name Inspectors
61 //@{
62 QuantLib::ext::shared_ptr<Coupon> underlying() const;
63 Real quantity() const;
64 QuantLib::ext::shared_ptr<Index> index() const; // might be null
65 const Date& fixingDate() const; // might be null
66 Real initialFixing() const; // might be null
67 Real multiplier() const;
68 //@}
69
70 //! \name Visitability
71 //@{
72 void accept(AcyclicVisitor&) override;
73 //@}
74
75private:
76 QuantLib::ext::shared_ptr<Coupon> c_;
77 Real qty_;
78 QuantLib::ext::shared_ptr<Index> index_;
81};
82
83//! indexed cashflow
84/*!
85 \ingroup cashflows
86*/
87class IndexWrappedCashFlow : public CashFlow, public Observer {
88public:
89 /*! pays c->amount() * qty * index(fixingDate) */
90 IndexWrappedCashFlow(const QuantLib::ext::shared_ptr<CashFlow>& c, const Real qty, const QuantLib::ext::shared_ptr<Index>& index,
91 const Date& fixingDate);
92 /*! pays c->amount() * qty * initialFixing */
93 IndexWrappedCashFlow(const QuantLib::ext::shared_ptr<CashFlow>& c, const Real qty, const Real initialFixing);
94
95 //! \name Observer interface
96 //@{
97 void update() override;
98 //@}
99
100 //! \name Cashflow interface
101 //@{
102 Date date() const override;
103 Real amount() const override;
104 //@}
105
106 //! \name Inspectors
107 //@{
108 QuantLib::ext::shared_ptr<CashFlow> underlying() const;
109 Real quantity() const;
110 QuantLib::ext::shared_ptr<Index> index() const; // might be null
111 const Date& fixingDate() const; // might be null
112 Real initialFixing() const; // might be null
113 Real multiplier() const;
114 //@}
115
116 //! \name Visitability
117 //@{
118 void accept(AcyclicVisitor&) override;
119 //@}
120
121private:
122 QuantLib::ext::shared_ptr<CashFlow> c_;
123 Real qty_;
124 QuantLib::ext::shared_ptr<Index> index_;
127
128};
129
130// if c casts to Coupon, unpack an indexed coupon, otherwise an index-wrapped cashflow
131QuantLib::ext::shared_ptr<CashFlow> unpackIndexedCouponOrCashFlow(const QuantLib::ext::shared_ptr<CashFlow>& c);
132
133// remove all index wrappers around a coupon
134QuantLib::ext::shared_ptr<Coupon> unpackIndexedCoupon(const QuantLib::ext::shared_ptr<Coupon>& c);
135
136// remove all index wrappers around a cashflow
137QuantLib::ext::shared_ptr<CashFlow> unpackIndexWrappedCashFlow(const QuantLib::ext::shared_ptr<CashFlow>& c);
138
139// get cumulated multiplier for indexed coupon or cashflow
140Real getIndexedCouponOrCashFlowMultiplier(const QuantLib::ext::shared_ptr<CashFlow>& c);
141
142// get all fixingDates / indices / multipliers for indexed coupon or index-wrapped cashflow
143std::vector<std::tuple<Date, QuantLib::ext::shared_ptr<Index>, Real>>
144getIndexedCouponOrCashFlowFixingDetails(const QuantLib::ext::shared_ptr<CashFlow>& c);
145
146//! indexed coupon leg
147/*!
148 \ingroup cashflows
149*/
151public:
152 IndexedCouponLeg(const Leg& underlyingLeg, const Real qty, const QuantLib::ext::shared_ptr<Index>& index);
153 IndexedCouponLeg& withInitialFixing(const Real initialFixing);
154 IndexedCouponLeg& withInitialNotionalFixing(const Real initialNotionalFixing);
155 IndexedCouponLeg& withValuationSchedule(const Schedule& valuationSchedule);
156 IndexedCouponLeg& withFixingDays(const Size fixingDays);
157 IndexedCouponLeg& withFixingCalendar(const Calendar& fixingCalendar);
158 IndexedCouponLeg& withFixingConvention(const BusinessDayConvention& fixingConvention);
160
161 operator Leg() const;
162
163private:
164 const Leg underlyingLeg_;
165 const Real qty_;
166 const QuantLib::ext::shared_ptr<Index> index_;
172 BusinessDayConvention fixingConvention_;
174};
175
176} // namespace QuantExt
177
178#endif
QuantLib::ext::shared_ptr< Index > index() const
QuantLib::ext::shared_ptr< Index > index_
Real amount() const override
void accept(AcyclicVisitor &) override
QuantLib::ext::shared_ptr< CashFlow > c_
QuantLib::ext::shared_ptr< CashFlow > underlying() const
Date date() const override
const Date & fixingDate() const
QuantLib::ext::shared_ptr< Index > index() const
void update() override
QuantLib::ext::shared_ptr< Index > index_
Real amount() const override
void accept(AcyclicVisitor &) override
Real nominal() const override
DayCounter dayCounter() const override
QuantLib::ext::shared_ptr< Coupon > underlying() const
QuantLib::ext::shared_ptr< Coupon > c_
const Date & fixingDate() const
Real accruedAmount(const Date &d) const override
Real rate() const override
IndexedCouponLeg & withInitialNotionalFixing(const Real initialNotionalFixing)
BusinessDayConvention fixingConvention_
IndexedCouponLeg & withFixingCalendar(const Calendar &fixingCalendar)
IndexedCouponLeg & inArrearsFixing(const bool inArrearsFixing=true)
IndexedCouponLeg & withInitialFixing(const Real initialFixing)
IndexedCouponLeg & withFixingDays(const Size fixingDays)
IndexedCouponLeg & withValuationSchedule(const Schedule &valuationSchedule)
IndexedCouponLeg & withFixingConvention(const BusinessDayConvention &fixingConvention)
const QuantLib::ext::shared_ptr< Index > index_
std::vector< std::tuple< Date, QuantLib::ext::shared_ptr< Index >, Real > > getIndexedCouponOrCashFlowFixingDetails(const QuantLib::ext::shared_ptr< CashFlow > &c)
QuantLib::ext::shared_ptr< Coupon > unpackIndexedCoupon(const QuantLib::ext::shared_ptr< Coupon > &c)
QuantLib::ext::shared_ptr< CashFlow > unpackIndexWrappedCashFlow(const QuantLib::ext::shared_ptr< CashFlow > &c)
Real getIndexedCouponOrCashFlowMultiplier(const QuantLib::ext::shared_ptr< CashFlow > &c)
QuantLib::ext::shared_ptr< CashFlow > unpackIndexedCouponOrCashFlow(const QuantLib::ext::shared_ptr< CashFlow > &c)