-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Const Notional Cross Currency Swaps #2248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
paolodelia99
wants to merge
18
commits into
lballabio:master
Choose a base branch
from
paolodelia99:feature/const-notional-xccy
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,631
−1
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
af4d044
Added base CrossCcySwap, CrossCcySwapEngine and related tests
paolodelia99 48e48aa
Update generated headers
github-actions[bot] 3732556
Update CrossCcySwap tests to account for usingAtParCoupons setting
paolodelia99 a880201
Added missing imports in crossccyswapengine.hpp
paolodelia99 5884906
Fix tag typo in QuantLib.vcxproj
paolodelia99 2d8185c
Refactor xccy tests file
paolodelia99 63f267f
Add crossccyfixfloatswap
paolodelia99 960ab15
Fixed typo in comments
paolodelia99 59df14c
add usingAtParCoupons, and fix code format in crossccyfixfloatswap.cpp
paolodelia99 9b62fab
Update generated headers
github-actions[bot] a65859e
Update copyright list in license
github-actions[bot] ecdda37
Add missing import in crossccyfixfloatswap tests
paolodelia99 cecf124
Added crossccybasisswap and related tests
paolodelia99 77e673f
Fix typo in crossccybasisswap filename in Makefile.am
paolodelia99 e35c609
Update generated headers
github-actions[bot] 496d95d
Add constructor docstring in crossccybasisswap.hpp
paolodelia99 9c82a36
Add constructor docstring in crossccyfixfloatswap.hpp
paolodelia99 68c8353
Rename xccyswapengine constructor params
paolodelia99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,176 @@ | ||
| /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | ||
|
|
||
| /* | ||
| Copyright (C) 2016 Quaternion Risk Management Ltd | ||
| All rights reserved. | ||
|
|
||
| This file is part of QuantLib, a free-software/open-source library | ||
| for financial quantitative analysts and developers - http://quantlib.org/ | ||
|
|
||
| QuantLib is free software: you can redistribute it and/or modify it | ||
| under the terms of the QuantLib license. You should have received a | ||
| copy of the license along with this program; if not, please email | ||
| <[email protected]>. The license is also available online at | ||
| <http://quantlib.org/license.shtml>. | ||
|
|
||
| This program is distributed in the hope that it will be useful, but WITHOUT | ||
| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| FOR A PARTICULAR PURPOSE. See the license for more details. | ||
| */ | ||
|
|
||
| #include <ql/cashflows/iborcoupon.hpp> | ||
| #include <ql/cashflows/simplecashflow.hpp> | ||
| #include <ql/cashflows/overnightindexedcoupon.hpp> | ||
| #include <ql/instruments/crossccybasisswap.hpp> | ||
|
|
||
| namespace QuantLib { | ||
|
|
||
| CrossCcyBasisSwap::CrossCcyBasisSwap(Real payNominal, const Currency& payCurrency, const Schedule& paySchedule, | ||
| const ext::shared_ptr<IborIndex>& payIndex, Spread paySpread, Real payGearing, | ||
| Real recNominal, const Currency& recCurrency, const Schedule& recSchedule, | ||
| const ext::shared_ptr<IborIndex>& recIndex, Spread recSpread, Real recGearing, | ||
| Size payPaymentLag, Size recPaymentLag, ext::optional<bool> payIncludeSpread, | ||
| ext::optional<Natural> payLookbackDays, ext::optional<bool> recIncludeSpread, | ||
| ext::optional<Natural> recLookbackDays, const bool telescopicValueDates) | ||
| : CrossCcySwap(2), payNominal_(payNominal), payCurrency_(payCurrency), paySchedule_(paySchedule), | ||
| payIndex_(payIndex), paySpread_(paySpread), payGearing_(payGearing), recNominal_(recNominal), | ||
| recCurrency_(recCurrency), recSchedule_(recSchedule), recIndex_(recIndex), recSpread_(recSpread), | ||
| recGearing_(recGearing), payPaymentLag_(payPaymentLag), recPaymentLag_(recPaymentLag), | ||
| payIncludeSpread_(payIncludeSpread), payLookbackDays_(payLookbackDays), recIncludeSpread_(recIncludeSpread), | ||
| recLookbackDays_(recLookbackDays), telescopicValueDates_(telescopicValueDates) { | ||
| registerWith(payIndex_); | ||
| registerWith(recIndex_); | ||
| initialize(); | ||
| } | ||
|
|
||
| void CrossCcyBasisSwap::initialize() { | ||
| // Pay leg | ||
| if (auto on = ext::dynamic_pointer_cast<OvernightIndex>(payIndex_)) { | ||
| // ON leg | ||
| legs_[0] = OvernightLeg(paySchedule_, on) | ||
| .withNotionals(payNominal_) | ||
| .withSpreads(paySpread_) | ||
| .withGearings(payGearing_) | ||
| .withPaymentLag(payPaymentLag_) | ||
| .withSpreads(payIncludeSpread_ ? *payIncludeSpread_ : false) | ||
| .withLookbackDays(payLookbackDays_ ? *payLookbackDays_ : 0) | ||
| .withTelescopicValueDates(telescopicValueDates_); | ||
| } else { | ||
| // Ibor leg | ||
| legs_[0] = IborLeg(paySchedule_, payIndex_) | ||
| .withNotionals(payNominal_) | ||
| .withSpreads(paySpread_) | ||
| .withGearings(payGearing_) | ||
| .withPaymentLag(payPaymentLag_); | ||
| } | ||
| payer_[0] = -1.0; | ||
| currencies_[0] = payCurrency_; | ||
| // Pay leg notional exchange at start. | ||
| Date initialPayDate = paySchedule_.dates().front(); | ||
| ext::shared_ptr<CashFlow> initialPayCF(new SimpleCashFlow(-payNominal_, initialPayDate)); | ||
| legs_[0].insert(legs_[0].begin(), initialPayCF); | ||
| // Pay leg notional exchange at end. | ||
| Date finalPayDate = paySchedule_.dates().back(); | ||
| ext::shared_ptr<CashFlow> finalPayCF(new SimpleCashFlow(payNominal_, finalPayDate)); | ||
| legs_[0].push_back(finalPayCF); | ||
|
|
||
| // Receive leg | ||
| if (auto on = ext::dynamic_pointer_cast<OvernightIndex>(recIndex_)) { | ||
| // ON leg | ||
| legs_[1] = OvernightLeg(recSchedule_, on) | ||
| .withNotionals(recNominal_) | ||
| .withSpreads(recSpread_) | ||
| .withGearings(recGearing_) | ||
| .withPaymentLag(recPaymentLag_) | ||
| .withSpreads(recIncludeSpread_ ? *recIncludeSpread_ : false) | ||
| .withLookbackDays(recLookbackDays_ ? *recLookbackDays_ : 0) | ||
| .withTelescopicValueDates(telescopicValueDates_); | ||
| } else { | ||
| // Ibor leg | ||
| legs_[1] = IborLeg(recSchedule_, recIndex_) | ||
| .withNotionals(recNominal_) | ||
| .withSpreads(recSpread_) | ||
| .withGearings(recGearing_) | ||
| .withPaymentLag(recPaymentLag_); | ||
| } | ||
| payer_[1] = +1.0; | ||
| currencies_[1] = recCurrency_; | ||
| // Receive leg notional exchange at start. | ||
| Date initialRecDate = recSchedule_.dates().front(); | ||
| ext::shared_ptr<CashFlow> initialRecCF(new SimpleCashFlow(-recNominal_, initialRecDate)); | ||
| legs_[1].insert(legs_[1].begin(), initialRecCF); | ||
| // Receive leg notional exchange at end. | ||
| Date finalRecDate = recSchedule_.dates().back(); | ||
| ext::shared_ptr<CashFlow> finalRecCF(new SimpleCashFlow(recNominal_, finalRecDate)); | ||
| legs_[1].push_back(finalRecCF); | ||
|
|
||
| // Register the instrument with all cashflows on each leg. | ||
| for (Size legNo = 0; legNo < 2; legNo++) { | ||
| Leg::iterator it; | ||
| for (it = legs_[legNo].begin(); it != legs_[legNo].end(); ++it) { | ||
| registerWith(*it); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void CrossCcyBasisSwap::setupArguments(PricingEngine::arguments* args) const { | ||
|
|
||
| CrossCcySwap::setupArguments(args); | ||
|
|
||
| CrossCcyBasisSwap::arguments* arguments = dynamic_cast<CrossCcyBasisSwap::arguments*>(args); | ||
|
|
||
| /* Returns here if e.g. args is CrossCcySwap::arguments which | ||
| is the case if PricingEngine is a CrossCcySwap::engine. */ | ||
| if (!arguments) | ||
| return; | ||
|
|
||
| arguments->paySpread = paySpread_; | ||
| arguments->recSpread = recSpread_; | ||
| } | ||
|
|
||
| void CrossCcyBasisSwap::fetchResults(const PricingEngine::results* r) const { | ||
|
|
||
| CrossCcySwap::fetchResults(r); | ||
|
|
||
| const CrossCcyBasisSwap::results* results = dynamic_cast<const CrossCcyBasisSwap::results*>(r); | ||
| if (results) { | ||
| /* If PricingEngine::results are of type | ||
| CrossCcyBasisSwap::results */ | ||
| fairPaySpread_ = results->fairPaySpread; | ||
| fairRecSpread_ = results->fairRecSpread; | ||
| } else { | ||
| /* If not, e.g. if the engine is a CrossCcySwap::engine */ | ||
| fairPaySpread_ = Null<Spread>(); | ||
| fairRecSpread_ = Null<Spread>(); | ||
| } | ||
|
|
||
| /* Calculate the fair pay and receive spreads if they are null */ | ||
| static Spread basisPoint = 1.0e-4; | ||
| if (fairPaySpread_ == Null<Spread>()) { | ||
| if (legBPS_[0] != Null<Real>()) | ||
| fairPaySpread_ = paySpread_ - NPV_ / (legBPS_[0] / basisPoint); | ||
| } | ||
| if (fairRecSpread_ == Null<Spread>()) { | ||
| if (legBPS_[1] != Null<Real>()) | ||
| fairRecSpread_ = recSpread_ - NPV_ / (legBPS_[1] / basisPoint); | ||
| } | ||
| } | ||
|
|
||
| void CrossCcyBasisSwap::setupExpired() const { | ||
| CrossCcySwap::setupExpired(); | ||
| fairPaySpread_ = Null<Spread>(); | ||
| fairRecSpread_ = Null<Spread>(); | ||
| } | ||
|
|
||
| void CrossCcyBasisSwap::arguments::validate() const { | ||
| CrossCcySwap::arguments::validate(); | ||
| QL_REQUIRE(paySpread != Null<Spread>(), "Pay spread cannot be null"); | ||
| QL_REQUIRE(recSpread != Null<Spread>(), "Rec spread cannot be null"); | ||
| } | ||
|
|
||
| void CrossCcyBasisSwap::results::reset() { | ||
| CrossCcySwap::results::reset(); | ||
| fairPaySpread = Null<Spread>(); | ||
| fairRecSpread = Null<Spread>(); | ||
| } | ||
| } // namespace QuantLib | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means that this models only the const-notional swap, right? If so, it should probably be in the name of the class. The same goes for the other classes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the mtm crossccy in ORE are named
crossccy<type_of_crossccy>mtmresetswap, while the const-notionals are namedcrossccy<type_of_crossccy>swap. Would you prefercrossccy<type_of_crossccy>constnotionalswapas naming convention for const-notional xccy?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pcaspers, would changing the class name be a problem?