Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
crossccybasisswap.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 <boost/assign/list_of.hpp>
20
21#include <ql/cashflows/iborcoupon.hpp>
22#include <ql/cashflows/simplecashflow.hpp>
23
27
28using boost::assign::list_of;
29
30namespace QuantExt {
31
32CrossCcyBasisSwap::CrossCcyBasisSwap(Real payNominal, const Currency& payCurrency, const Schedule& paySchedule,
33 const QuantLib::ext::shared_ptr<IborIndex>& payIndex, Spread paySpread, Real payGearing,
34 Real recNominal, const Currency& recCurrency, const Schedule& recSchedule,
35 const QuantLib::ext::shared_ptr<IborIndex>& recIndex, Spread recSpread, Real recGearing,
36 Size payPaymentLag, Size recPaymentLag, boost::optional<bool> payIncludeSpread,
37 boost::optional<Period> payLookback, boost::optional<Size> payFixingDays,
38 boost::optional<Size> payRateCutoff, boost::optional<bool> payIsAveraged,
39 boost::optional<bool> recIncludeSpread, boost::optional<Period> recLookback,
40 boost::optional<Size> recFixingDays, boost::optional<Size> recRateCutoff,
41 boost::optional<bool> recIsAveraged, const bool telescopicValueDates)
42 : CrossCcySwap(2), payNominal_(payNominal), payCurrency_(payCurrency), paySchedule_(paySchedule),
43 payIndex_(payIndex), paySpread_(paySpread), payGearing_(payGearing), recNominal_(recNominal),
44 recCurrency_(recCurrency), recSchedule_(recSchedule), recIndex_(recIndex), recSpread_(recSpread),
45 recGearing_(recGearing), payPaymentLag_(payPaymentLag), recPaymentLag_(recPaymentLag),
46 payIncludeSpread_(payIncludeSpread), payLookback_(payLookback), payFixingDays_(payFixingDays),
47 payRateCutoff_(payRateCutoff), payIsAveraged_(payIsAveraged), recIncludeSpread_(recIncludeSpread),
48 recLookback_(recLookback), recFixingDays_(recFixingDays), recRateCutoff_(recRateCutoff),
49 recIsAveraged_(recIsAveraged), telescopicValueDates_(telescopicValueDates) {
50 registerWith(payIndex_);
51 registerWith(recIndex_);
52 initialize();
53}
54
56 // Pay leg
57 if (auto on = QuantLib::ext::dynamic_pointer_cast<QuantLib::OvernightIndex>(payIndex_)) {
58 // ON leg
69 } else {
80 }
81 } else {
82 // Ibor leg
83 legs_[0] = IborLeg(paySchedule_, payIndex_)
88 }
89 payer_[0] = -1.0;
91 // Pay leg notional exchange at start.
92 Date initialPayDate = paySchedule_.dates().front();
93 QuantLib::ext::shared_ptr<CashFlow> initialPayCF(new SimpleCashFlow(-payNominal_, initialPayDate));
94 legs_[0].insert(legs_[0].begin(), initialPayCF);
95 // Pay leg notional exchange at end.
96 Date finalPayDate = paySchedule_.dates().back();
97 QuantLib::ext::shared_ptr<CashFlow> finalPayCF(new SimpleCashFlow(payNominal_, finalPayDate));
98 legs_[0].push_back(finalPayCF);
99
100 // Receive leg
101 if (auto on = QuantLib::ext::dynamic_pointer_cast<QuantLib::OvernightIndex>(recIndex_)) {
102 // ON leg
113 } else {
124 }
125 } else {
126 // Ibor leg
127 legs_[1] = IborLeg(recSchedule_, recIndex_)
132 }
133 payer_[1] = +1.0;
135 // Receive leg notional exchange at start.
136 Date initialRecDate = recSchedule_.dates().front();
137 QuantLib::ext::shared_ptr<CashFlow> initialRecCF(new SimpleCashFlow(-recNominal_, initialRecDate));
138 legs_[1].insert(legs_[1].begin(), initialRecCF);
139 // Receive leg notional exchange at end.
140 Date finalRecDate = recSchedule_.dates().back();
141 QuantLib::ext::shared_ptr<CashFlow> finalRecCF(new SimpleCashFlow(recNominal_, finalRecDate));
142 legs_[1].push_back(finalRecCF);
143
144 // Register the instrument with all cashflows on each leg.
145 for (Size legNo = 0; legNo < 2; legNo++) {
146 Leg::iterator it;
147 for (it = legs_[legNo].begin(); it != legs_[legNo].end(); ++it) {
148 registerWith(*it);
149 }
150 }
151}
152
153void CrossCcyBasisSwap::setupArguments(PricingEngine::arguments* args) const {
154
156
158
159 /* Returns here if e.g. args is CrossCcySwap::arguments which
160 is the case if PricingEngine is a CrossCcySwap::engine. */
161 if (!arguments)
162 return;
163
166}
167
168void CrossCcyBasisSwap::fetchResults(const PricingEngine::results* r) const {
169
171
172 const CrossCcyBasisSwap::results* results = dynamic_cast<const CrossCcyBasisSwap::results*>(r);
173 if (results) {
174 /* If PricingEngine::results are of type
175 CrossCcyBasisSwap::results */
178 } else {
179 /* If not, e.g. if the engine is a CrossCcySwap::engine */
180 fairPaySpread_ = Null<Spread>();
181 fairRecSpread_ = Null<Spread>();
182 }
183
184 /* Calculate the fair pay and receive spreads if they are null */
185 static Spread basisPoint = 1.0e-4;
186 if (fairPaySpread_ == Null<Spread>()) {
187 if (legBPS_[0] != Null<Real>())
188 fairPaySpread_ = paySpread_ - NPV_ / (legBPS_[0] / basisPoint);
189 }
190 if (fairRecSpread_ == Null<Spread>()) {
191 if (legBPS_[1] != Null<Real>())
192 fairRecSpread_ = recSpread_ - NPV_ / (legBPS_[1] / basisPoint);
193 }
194}
195
198 fairPaySpread_ = Null<Spread>();
199 fairRecSpread_ = Null<Spread>();
200}
201
204 QL_REQUIRE(paySpread != Null<Spread>(), "Pay spread cannot be null");
205 QL_REQUIRE(recSpread != Null<Spread>(), "Rec spread cannot be null");
206}
207
210 fairPaySpread = Null<Spread>();
211 fairRecSpread = Null<Spread>();
212}
213} // namespace QuantExt
coupon paying the weighted average of the daily overnight rate
helper class building a sequence of overnight coupons
AverageONLeg & withGearing(Real gearing)
AverageONLeg & withSpread(Spread spread)
AverageONLeg & withPaymentLag(Natural lag)
AverageONLeg & withNotional(Real notional)
AverageONLeg & withLookback(const Period &lookback)
AverageONLeg & withRateCutoff(Natural rateCutoff)
AverageONLeg & withTelescopicValueDates(bool telescopicValueDates)
AverageONLeg & withFixingDays(const Size fixingDays)
boost::optional< QuantLib::Period > payLookback_
QuantLib::ext::shared_ptr< IborIndex > payIndex_
QuantLib::ext::shared_ptr< IborIndex > recIndex_
boost::optional< bool > payIsAveraged_
boost::optional< Size > recRateCutoff_
boost::optional< bool > payIncludeSpread_
boost::optional< bool > recIsAveraged_
boost::optional< QuantLib::Size > payFixingDays_
boost::optional< QuantLib::Size > recFixingDays_
void setupArguments(PricingEngine::arguments *args) const override
boost::optional< Size > payRateCutoff_
void setupExpired() const override
void fetchResults(const PricingEngine::results *) const override
boost::optional< QuantLib::Period > recLookback_
CrossCcyBasisSwap(Real payNominal, const Currency &payCurrency, const Schedule &paySchedule, const QuantLib::ext::shared_ptr< IborIndex > &payIndex, Spread paySpread, Real payGearing, Real recNominal, const Currency &recCurrency, const Schedule &recSchedule, const QuantLib::ext::shared_ptr< IborIndex > &recIndex, Spread recSpread, Real recGearing, Size payPaymentLag=0, Size recPaymentLag=0, boost::optional< bool > payIncludeSpread=boost::none, boost::optional< Period > payLookback=boost::none, boost::optional< Size > payFixingDays=boost::none, boost::optional< Size > payRateCutoff=boost::none, boost::optional< bool > payIsAveraged=boost::none, boost::optional< bool > recIncludeSpread=boost::none, boost::optional< Period > recLookback=boost::none, boost::optional< Size > recFixingDays=boost::none, boost::optional< Size > recRateCutoff=boost::none, boost::optional< bool > recIsAveraged=boost::none, const bool telescopicValueDates=false)
boost::optional< bool > recIncludeSpread_
void validate() const override
Cross currency swap.
void setupArguments(PricingEngine::arguments *args) const override
void setupExpired() const override
void fetchResults(const PricingEngine::results *) const override
std::vector< Currency > currencies_
helper class building a sequence of overnight coupons
OvernightLeg & withLookback(const Period &lookback)
OvernightLeg & withGearings(Real gearing)
OvernightLeg & withTelescopicValueDates(bool telescopicValueDates)
OvernightLeg & withFixingDays(const Natural fixingDays)
OvernightLeg & withNotionals(Real notional)
OvernightLeg & withRateCutoff(const Natural rateCutoff)
OvernightLeg & withSpreads(Spread spread)
OvernightLeg & includeSpread(bool includeSpread)
OvernightLeg & withPaymentLag(Natural lag)
Cross currency basis swap instrument.
coupon paying the compounded daily overnight rate, copy of QL class, added includeSpread flag