QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.38
Loading...
Searching...
No Matches
arithmeticaverageois.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) 2016 Stefano Fondi
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
24#include <utility>
25
26namespace QuantLib {
27
29
31 Real nominal,
32 Schedule fixedLegSchedule,
33 Rate fixedRate,
34 DayCounter fixedDC,
35 ext::shared_ptr<OvernightIndex> overnightIndex,
36 Schedule overnightLegSchedule,
37 Spread spread,
38 Real meanReversionSpeed,
39 Real volatility,
40 bool byApprox)
41 : Swap(2), type_(type), nominals_(std::vector<Real>(1, nominal)),
42 fixedLegPaymentFrequency_(fixedLegSchedule.tenor().frequency()),
43 overnightLegPaymentFrequency_(overnightLegSchedule.tenor().frequency()),
44 fixedRate_(fixedRate), fixedDC_(std::move(fixedDC)),
45 overnightIndex_(std::move(overnightIndex)), spread_(spread), byApprox_(byApprox),
46 mrs_(meanReversionSpeed), vol_(volatility) {
47
48 initialize(std::move(fixedLegSchedule), std::move(overnightLegSchedule));
49 }
50
52 std::vector<Real> nominals,
53 Schedule fixedLegSchedule,
54 Rate fixedRate,
55 DayCounter fixedDC,
56 ext::shared_ptr<OvernightIndex> overnightIndex,
57 Schedule overnightLegSchedule,
58 Spread spread,
59 Real meanReversionSpeed,
60 Real volatility,
61 bool byApprox)
62 : Swap(2), type_(type), nominals_(std::move(nominals)),
63 fixedLegPaymentFrequency_(fixedLegSchedule.tenor().frequency()),
64 overnightLegPaymentFrequency_(overnightLegSchedule.tenor().frequency()),
65 fixedRate_(fixedRate), fixedDC_(std::move(fixedDC)),
66 overnightIndex_(std::move(overnightIndex)), spread_(spread), byApprox_(byApprox),
67 mrs_(meanReversionSpeed), vol_(volatility) {
68
69 initialize(std::move(fixedLegSchedule), std::move(overnightLegSchedule));
70 }
71
73 Schedule overnightLegSchedule) {
74 if (fixedDC_==DayCounter())
75 fixedDC_ = overnightIndex_->dayCounter();
76 legs_[0] = FixedRateLeg(std::move(fixedLegSchedule))
79
80 legs_[1] = OvernightLeg(std::move(overnightLegSchedule), overnightIndex_)
83
84 ext::shared_ptr<FloatingRateCouponPricer> arithmeticPricer(
86
87 for (auto& i : legs_[1]) {
88 ext::shared_ptr<OvernightIndexedCoupon> c =
89 ext::dynamic_pointer_cast<OvernightIndexedCoupon>(i);
90 c->setPricer(arithmeticPricer);
91 }
92
93 for (Size j=0; j<2; ++j) {
94 for (auto& i : legs_[j])
95 registerWith(i);
96 }
97
98 switch (type_) {
99 case Payer:
100 payer_[0] = -1.0;
101 payer_[1] = +1.0;
102 break;
103 case Receiver:
104 payer_[0] = +1.0;
105 payer_[1] = -1.0;
106 break;
107 default:
108 QL_FAIL("Unknown overnight-swap type");
109 }
110 }
111
113 static Spread basisPoint = 1.0e-4;
114 calculate();
115 return fixedRate_ - NPV_/(fixedLegBPS()/basisPoint);
116 }
117
119 static Spread basisPoint = 1.0e-4;
120 calculate();
121 return spread_ - NPV_/(overnightLegBPS()/basisPoint);
122 }
123
125 calculate();
126 QL_REQUIRE(legBPS_[0] != Null<Real>(), "result not available");
127 return legBPS_[0];
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_[0] != Null<Real>(), "result not available");
139 return legNPV_[0];
140 }
141
143 calculate();
144 QL_REQUIRE(legNPV_[1] != Null<Real>(), "result not available");
145 return legNPV_[1];
146 }
147
149
150}
Overnight index swap paying arithmetic average of overnight vs. fixed.
ext::shared_ptr< SimpleQuote > vol_
Definition: cdsoption.cpp:62
ext::shared_ptr< OvernightIndex > overnightIndex_
void initialize(Schedule fixedLegSchedule, Schedule overnightLegSchedule)
ArithmeticAverageOIS(Type type, Real nominal, Schedule fixedLegSchedule, Rate fixedRate, DayCounter fixedDC, ext::shared_ptr< OvernightIndex > overnightIndex, Schedule overnightLegSchedule, Spread spread=0.0, Real meanReversionSpeed=0.03, Real volatility=0.00, bool byApprox=false)
day counter class
Definition: daycounter.hpp:44
helper class building a sequence of fixed rate coupons
FixedRateLeg & withNotionals(Real)
FixedRateLeg & withCouponRates(Rate, const DayCounter &paymentDayCounter, Compounding comp=Simple, Frequency freq=Annual)
void calculate() const override
Definition: instrument.hpp:129
template class providing a null value for a given type.
Definition: null.hpp:59
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:226
helper class building a sequence of overnight coupons
OvernightLeg & withNotionals(Real notional)
OvernightLeg & withSpreads(Spread spread)
Payment schedule.
Definition: schedule.hpp:40
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
Coupon paying a fixed annual rate.
QL_REAL Real
real number
Definition: types.hpp:50
Real Spread
spreads on interest rates
Definition: types.hpp:74
Real Rate
interest rates
Definition: types.hpp:70
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:37
STL namespace.
coupon paying the compounded daily overnight rate
contains the pricer for an OvernightIndexedCoupon
#define QL_DEPRECATED_DISABLE_WARNING
Definition: qldefines.hpp:216
#define QL_DEPRECATED_ENABLE_WARNING
Definition: qldefines.hpp:217