QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.38
Loading...
Searching...
No Matches
makearithmeticaverageois.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
23#include <ql/time/schedule.hpp>
24
25namespace QuantLib {
26
28
30 const Period& swapTenor,
31 const ext::shared_ptr<OvernightIndex>& overnightIndex,
32 Rate fixedRate,
33 const Period& forwardStart)
34 : swapTenor_(swapTenor), overnightIndex_(overnightIndex), fixedRate_(fixedRate),
35 forwardStart_(forwardStart),
36
37 calendar_(overnightIndex->fixingCalendar()),
38
39 fixedDayCount_(overnightIndex->dayCounter()) {}
40
41 MakeArithmeticAverageOIS::operator ArithmeticAverageOIS() const {
42 ext::shared_ptr<ArithmeticAverageOIS> ois = *this;
43 return *ois;
44 }
45
46 MakeArithmeticAverageOIS::operator ext::shared_ptr<ArithmeticAverageOIS>() const {
47
48 Date startDate;
49 if (effectiveDate_ != Date())
50 startDate = effectiveDate_;
51 else {
53 // if the evaluation date is not a business day
54 // then move to the next business day
55 refDate = calendar_.adjust(refDate);
56 Date spotDate = calendar_.advance(refDate,
57 settlementDays_*Days);
58 startDate = spotDate+forwardStart_;
59 if (forwardStart_.length()<0)
60 startDate = calendar_.adjust(startDate, Preceding);
61 else
62 startDate = calendar_.adjust(startDate, Following);
63 }
64
65 // OIS end of month default
66 bool usedEndOfMonth =
67 isDefaultEOM_ ? calendar_.isEndOfMonth(startDate) : endOfMonth_;
68
69 Date endDate = terminationDate_;
70 if (endDate == Date()) {
71 if (usedEndOfMonth)
72 endDate = calendar_.advance(startDate,
73 swapTenor_,
75 usedEndOfMonth);
76 else
77 endDate = startDate + swapTenor_;
78 }
79
80 Schedule fixedLegSchedule(startDate, endDate,
81 Period(fixedLegPaymentFrequency_),
82 calendar_,
85 rule_,
86 usedEndOfMonth);
87
88 Schedule overnightLegSchedule(startDate, endDate,
89 Period(overnightLegPaymentFrequency_),
90 calendar_,
93 rule_,
94 usedEndOfMonth);
95
96 Rate usedFixedRate = fixedRate_;
97 if (fixedRate_ == Null<Rate>()) {
98 ArithmeticAverageOIS temp(type_, nominal_,
99 fixedLegSchedule,
100 0.0, // fixed rate
101 fixedDayCount_,
102 overnightIndex_,
103 overnightLegSchedule,
104 overnightSpread_,
105 mrs_, vol_, byApprox_);
106 if (engine_ == nullptr) {
108 overnightIndex_->forwardingTermStructure();
109 QL_REQUIRE(!disc.empty(),
110 "null term structure set to this instance of " <<
111 overnightIndex_->name());
112 bool includeSettlementDateFlows = false;
113 ext::shared_ptr<PricingEngine> engine(new
114 DiscountingSwapEngine(disc, includeSettlementDateFlows));
115 temp.setPricingEngine(engine);
116 } else
118
119 usedFixedRate = temp.fairRate();
120 }
121
122 ext::shared_ptr<ArithmeticAverageOIS> ois(new
123 ArithmeticAverageOIS(type_, nominal_,
124 fixedLegSchedule,
125 usedFixedRate, fixedDayCount_,
126 overnightIndex_,
127 overnightLegSchedule,
128 overnightSpread_,
129 mrs_, vol_, byApprox_));
130
131 if (engine_ == nullptr) {
133 overnightIndex_->forwardingTermStructure();
134 bool includeSettlementDateFlows = false;
135 ext::shared_ptr<PricingEngine> engine(new
136 DiscountingSwapEngine(disc, includeSettlementDateFlows));
137 ois->setPricingEngine(engine);
138 } else
139 ois->setPricingEngine(engine_);
140
141 return ois;
142 }
143
146 return *this;
147 }
148
150 type_ = type;
151 return *this;
152 }
153
155 nominal_ = n;
156 return *this;
157 }
158
160 settlementDays_ = settlementDays;
162 return *this;
163 }
164
166 effectiveDate_ = effectiveDate;
167 return *this;
168 }
169
171 terminationDate_ = terminationDate;
172 swapTenor_ = Period();
173 return *this;
174 }
175
180 return *this;
181 }
182
187 return *this;
188 }
189
191 rule_ = r;
192 if (r==DateGeneration::Zero) {
195 }
196 return *this;
197 }
198
201 bool includeSettlementDateFlows = false;
202 engine_ = ext::shared_ptr<PricingEngine>(new
203 DiscountingSwapEngine(d, includeSettlementDateFlows));
204 return *this;
205 }
206
208 const ext::shared_ptr<PricingEngine>& engine) {
209 engine_ = engine;
210 return *this;
211 }
212
214 fixedDayCount_ = dc;
215 return *this;
216 }
217
219 endOfMonth_ = flag;
220 isDefaultEOM_ = false;
221 return *this;
222 }
223
225 overnightSpread_ = sp;
226 return *this;
227 }
228
230 Real meanReversionSpeed,
231 Real volatility,
232 bool byApprox) {
233 mrs_ = meanReversionSpeed;
234 vol_ = volatility;
235 byApprox_ = byApprox;
236 return *this;
237 }
238
240
241}
ext::shared_ptr< SimpleQuote > vol_
Definition: cdsoption.cpp:62
ext::shared_ptr< PricingEngine > engine_
Definition: cdsoption.cpp:60
Concrete date class.
Definition: date.hpp:125
static bool isEndOfMonth(const Date &d)
whether a date is the last day of its month
Definition: date.hpp:430
static Date advance(const Date &d, Integer units, TimeUnit)
Definition: date.cpp:139
day counter class
Definition: daycounter.hpp:44
Discounting engine for swaps.
Shared handle to an observable.
Definition: handle.hpp:41
bool empty() const
checks if the contained shared pointer points to anything
Definition: handle.hpp:188
void setPricingEngine(const ext::shared_ptr< PricingEngine > &)
set the pricing engine to be used.
Definition: instrument.cpp:35
MakeArithmeticAverageOIS & withOvernightLegSpread(Spread sp)
MakeArithmeticAverageOIS & withType(Swap::Type type)
MakeArithmeticAverageOIS & withEndOfMonth(bool flag=true)
MakeArithmeticAverageOIS & withFixedLegPaymentFrequency(Frequency f)
QL_DEPRECATED_DISABLE_WARNING MakeArithmeticAverageOIS(const Period &swapTenor, const ext::shared_ptr< OvernightIndex > &overnightIndex, Rate fixedRate=Null< Rate >(), const Period &fwdStart=0 *Days)
MakeArithmeticAverageOIS & withEffectiveDate(const Date &)
MakeArithmeticAverageOIS & withArithmeticAverage(Real meanReversionSpeed=0.03, Real volatility=0.00, bool byApprox=false)
MakeArithmeticAverageOIS & withDiscountingTermStructure(const Handle< YieldTermStructure > &discountingTermStructure)
MakeArithmeticAverageOIS & withSettlementDays(Natural settlementDays)
MakeArithmeticAverageOIS & withFixedLegDayCount(const DayCounter &dc)
MakeArithmeticAverageOIS & receiveFixed(bool flag=true)
MakeArithmeticAverageOIS & withOvernightLegPaymentFrequency(Frequency f)
ext::shared_ptr< PricingEngine > engine_
MakeArithmeticAverageOIS & withPricingEngine(const ext::shared_ptr< PricingEngine > &engine)
MakeArithmeticAverageOIS & withNominal(Real n)
MakeArithmeticAverageOIS & withRule(DateGeneration::Rule r)
MakeArithmeticAverageOIS & withTerminationDate(const Date &)
template class providing a null value for a given type.
Definition: null.hpp:59
Payment schedule.
Definition: schedule.hpp:40
DateProxy & evaluationDate()
the date at which pricing is to be performed.
Definition: settings.hpp:147
static Settings & instance()
access to the unique instance
Definition: singleton.hpp:104
discounting swap engine
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
Date d
Frequency
Frequency of events.
Definition: frequency.hpp:37
@ Once
only once, e.g., a zero-coupon
Definition: frequency.hpp:38
QL_REAL Real
real number
Definition: types.hpp:50
unsigned QL_INTEGER Natural
positive integer
Definition: types.hpp:43
Real Spread
spreads on interest rates
Definition: types.hpp:74
Real Rate
interest rates
Definition: types.hpp:70
base class for Inter-Bank-Offered-Rate indexes
Helper class to instantiate overnight indexed swaps.
Definition: any.hpp:37
ext::shared_ptr< YieldTermStructure > r
#define QL_DEPRECATED_DISABLE_WARNING
Definition: qldefines.hpp:216
#define QL_DEPRECATED_ENABLE_WARNING
Definition: qldefines.hpp:217
date schedule