QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
bmaswap.cpp
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) 2007 Roland Lichters
5 Copyright (C) 2007 StatPro Italia srl
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
24
25namespace QuantLib {
26
28 Real nominal,
29 // Libor leg
30 Schedule liborSchedule,
31 Real liborFraction,
32 Spread liborSpread,
33 const ext::shared_ptr<IborIndex>& liborIndex,
34 const DayCounter& liborDayCount,
35 // BMA leg
36 Schedule bmaSchedule,
37 const ext::shared_ptr<BMAIndex>& bmaIndex,
38 const DayCounter& bmaDayCount)
39 : Swap(2), type_(type), nominal_(nominal),
40 liborFraction_(liborFraction), liborSpread_(liborSpread) {
41
42 BusinessDayConvention convention =
43 liborSchedule.businessDayConvention();
44
45 legs_[0] = IborLeg(std::move(liborSchedule), liborIndex)
47 .withPaymentDayCounter(liborDayCount)
48 .withPaymentAdjustment(convention)
49 .withFixingDays(liborIndex->fixingDays())
52
53 auto bmaConvention = bmaSchedule.businessDayConvention();
54
55 legs_[1] = AverageBMALeg(std::move(bmaSchedule), bmaIndex)
57 .withPaymentDayCounter(bmaDayCount)
58 .withPaymentAdjustment(bmaConvention);
59
60 for (Size j=0; j<2; ++j) {
61 for (auto& i : legs_[j])
62 registerWith(i);
63 }
64
65 switch (type_) {
66 case Payer:
67 payer_[0] = +1.0;
68 payer_[1] = -1.0;
69 break;
70 case Receiver:
71 payer_[0] = -1.0;
72 payer_[1] = +1.0;
73 break;
74 default:
75 QL_FAIL("Unknown BMA-swap type");
76 }
77 }
78
80 return liborFraction_;
81 }
82
84 return liborSpread_;
85 }
86
88 return nominal_;
89 }
90
92 return type_;
93 }
94
95 const Leg& BMASwap::liborLeg() const {
96 return legs_[0];
97 }
98
99 const Leg& BMASwap::bmaLeg() const {
100 return legs_[1];
101 }
102
103
105 calculate();
106 QL_REQUIRE(legBPS_[0] != Null<Real>(), "result not available");
107 return legBPS_[0];
108 }
109
111 calculate();
112 QL_REQUIRE(legNPV_[0] != Null<Real>(), "result not available");
113 return legNPV_[0];
114 }
115
117 static Spread basisPoint = 1.0e-4;
118
119 Real spreadNPV = (liborSpread_/basisPoint)*liborLegBPS();
120 Real pureLiborNPV = liborLegNPV() - spreadNPV;
121 QL_REQUIRE(pureLiborNPV != 0.0,
122 "result not available (null libor NPV)");
123 return -liborFraction_ * (bmaLegNPV() + spreadNPV) / pureLiborNPV;
124 }
125
127 static Spread basisPoint = 1.0e-4;
128
129 return liborSpread_ - NPV()/(liborLegBPS()/basisPoint);
130 }
131
133 calculate();
134 QL_REQUIRE(legBPS_[1] != Null<Real>(), "result not available");
135 return legBPS_[1];
136 }
137
139 calculate();
140 QL_REQUIRE(legNPV_[1] != Null<Real>(), "result not available");
141 return legNPV_[1];
142 }
143
144}
coupon paying a weighted average of BMA-index fixings
swap paying Libor against BMA coupons
helper class building a sequence of average BMA coupons
AverageBMALeg & withPaymentDayCounter(const DayCounter &)
AverageBMALeg & withPaymentAdjustment(BusinessDayConvention)
AverageBMALeg & withNotionals(Real notional)
Real bmaLegNPV() const
Definition: bmaswap.cpp:138
Real liborFraction() const
Definition: bmaswap.cpp:79
Spread fairLiborSpread() const
Definition: bmaswap.cpp:126
Real liborLegNPV() const
Definition: bmaswap.cpp:110
Rate fairLiborFraction() const
Definition: bmaswap.cpp:116
const Leg & bmaLeg() const
Definition: bmaswap.cpp:99
Type type() const
"Payer" or "Receiver" refers to the BMA leg
Definition: bmaswap.cpp:91
Real liborLegBPS() const
Definition: bmaswap.cpp:104
Real nominal() const
Definition: bmaswap.cpp:87
Spread liborSpread() const
Definition: bmaswap.cpp:83
Real bmaLegBPS() const
Definition: bmaswap.cpp:132
const Leg & liborLeg() const
Definition: bmaswap.cpp:95
BMASwap(Type type, Real nominal, Schedule liborSchedule, Rate liborFraction, Rate liborSpread, const ext::shared_ptr< IborIndex > &liborIndex, const DayCounter &liborDayCount, Schedule bmaSchedule, const ext::shared_ptr< BMAIndex > &bmaIndex, const DayCounter &bmaDayCount)
Definition: bmaswap.cpp:27
day counter class
Definition: daycounter.hpp:44
helper class building a sequence of capped/floored ibor-rate coupons
Definition: iborcoupon.hpp:134
IborLeg & withSpreads(Spread spread)
Definition: iborcoupon.cpp:212
IborLeg & withPaymentAdjustment(BusinessDayConvention)
Definition: iborcoupon.cpp:177
IborLeg & withPaymentDayCounter(const DayCounter &)
Definition: iborcoupon.cpp:172
IborLeg & withNotionals(Real notional)
Definition: iborcoupon.cpp:162
IborLeg & withGearings(Real gearing)
Definition: iborcoupon.cpp:202
IborLeg & withFixingDays(Natural fixingDays)
Definition: iborcoupon.cpp:192
Real NPV() const
returns the net present value of the instrument.
Definition: instrument.hpp:167
void calculate() const override
Definition: instrument.hpp:129
template class providing a null value for a given type.
Definition: null.hpp:76
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
Payment schedule.
Definition: schedule.hpp:40
BusinessDayConvention businessDayConvention() const
Definition: schedule.hpp:196
Interest rate swap.
Definition: swap.hpp:41
std::vector< Leg > legs_
Definition: swap.hpp:133
std::vector< Real > legNPV_
Definition: swap.hpp:135
std::vector< Real > legBPS_
Definition: swap.hpp:136
std::vector< Real > payer_
Definition: swap.hpp:134
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
#define QL_FAIL(message)
throw an error (possibly with file and line information)
Definition: errors.hpp:92
BusinessDayConvention
Business Day conventions.
QL_REAL Real
real number
Definition: types.hpp:50
Real Spread
spreads on interest rates
Definition: types.hpp:74
std::size_t Size
size of a container
Definition: types.hpp:58
Coupon paying a Libor-type index.
Definition: any.hpp:35
std::vector< ext::shared_ptr< CashFlow > > Leg
Sequence of cash-flows.
Definition: cashflow.hpp:78