QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
zerocouponswap.hpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2021 Marcin Rybacki
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/*! \file zerocouponswap.hpp
21 \brief Zero-coupon interest rate swap
22 */
23
24#ifndef quantlib_zerocouponswap_hpp
25#define quantlib_zerocouponswap_hpp
26
28#include <ql/time/calendar.hpp>
30
31namespace QuantLib {
32 class IborIndex;
33
34 //! Zero-coupon interest rate swap
35 /*! Quoted in terms of a known fixed cash flow \f$ N^{FIX} \f$ or
36 a fixed rate \f$ R \f$, where:
37 \f[
38 N^{FIX} = N \left[ (1+R)^{\alpha(T_{0}, T_{K})}-1 \right] ,
39 \f]
40 with \f$ \alpha(T_{0}, T_{K}) \f$ being the time fraction
41 between the start date of the contract \f$ T_{0} \f$ and
42 the end date \f$ T_{K} \f$ - according to a given day count
43 convention. \f$ N \f$ is the base notional amount prior to
44 compounding.
45 The floating leg also pays a single cash flow \f$ N^{FLT} \f$,
46 which value is determined by periodically averaging (e.g. every
47 6 months) interest rate index fixings.
48 Assuming the use of compounded averaging the projected value of
49 the floating leg becomes:
50 \f[
51 N^{FLT} = N \left[ \prod_{k=0}^{K-1} (1+\alpha(T_{k},T_{k+1})
52 L(T_{k},T_{k+1})) -1 \right],
53 \f]
54 where \f$ L(T_{i}, T_{j})) \f$ are interest rate index fixings
55 for accrual period \f$ [T_{i}, T_{j}] \f$.
56 For a par contract, it holds that:
57 \f[
58 P_n(0,T) N^{FIX} = P_n(0,T) N^{FLT}
59 \f]
60 where \f$ T \f$ is the final payment time, \f$ P_n(0,t) \f$
61 is the nominal discount factor at time \f$ t \f$.
62
63 At maturity the two single cashflows are swapped.
64
65 \note we do not need Schedules on the legs because they use
66 one or two dates only per leg. Those dates are not
67 adjusted for potential non-business days. Only the
68 payment date is subject to adjustment.
69 */
70
71 class ZeroCouponSwap : public Swap {
72 public:
75 const Date& startDate,
76 const Date& maturityDate,
78 ext::shared_ptr<IborIndex> iborIndex,
79 const Calendar& paymentCalendar,
80 BusinessDayConvention paymentConvention = Following,
81 Natural paymentDelay = 0);
82
85 const Date& startDate,
86 const Date& maturityDate,
87 Rate fixedRate,
88 const DayCounter& fixedDayCounter,
89 ext::shared_ptr<IborIndex> iborIndex,
90 const Calendar& paymentCalendar,
91 BusinessDayConvention paymentConvention = Following,
92 Natural paymentDelay = 0);
93
94 //! \name Inspectors
95 //@{
96 //! "payer" or "receiver" refer to the fixed leg.
97 Type type() const { return type_; }
98 Real baseNominal() const { return baseNominal_; }
99 Date startDate() const override { return startDate_; }
100 Date maturityDate() const override { return maturityDate_; }
101 const ext::shared_ptr<IborIndex>& iborIndex() const { return iborIndex_; }
102
103 //! just one cashflow in each leg
104 const Leg& fixedLeg() const;
105 //! just one cashflow in each leg
106 const Leg& floatingLeg() const;
107
108 Real fixedPayment() const;
109 //@}
110
111 //! \name Results
112 //@{
113 Real fixedLegNPV() const;
114 Real floatingLegNPV() const;
115 Real fairFixedPayment() const;
116 Rate fairFixedRate(const DayCounter& dayCounter) const;
117 //@}
118
119 private:
122 const Date& startDate,
123 const Date& maturityDate,
124 ext::shared_ptr<IborIndex> iborIndex,
125 const Calendar& paymentCalendar,
126 BusinessDayConvention paymentConvention,
127 Natural paymentDelay);
128
131 ext::shared_ptr<IborIndex> iborIndex_;
135 };
136}
137
138#endif
calendar class
calendar class
Definition: calendar.hpp:61
Concrete date class.
Definition: date.hpp:125
day counter class
Definition: daycounter.hpp:44
Interest rate swap.
Definition: swap.hpp:41
Zero-coupon interest rate swap.
Rate fairFixedRate(const DayCounter &dayCounter) const
const Leg & floatingLeg() const
just one cashflow in each leg
Date startDate() const override
ext::shared_ptr< IborIndex > iborIndex_
const ext::shared_ptr< IborIndex > & iborIndex() const
const Leg & fixedLeg() const
just one cashflow in each leg
Date maturityDate() const override
Type type() const
"payer" or "receiver" refer to the fixed leg.
day counter class
BusinessDayConvention
Business Day conventions.
QL_REAL Real
real number
Definition: types.hpp:50
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
Real Rate
interest rates
Definition: types.hpp:70
Definition: any.hpp:35
std::vector< ext::shared_ptr< CashFlow > > Leg
Sequence of cash-flows.
Definition: cashflow.hpp:78
Interest rate swap.