Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
averageois.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/cashflows/fixedratecoupon.hpp>
20
23
24namespace QuantExt {
25
26AverageOIS::AverageOIS(Type type, Real nominal, const Schedule& fixedLegSchedule, Rate fixedRate,
27 const DayCounter& fixedDCB, BusinessDayConvention fixedLegPaymentAdjustment,
28 const Calendar& fixedLegPaymentCalendar, const Schedule& onLegSchedule,
29 const QuantLib::ext::shared_ptr<OvernightIndex>& overnightIndex,
30 BusinessDayConvention onLegPaymentAdjustment, const Calendar& onLegPaymentCalendar,
31 Natural rateCutoff, Spread onLegSpread, Real onLegGearing, const DayCounter& onLegDCB,
32 const QuantLib::ext::shared_ptr<AverageONIndexedCouponPricer>& onLegCouponPricer,
33 const bool telescopicValueDates)
34 : Swap(2), type_(type), nominals_(std::vector<Real>(1, nominal)), fixedRates_(std::vector<Rate>(1, fixedRate)),
35 fixedDayCounter_(fixedDCB), fixedPaymentAdjustment_(fixedLegPaymentAdjustment),
36 fixedPaymentCalendar_(fixedLegPaymentCalendar), overnightIndex_(overnightIndex),
37 onPaymentAdjustment_(onLegPaymentAdjustment), onPaymentCalendar_(onLegPaymentCalendar), rateCutoff_(rateCutoff),
38 onSpreads_(std::vector<Spread>(1, onLegSpread)), onGearings_(std::vector<Real>(1, onLegGearing)),
39 onDayCounter_(onLegDCB), onCouponPricer_(onLegCouponPricer), telescopicValueDates_(telescopicValueDates) {
40 initialize(fixedLegSchedule, onLegSchedule);
41}
42
43AverageOIS::AverageOIS(Type type, std::vector<Real> nominals, const Schedule& fixedLegSchedule,
44 std::vector<Rate> fixedRates, const DayCounter& fixedDCB,
45 BusinessDayConvention fixedLegPaymentAdjustment, const Calendar& fixedLegPaymentCalendar,
46 const Schedule& onLegSchedule, const QuantLib::ext::shared_ptr<OvernightIndex>& overnightIndex,
47 BusinessDayConvention onLegPaymentAdjustment, const Calendar& onLegPaymentCalendar,
48 Natural rateCutoff, std::vector<Spread> onLegSpreads, std::vector<Real> onLegGearings,
49 const DayCounter& onLegDCB,
50 const QuantLib::ext::shared_ptr<AverageONIndexedCouponPricer>& onLegCouponPricer,
51 const bool telescopicValueDates)
52 : Swap(2), type_(type), nominals_(nominals), fixedRates_(fixedRates), fixedDayCounter_(fixedDCB),
53 fixedPaymentAdjustment_(fixedLegPaymentAdjustment), fixedPaymentCalendar_(fixedLegPaymentCalendar),
54 overnightIndex_(overnightIndex), onPaymentAdjustment_(onLegPaymentAdjustment),
55 onPaymentCalendar_(onLegPaymentCalendar), rateCutoff_(rateCutoff), onSpreads_(onLegSpreads),
56 onGearings_(onLegGearings), onDayCounter_(onLegDCB), onCouponPricer_(onLegCouponPricer),
57 telescopicValueDates_(telescopicValueDates) {
58 initialize(fixedLegSchedule, onLegSchedule);
59}
60
61void AverageOIS::initialize(const Schedule& fixedLegSchedule, const Schedule& onLegSchedule) {
62 // Fixed leg.
63 legs_[0] = FixedRateLeg(fixedLegSchedule)
64 .withNotionals(nominals_)
65 .withCouponRates(fixedRates_, fixedDayCounter_)
66 .withPaymentAdjustment(fixedPaymentAdjustment_)
67 .withPaymentCalendar(fixedPaymentCalendar_);
68
69 // Average ON leg.
70 AverageONLeg tempAverageONLeg = AverageONLeg(onLegSchedule, overnightIndex_)
79
80 if (onCouponPricer_) {
81 tempAverageONLeg = tempAverageONLeg.withAverageONIndexedCouponPricer(onCouponPricer_);
82 }
83
84 legs_[1] = tempAverageONLeg;
85
86 // Set the fixed and ON leg to pay (receive) and receive (pay) resp.
87 switch (type_) {
88 case Payer:
89 payer_[0] = -1.0;
90 payer_[1] = +1.0;
91 break;
92 case Receiver:
93 payer_[0] = +1.0;
94 payer_[1] = -1.0;
95 break;
96 default:
97 QL_FAIL("Unknown average ON index swap type");
98 }
99}
100
102 QL_REQUIRE(nominals_.size() == 1, "Swap has varying nominals");
103 return nominals_[0];
104}
105
107 QL_REQUIRE(fixedRates_.size() == 1, "Swap has varying fixed rates");
108 return fixedRates_[0];
109}
110
111Spread AverageOIS::onSpread() const {
112 QL_REQUIRE(onSpreads_.size() == 1, "Swap has varying ON spreads");
113 return onSpreads_[0];
114}
115
117 QL_REQUIRE(onGearings_.size() == 1, "Swap has varying ON gearings");
118 return onGearings_[0];
119}
120
122 calculate();
123 QL_REQUIRE(legBPS_[0] != Null<Real>(), "fixedLegBPS not available");
124 return legBPS_[0];
125}
126
128 calculate();
129 QL_REQUIRE(legNPV_[0] != Null<Real>(), "fixedLegNPV not available");
130 return legNPV_[0];
131}
132
134 static const Spread basisPoint = 1.0e-4;
135 calculate();
136 return -overnightLegNPV() / (fixedLegBPS() / basisPoint);
137}
138
140 calculate();
141 QL_REQUIRE(legBPS_[1] != Null<Real>(), "overnightLegBPS not available");
142 return legBPS_[1];
143}
144
146 calculate();
147 QL_REQUIRE(legNPV_[1] != Null<Real>(), "overnightLegNPV not available");
148 return legNPV_[1];
149}
150
152 QL_REQUIRE(onSpreads_.size() == 1, "fairSpread not implemented for varying spreads.");
153 static const Spread basisPoint = 1.0e-4;
154 calculate();
155 return onSpreads_[0] - NPV_ / (overnightLegBPS() / basisPoint);
156}
157
158void AverageOIS::setONIndexedCouponPricer(const QuantLib::ext::shared_ptr<AverageONIndexedCouponPricer>& onCouponPricer) {
159 QuantExt::setCouponPricer(legs_[1], onCouponPricer);
160 update();
161}
162} // namespace QuantExt
Swap of arithmetic average overnight index against fixed.
Spread onSpread() const
Definition: averageois.cpp:111
Rate fixedRate() const
Definition: averageois.cpp:106
Real fairRate() const
Definition: averageois.cpp:133
QuantLib::ext::shared_ptr< OvernightIndex > overnightIndex_
Definition: averageois.hpp:123
Type
Receiver (Payer) means receive (pay) fixed.
Definition: averageois.hpp:49
DayCounter fixedDayCounter_
Definition: averageois.hpp:119
BusinessDayConvention fixedPaymentAdjustment_
Definition: averageois.hpp:120
Spread fairSpread() const
Definition: averageois.cpp:151
BusinessDayConvention onPaymentAdjustment_
Definition: averageois.hpp:124
void initialize(const Schedule &fixedLegSchedule, const Schedule &onLegSchedule)
Definition: averageois.cpp:61
std::vector< Rate > fixedRates_
Definition: averageois.hpp:118
QuantLib::ext::shared_ptr< AverageONIndexedCouponPricer > onCouponPricer_
Definition: averageois.hpp:130
std::vector< Spread > onSpreads_
Definition: averageois.hpp:127
Calendar onPaymentCalendar_
Definition: averageois.hpp:125
Real nominal() const
Definition: averageois.cpp:101
Real fixedLegBPS() const
Definition: averageois.cpp:121
Calendar fixedPaymentCalendar_
Definition: averageois.hpp:121
Real onGearing() const
Definition: averageois.cpp:116
void setONIndexedCouponPricer(const QuantLib::ext::shared_ptr< AverageONIndexedCouponPricer > &onCouponPricer)
Definition: averageois.cpp:158
AverageOIS(Type type, Real nominal, const Schedule &fixedSchedule, Rate fixedRate, const DayCounter &fixedDayCounter, BusinessDayConvention fixedPaymentAdjustment, const Calendar &fixedPaymentCalendar, const Schedule &onSchedule, const QuantLib::ext::shared_ptr< OvernightIndex > &overnightIndex, BusinessDayConvention onPaymentAdjustment, const Calendar &onPaymentCalendar, Natural rateCutoff=0, Spread onSpread=0.0, Real onGearing=1.0, const DayCounter &onDayCounter=DayCounter(), const QuantLib::ext::shared_ptr< AverageONIndexedCouponPricer > &onCouponPricer=QuantLib::ext::shared_ptr< AverageONIndexedCouponPricer >(), const bool telescopicValueDates=false)
Arithmetic average ON leg vs. fixed leg constructor.
Definition: averageois.cpp:26
Real overnightLegBPS() const
Definition: averageois.cpp:139
Real fixedLegNPV() const
Definition: averageois.cpp:127
DayCounter onDayCounter_
Definition: averageois.hpp:129
Real overnightLegNPV() const
Definition: averageois.cpp:145
std::vector< Real > onGearings_
Definition: averageois.hpp:128
std::vector< Real > nominals_
Definition: averageois.hpp:116
helper class building a sequence of overnight coupons
AverageONLeg & withPaymentDayCounter(const DayCounter &dayCounter)
AverageONLeg & withRateCutoff(Natural rateCutoff)
AverageONLeg & withPaymentCalendar(const Calendar &calendar)
AverageONLeg & withTelescopicValueDates(bool telescopicValueDates)
AverageONLeg & withPaymentAdjustment(BusinessDayConvention convention)
AverageONLeg & withNotionals(const std::vector< Real > &notionals)
AverageONLeg & withSpreads(const std::vector< Spread > &spreads)
AverageONLeg & withAverageONIndexedCouponPricer(const QuantLib::ext::shared_ptr< AverageONIndexedCouponPricer > &couponPricer)
AverageONLeg & withGearings(const std::vector< Real > &gearings)
Utility functions for setting coupon pricers on legs.
void setCouponPricer(const Leg &leg, const QuantLib::ext::shared_ptr< FloatingRateCouponPricer > &pricer)
Set Coupon Pricer.