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
27 BMASwap::BMASwap(Type type,
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)
46 .withNotionals(notional: nominal)
47 .withPaymentDayCounter(liborDayCount)
48 .withPaymentAdjustment(convention)
49 .withFixingDays(fixingDays: liborIndex->fixingDays())
50 .withGearings(gearing: liborFraction)
51 .withSpreads(spread: liborSpread);
52
53 legs_[1] = AverageBMALeg(bmaSchedule, bmaIndex)
54 .withNotionals(notional: nominal)
55 .withPaymentDayCounter(bmaDayCount)
56 .withPaymentAdjustment(bmaSchedule.businessDayConvention());
57
58 for (Size j=0; j<2; ++j) {
59 for (auto& i : legs_[j])
60 registerWith(h: 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
77 Real BMASwap::liborFraction() const {
78 return liborFraction_;
79 }
80
81 Spread BMASwap::liborSpread() const {
82 return liborSpread_;
83 }
84
85 Real BMASwap::nominal() const {
86 return nominal_;
87 }
88
89 Swap::Type BMASwap::type() const {
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
102 Real BMASwap::liborLegBPS() const {
103 calculate();
104 QL_REQUIRE(legBPS_[0] != Null<Real>(), "result not available");
105 return legBPS_[0];
106 }
107
108 Real BMASwap::liborLegNPV() const {
109 calculate();
110 QL_REQUIRE(legNPV_[0] != Null<Real>(), "result not available");
111 return legNPV_[0];
112 }
113
114 Real BMASwap::fairLiborFraction() const {
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
124 Spread BMASwap::fairLiborSpread() const {
125 static Spread basisPoint = 1.0e-4;
126
127 return liborSpread_ - NPV()/(liborLegBPS()/basisPoint);
128 }
129
130 Real BMASwap::bmaLegBPS() const {
131 calculate();
132 QL_REQUIRE(legBPS_[1] != Null<Real>(), "result not available");
133 return legBPS_[1];
134 }
135
136 Real BMASwap::bmaLegNPV() const {
137 calculate();
138 QL_REQUIRE(legNPV_[1] != Null<Real>(), "result not available");
139 return legNPV_[1];
140 }
141
142}
143

source code of quantlib/ql/instruments/bmaswap.cpp

Morty Proxy This is a proxified and sanitized view of the page, visit original site.