QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
bmaswap.cpp
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
21#include <ql/instruments/bmaswap.hpp>
22#include <ql/cashflows/iborcoupon.hpp>
23#include <ql/cashflows/averagebmacoupon.hpp>
24
25namespace QuantLib {
26
28 Real nominal,
29 // Libor leg
30 const Schedule& liborSchedule,
31 Real liborFraction,
32 Spread liborSpread,
33 const ext::shared_ptr<IborIndex>& liborIndex,
34 const DayCounter& liborDayCount,
35 // BMA leg
36 const 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(liborSchedule, liborIndex)
47 .withPaymentDayCounter(liborDayCount)
48 .withPaymentAdjustment(convention)
49 .withFixingDays(liborIndex->fixingDays())
52
53 legs_[1] = AverageBMALeg(bmaSchedule, bmaIndex)
55 .withPaymentDayCounter(bmaDayCount)
57
58 for (Size j=0; j<2; ++j) {
59 for (auto& i : legs_[j])
60 registerWith(i);
61 }
62
63 switch (type_) {
64 case Payer:
65 payer_[0] = +1.0;
66 payer_[1] = -1.0;
67 break;
68 case Receiver:
69 payer_[0] = -1.0;
70 payer_[1] = +1.0;
71 break;
72 default:
73 QL_FAIL("Unknown BMA-swap type");
74 }
75 }
76
78 return liborFraction_;
79 }
80
82 return liborSpread_;
83 }
84
86 return nominal_;
87 }
88
90 return type_;
91 }
92
93 const Leg& BMASwap::liborLeg() const {
94 return legs_[0];
95 }
96
97 const Leg& BMASwap::bmaLeg() const {
98 return legs_[1];
99 }
100
101
103 calculate();
104 QL_REQUIRE(legBPS_[0] != Null<Real>(), "result not available");
105 return legBPS_[0];
106 }
107
109 calculate();
110 QL_REQUIRE(legNPV_[0] != Null<Real>(), "result not available");
111 return legNPV_[0];
112 }
113
115 static Spread basisPoint = 1.0e-4;
116
117 Real spreadNPV = (liborSpread_/basisPoint)*liborLegBPS();
118 Real pureLiborNPV = liborLegNPV() - spreadNPV;
119 QL_REQUIRE(pureLiborNPV != 0.0,
120 "result not available (null libor NPV)");
121 return -liborFraction_ * (bmaLegNPV() + spreadNPV) / pureLiborNPV;
122 }
123
125 static Spread basisPoint = 1.0e-4;
126
127 return liborSpread_ - NPV()/(liborLegBPS()/basisPoint);
128 }
129
131 calculate();
132 QL_REQUIRE(legBPS_[1] != Null<Real>(), "result not available");
133 return legBPS_[1];
134 }
135
137 calculate();
138 QL_REQUIRE(legNPV_[1] != Null<Real>(), "result not available");
139 return legNPV_[1];
140 }
141
142}
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:136
Real liborFraction() const
Definition: bmaswap.cpp:77
Spread fairLiborSpread() const
Definition: bmaswap.cpp:124
Real liborLegNPV() const
Definition: bmaswap.cpp:108
Rate fairLiborFraction() const
Definition: bmaswap.cpp:114
const Leg & bmaLeg() const
Definition: bmaswap.cpp:97
Type type() const
"Payer" or "Receiver" refers to the BMA leg
Definition: bmaswap.cpp:89
Real liborLegBPS() const
Definition: bmaswap.cpp:102
Real nominal() const
Definition: bmaswap.cpp:85
Spread liborSpread() const
Definition: bmaswap.cpp:81
Real bmaLegBPS() const
Definition: bmaswap.cpp:130
BMASwap(Type type, Real nominal, const Schedule &liborSchedule, Rate liborFraction, Rate liborSpread, const ext::shared_ptr< IborIndex > &liborIndex, const DayCounter &liborDayCount, const Schedule &bmaSchedule, const ext::shared_ptr< BMAIndex > &bmaIndex, const DayCounter &bmaDayCount)
Definition: bmaswap.cpp:27
const Leg & liborLeg() const
Definition: bmaswap.cpp:93
day counter class
Definition: daycounter.hpp:44
helper class building a sequence of capped/floored ibor-rate coupons
Definition: iborcoupon.hpp:133
IborLeg & withSpreads(Spread spread)
Definition: iborcoupon.cpp:208
IborLeg & withPaymentAdjustment(BusinessDayConvention)
Definition: iborcoupon.cpp:173
IborLeg & withPaymentDayCounter(const DayCounter &)
Definition: iborcoupon.cpp:168
IborLeg & withNotionals(Real notional)
Definition: iborcoupon.cpp:158
IborLeg & withGearings(Real gearing)
Definition: iborcoupon.cpp:198
IborLeg & withFixingDays(Natural fixingDays)
Definition: iborcoupon.cpp:188
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
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
Definition: any.hpp:35
std::vector< ext::shared_ptr< CashFlow > > Leg
Sequence of cash-flows.
Definition: cashflow.hpp:78