QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
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 Real nominal,
30 Schedule fixedLegSchedule,
31 Rate fixedRate,
32 DayCounter fixedDC,
33 ext::shared_ptr<OvernightIndex> overnightIndex,
34 Schedule overnightLegSchedule,
35 Spread spread,
36 Real meanReversionSpeed,
37 Real volatility,
38 bool byApprox)
39 : Swap(2), type_(type), nominals_(std::vector<Real>(1, nominal)),
40 fixedLegPaymentFrequency_(fixedLegSchedule.tenor().frequency()),
41 overnightLegPaymentFrequency_(overnightLegSchedule.tenor().frequency()),
42 fixedRate_(fixedRate), fixedDC_(std::move(fixedDC)),
43 overnightIndex_(std::move(overnightIndex)), spread_(spread), byApprox_(byApprox),
44 mrs_(meanReversionSpeed), vol_(volatility) {
45
46 initialize(std::move(fixedLegSchedule), std::move(overnightLegSchedule));
47 }
48
50 std::vector<Real> nominals,
51 Schedule fixedLegSchedule,
52 Rate fixedRate,
53 DayCounter fixedDC,
54 ext::shared_ptr<OvernightIndex> overnightIndex,
55 Schedule overnightLegSchedule,
56 Spread spread,
57 Real meanReversionSpeed,
58 Real volatility,
59 bool byApprox)
60 : Swap(2), type_(type), nominals_(std::move(nominals)),
61 fixedLegPaymentFrequency_(fixedLegSchedule.tenor().frequency()),
62 overnightLegPaymentFrequency_(overnightLegSchedule.tenor().frequency()),
63 fixedRate_(fixedRate), fixedDC_(std::move(fixedDC)),
64 overnightIndex_(std::move(overnightIndex)), spread_(spread), byApprox_(byApprox),
65 mrs_(meanReversionSpeed), vol_(volatility) {
66
67 initialize(std::move(fixedLegSchedule), std::move(overnightLegSchedule));
68 }
69
71 Schedule overnightLegSchedule) {
72 if (fixedDC_==DayCounter())
73 fixedDC_ = overnightIndex_->dayCounter();
74 legs_[0] = FixedRateLeg(std::move(fixedLegSchedule))
77
78 legs_[1] = OvernightLeg(std::move(overnightLegSchedule), overnightIndex_)
81
82 ext::shared_ptr<FloatingRateCouponPricer> arithmeticPricer(
84
85 for (auto& i : legs_[1]) {
86 ext::shared_ptr<OvernightIndexedCoupon> c =
87 ext::dynamic_pointer_cast<OvernightIndexedCoupon>(i);
88 c->setPricer(arithmeticPricer);
89 }
90
91 for (Size j=0; j<2; ++j) {
92 for (auto& i : legs_[j])
93 registerWith(i);
94 }
95
96 switch (type_) {
97 case Payer:
98 payer_[0] = -1.0;
99 payer_[1] = +1.0;
100 break;
101 case Receiver:
102 payer_[0] = +1.0;
103 payer_[1] = -1.0;
104 break;
105 default:
106 QL_FAIL("Unknown overnight-swap type");
107 }
108 }
109
111 static Spread basisPoint = 1.0e-4;
112 calculate();
113 return fixedRate_ - NPV_/(fixedLegBPS()/basisPoint);
114 }
115
117 static Spread basisPoint = 1.0e-4;
118 calculate();
119 return spread_ - NPV_/(overnightLegBPS()/basisPoint);
120 }
121
123 calculate();
124 QL_REQUIRE(legBPS_[0] != Null<Real>(), "result not available");
125 return legBPS_[0];
126 }
127
129 calculate();
130 QL_REQUIRE(legBPS_[1] != Null<Real>(), "result not available");
131 return legBPS_[1];
132 }
133
135 calculate();
136 QL_REQUIRE(legNPV_[0] != Null<Real>(), "result not available");
137 return legNPV_[0];
138 }
139
141 calculate();
142 QL_REQUIRE(legNPV_[1] != Null<Real>(), "result not available");
143 return legNPV_[1];
144 }
145
146}
Overnight index swap paying arithmetic average of overnight vs. fixed.
pricer for arithmetically-averaged overnight-indexed coupons
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:76
std::pair< iterator, bool > registerWith(const ext::shared_ptr< Observable > &)
Definition: observable.hpp:228
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:35
STL namespace.
coupon paying the compounded daily overnight rate