Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
makeaverageois.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2016 Quaternion Risk Management Ltd
3 All rights reserved.
4
5 This file is part of ORE, a free-software/open-source library
6 for transparent pricing and risk analysis - http://opensourcerisk.org
7
8 ORE is free software: you can redistribute it and/or modify it
9 under the terms of the Modified BSD License. You should have received a
10 copy of the license along with this program.
11 The license is also available online at <http://opensourcerisk.org>
12
13 This program is distributed on the basis that it will form a useful
14 contribution to risk analytics and model standardisation, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
17*/
18
19#include <ql/pricingengines/swap/discountingswapengine.hpp>
20#include <ql/time/calendars/weekendsonly.hpp>
21
23
24namespace QuantExt {
25
26MakeAverageOIS::MakeAverageOIS(const Period& swapTenor, const QuantLib::ext::shared_ptr<OvernightIndex>& overnightIndex,
27 const Period& onTenor, Rate fixedRate, const Period& fixedTenor,
28 const DayCounter& fixedDayCounter, const Period& spotLagTenor,
29 const Period& forwardStart)
30 : swapTenor_(swapTenor), overnightIndex_(overnightIndex), onTenor_(onTenor), fixedRate_(fixedRate),
31 fixedTenor_(fixedTenor), fixedDayCounter_(fixedDayCounter), spotLagTenor_(spotLagTenor),
32 forwardStart_(forwardStart), type_(AverageOIS::Receiver), nominal_(1.0), effectiveDate_(Date()),
33 spotLagCalendar_(overnightIndex->fixingCalendar()), fixedCalendar_(WeekendsOnly()), fixedConvention_(Unadjusted),
34 fixedTerminationDateConvention_(Unadjusted), fixedRule_(DateGeneration::Backward), fixedEndOfMonth_(false),
35 fixedFirstDate_(Date()), fixedNextToLastDate_(Date()),
36 fixedPaymentAdjustment_(overnightIndex->businessDayConvention()),
37 fixedPaymentCalendar_(overnightIndex->fixingCalendar()), onCalendar_(overnightIndex->fixingCalendar()),
38 onConvention_(overnightIndex->businessDayConvention()),
39 onTerminationDateConvention_(overnightIndex->businessDayConvention()), onRule_(DateGeneration::Backward),
40 onEndOfMonth_(false), onFirstDate_(Date()), onNextToLastDate_(Date()), rateCutoff_(0), onSpread_(0.0),
41 onGearing_(1.0), onDayCounter_(overnightIndex->dayCounter()),
42 onPaymentAdjustment_(overnightIndex->businessDayConvention()),
43 onPaymentCalendar_(overnightIndex->fixingCalendar()), telescopicValueDates_(false),
44 onCouponPricer_(QuantLib::ext::make_shared<AverageONIndexedCouponPricer>()) {}
45
46MakeAverageOIS::operator AverageOIS() const {
47 QuantLib::ext::shared_ptr<AverageOIS> swap = *this;
48 return *swap;
49}
50
51MakeAverageOIS::operator QuantLib::ext::shared_ptr<AverageOIS>() const {
52
53 // Deduce the effective date if it is not given.
54 Date effectiveDate;
55 if (effectiveDate_ != Date()) {
56 effectiveDate = effectiveDate_;
57 } else {
58 Date valuationDate = Settings::instance().evaluationDate();
59 // if the evaluation date is not a business day
60 // then move to the next business day
61 valuationDate = spotLagCalendar_.adjust(valuationDate);
62 Date spotDate = spotLagCalendar_.advance(valuationDate, spotLagTenor_);
63 effectiveDate = spotDate + forwardStart_;
64 }
65
66 // Deduce the termination date if it is not given.
67 Date terminationDate;
68 if (terminationDate_ != Date()) {
69 terminationDate = terminationDate_;
70 } else {
71 terminationDate = effectiveDate + swapTenor_;
72 }
73
74 Schedule fixedSchedule(effectiveDate, terminationDate, fixedTenor_, fixedCalendar_, fixedConvention_,
75 fixedTerminationDateConvention_, fixedRule_, fixedEndOfMonth_, fixedFirstDate_,
76 fixedNextToLastDate_);
77
78 Schedule onSchedule(effectiveDate, terminationDate, onTenor_, onCalendar_, onConvention_,
79 onTerminationDateConvention_, onRule_, onEndOfMonth_, onFirstDate_, onNextToLastDate_);
80
81 QuantLib::ext::shared_ptr<AverageOIS> swap(
82 new AverageOIS(type_, nominal_, fixedSchedule, fixedRate_, fixedDayCounter_, fixedPaymentAdjustment_,
83 fixedPaymentCalendar_, onSchedule, overnightIndex_, onPaymentAdjustment_, onPaymentCalendar_,
84 rateCutoff_, onSpread_, onGearing_, onDayCounter_, onCouponPricer_, telescopicValueDates_));
85
86 swap->setPricingEngine(engine_);
87 return swap;
88}
89
92 return *this;
93}
94
96 type_ = type;
97 return *this;
98}
99
101 nominal_ = nominal;
102 return *this;
103}
104
106 effectiveDate_ = effectiveDate;
107 return *this;
108}
109
111 terminationDate_ = terminationDate;
112 swapTenor_ = Period();
113 return *this;
114}
115
116MakeAverageOIS& MakeAverageOIS::withRule(DateGeneration::Rule rule) {
117 fixedRule_ = rule;
118 onRule_ = rule;
119 return *this;
120}
121
122MakeAverageOIS& MakeAverageOIS::withSpotLagCalendar(const Calendar& spotLagCalendar) {
123 spotLagCalendar_ = spotLagCalendar;
124 return *this;
125}
126
127MakeAverageOIS& MakeAverageOIS::withFixedCalendar(const Calendar& fixedCalendar) {
128 fixedCalendar_ = fixedCalendar;
129 return *this;
130}
131
132MakeAverageOIS& MakeAverageOIS::withFixedConvention(BusinessDayConvention fixedConvention) {
133 fixedConvention_ = fixedConvention;
134 return *this;
135}
136
138MakeAverageOIS::withFixedTerminationDateConvention(BusinessDayConvention fixedTerminationDateConvention) {
139 fixedTerminationDateConvention_ = fixedTerminationDateConvention;
140 return *this;
141}
142
143MakeAverageOIS& MakeAverageOIS::withFixedRule(DateGeneration::Rule fixedRule) {
144 fixedRule_ = fixedRule;
145 return *this;
146}
147
149 fixedEndOfMonth_ = fixedEndOfMonth;
150 return *this;
151}
152
154 fixedFirstDate_ = fixedFirstDate;
155 return *this;
156}
157
159 fixedNextToLastDate_ = fixedNextToLastDate;
160 return *this;
161}
162
163MakeAverageOIS& MakeAverageOIS::withFixedPaymentAdjustment(BusinessDayConvention fixedPaymentAdjustment) {
164 fixedPaymentAdjustment_ = fixedPaymentAdjustment;
165 return *this;
166}
167
168MakeAverageOIS& MakeAverageOIS::withFixedPaymentCalendar(const Calendar& fixedPaymentCalendar) {
169 fixedPaymentCalendar_ = fixedPaymentCalendar;
170 return *this;
171}
172
173MakeAverageOIS& MakeAverageOIS::withONCalendar(const Calendar& onCalendar) {
174 onCalendar_ = onCalendar;
175 return *this;
176}
177
178MakeAverageOIS& MakeAverageOIS::withONConvention(BusinessDayConvention onConvention) {
179 onConvention_ = onConvention;
180 return *this;
181}
182
183MakeAverageOIS& MakeAverageOIS::withONTerminationDateConvention(BusinessDayConvention onTerminationDateConvention) {
184 onTerminationDateConvention_ = onTerminationDateConvention;
185 return *this;
186}
187
188MakeAverageOIS& MakeAverageOIS::withONRule(DateGeneration::Rule onRule) {
189 onRule_ = onRule;
190 return *this;
191}
192
194 onEndOfMonth_ = onEndOfMonth;
195 return *this;
196}
197
199 onFirstDate_ = onFirstDate;
200 return *this;
201}
202
204 onNextToLastDate_ = onNextToLastDate;
205 return *this;
206}
207
209 rateCutoff_ = rateCutoff;
210 return *this;
211}
212
214 onSpread_ = onSpread;
215 return *this;
216}
217
219 onGearing_ = onGearing;
220 return *this;
221}
222
223MakeAverageOIS& MakeAverageOIS::withONDayCounter(const DayCounter& onDayCounter) {
224 onDayCounter_ = onDayCounter;
225 return *this;
226}
227
228MakeAverageOIS& MakeAverageOIS::withONPaymentAdjustment(BusinessDayConvention onPaymentAdjustment) {
229 onPaymentAdjustment_ = onPaymentAdjustment;
230 return *this;
231}
232
233MakeAverageOIS& MakeAverageOIS::withONPaymentCalendar(const Calendar& onPaymentCalendar) {
234 onPaymentCalendar_ = onPaymentCalendar;
235 return *this;
236}
237
239 telescopicValueDates_ = telescopicValueDates;
240 return *this;
241}
242
244MakeAverageOIS::withONCouponPricer(const QuantLib::ext::shared_ptr<AverageONIndexedCouponPricer>& onCouponPricer) {
245 onCouponPricer_ = onCouponPricer;
246 return *this;
247}
248
249MakeAverageOIS& MakeAverageOIS::withDiscountingTermStructure(const Handle<YieldTermStructure>& discountCurve) {
250 bool includeSettlementDateFlows = false;
251 engine_ = QuantLib::ext::shared_ptr<PricingEngine>(new DiscountingSwapEngine(discountCurve, includeSettlementDateFlows));
252 return *this;
253}
254
255MakeAverageOIS& MakeAverageOIS::withPricingEngine(const QuantLib::ext::shared_ptr<PricingEngine>& engine) {
256 engine_ = engine;
257 return *this;
258}
259} // namespace QuantExt
QuantLib::ext::shared_ptr< PricingEngine > engine_
Definition: cdsoption.cpp:78
Average overnight index swap.
Definition: averageois.hpp:46
Type
Receiver (Payer) means receive (pay) fixed.
Definition: averageois.hpp:49
Pricer for average overnight indexed coupons.
BusinessDayConvention fixedConvention_
MakeAverageOIS & withONCalendar(const Calendar &onCalendar)
MakeAverageOIS & withFixedConvention(BusinessDayConvention fixedConvention)
BusinessDayConvention fixedPaymentAdjustment_
MakeAverageOIS & withFixedPaymentCalendar(const Calendar &fixedPaymentCalendar)
MakeAverageOIS & withTelescopicValueDates(bool telescopicValueDates)
MakeAverageOIS & withONRule(DateGeneration::Rule onRule)
MakeAverageOIS & withONNextToLastDate(const Date &onNextToLastDate)
MakeAverageOIS & receiveFixed(bool receiveFixed=true)
MakeAverageOIS & withRateCutoff(Natural rateCutoff)
MakeAverageOIS & withRule(DateGeneration::Rule rule)
BusinessDayConvention onPaymentAdjustment_
MakeAverageOIS & withONGearing(Real onGearing)
MakeAverageOIS & withONSpread(Spread onSpread)
MakeAverageOIS & withONFirstDate(const Date &onFirstDate)
MakeAverageOIS & withType(AverageOIS::Type type)
QuantLib::ext::shared_ptr< AverageONIndexedCouponPricer > onCouponPricer_
MakeAverageOIS & withFixedRule(DateGeneration::Rule fixedRule)
QuantLib::ext::shared_ptr< PricingEngine > engine_
MakeAverageOIS & withFixedPaymentAdjustment(BusinessDayConvention fixedPaymentAdjustment)
BusinessDayConvention onTerminationDateConvention_
MakeAverageOIS & withONDayCounter(const DayCounter &onDayCounter)
MakeAverageOIS & withFixedFirstDate(const Date &fixedFirstDate)
MakeAverageOIS & withONEndOfMonth(bool onEndOfMonth=false)
DateGeneration::Rule fixedRule_
DateGeneration::Rule onRule_
BusinessDayConvention onConvention_
MakeAverageOIS & withEffectiveDate(const Date &effectiveDate)
MakeAverageOIS & withONConvention(BusinessDayConvention onConvention)
MakeAverageOIS & withONPaymentAdjustment(BusinessDayConvention onPaymentAdjustment)
MakeAverageOIS & withFixedNextToLastDate(const Date &fixedNextToLastDate)
MakeAverageOIS & withFixedEndOfMonth(bool fixedEndOfMonth=false)
BusinessDayConvention fixedTerminationDateConvention_
MakeAverageOIS & withPricingEngine(const QuantLib::ext::shared_ptr< PricingEngine > &engine)
MakeAverageOIS(const Period &swapTenor, const QuantLib::ext::shared_ptr< OvernightIndex > &overnightIndex, const Period &onTenor, Rate fixedRate, const Period &fixedTenor, const DayCounter &fixedDayCounter, const Period &spotLagTenor=2 *Days, const Period &forwardStart=0 *Days)
MakeAverageOIS & withONCouponPricer(const QuantLib::ext::shared_ptr< AverageONIndexedCouponPricer > &onCouponPricer)
MakeAverageOIS & withNominal(Real nominal)
MakeAverageOIS & withTerminationDate(const Date &terminationDate)
MakeAverageOIS & withDiscountingTermStructure(const Handle< YieldTermStructure > &discountCurve)
MakeAverageOIS & withFixedTerminationDateConvention(BusinessDayConvention fixedTerminationDateConvention)
MakeAverageOIS & withSpotLagCalendar(const Calendar &spotLagCalendar)
MakeAverageOIS & withONPaymentCalendar(const Calendar &onPaymentCalendar)
MakeAverageOIS & withONTerminationDateConvention(BusinessDayConvention onTerminationDateConvention)
MakeAverageOIS & withFixedCalendar(const Calendar &fixedCalendar)
Helper class to instantiate standard average ON indexed swaps.