Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
bondtotalreturnswap.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2019 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
21
22#include <ql/event.hpp>
23#include <ql/termstructures/yieldtermstructure.hpp>
24
25namespace QuantExt {
26
27BondTRS::BondTRS(const QuantLib::ext::shared_ptr<QuantExt::BondIndex>& bondIndex, const Real bondNotional,
28 const Real initialPrice, const std::vector<QuantLib::Leg>& fundingLeg, const bool payTotalReturnLeg,
29 const std::vector<Date>& valuationDates, const std::vector<Date>& paymentDates,
30 const QuantLib::ext::shared_ptr<QuantExt::FxIndex>& fxIndex, bool payBondCashFlowsImmediately,
31 const Currency& fundingCurrency, const Currency& bondCurrency)
32 : bondIndex_(bondIndex), bondNotional_(bondNotional), initialPrice_(initialPrice), fundingLeg_(fundingLeg),
33 payTotalReturnLeg_(payTotalReturnLeg), fxIndex_(fxIndex),
34 payBondCashFlowsImmediately_(payBondCashFlowsImmediately), fundingCurrency_(fundingCurrency),
35 bondCurrency_(bondCurrency), valuationDates_(valuationDates), paymentDates_(paymentDates) {
36
37 QL_REQUIRE(bondIndex, "BondTRS: no bond index given");
38 registerWith(bondIndex);
39
40 if (fxIndex_ != nullptr)
41 registerWith(fxIndex_);
42
43 if (!fundingCurrency_.empty() && !bondCurrency_.empty()) {
44 // do we require an fx index for conversion ...
45 QL_REQUIRE(fundingCurrency_ == bondCurrency_ || fxIndex_ != nullptr,
46 "BondTRS: fx index required if funding ccy ("
47 << fundingCurrency_.code() << ") not equal to bond ccy (" << bondCurrency_.code() << ")");
48 // ... and if yes, has it the right currencies?
49 if (fxIndex_ != nullptr) {
50 QL_REQUIRE(fxIndex_->sourceCurrency() == bondCurrency_ && fxIndex_->targetCurrency() == fundingCurrency_,
51 "BondTRS: fx index '" << fxIndex_->name() << "' currencies must match bond ccy / funding ccy ("
52 << bondCurrency_.code() << " / " << fundingCurrency_.code() << ")");
53 }
54 }
55
56 for (auto const& l : fundingLeg) {
57 for (auto const& c : l)
58 registerWith(c);
59 }
60 QL_REQUIRE(valuationDates.size() > 1, "valuation dates size > 1 required");
61
64}
65
66bool BondTRS::isExpired() const { return detail::simple_event(valuationDates_.back()).hasOccurred(); }
67
68void BondTRS::setupArguments(PricingEngine::arguments* args) const {
69 BondTRS::arguments* arguments = dynamic_cast<BondTRS::arguments*>(args);
70 QL_REQUIRE(arguments, "BondTRS instrument: wrong argument type in bond total return swap");
82}
83
84} // namespace QuantExt
cashflow paying the total return of a bond
QuantLib::ext::shared_ptr< QuantExt::BondIndex > bondIndex
QuantLib::ext::shared_ptr< QuantExt::FxIndex > fxIndex
const QuantLib::ext::shared_ptr< QuantExt::BondIndex > & bondIndex() const
void setupArguments(PricingEngine::arguments *) const override
QuantLib::ext::shared_ptr< QuantExt::FxIndex > fxIndex_
BondTRS(const QuantLib::ext::shared_ptr< QuantExt::BondIndex > &bondIndex, const Real bondNotional, const Real initialPrice, const std::vector< Leg > &fundingLeg, const bool payTotalReturnLeg, const std::vector< Date > &valuationDates, const std::vector< Date > &paymentDates, const QuantLib::ext::shared_ptr< QuantExt::FxIndex > &fxIndex=nullptr, bool payBondCashFlowsImmediately=false, const Currency &fundingCurrency=Currency(), const Currency &bondCurrency=Currency())
Constructor.
bool isExpired() const override
std::vector< Leg > fundingLeg_
const std::vector< Date > & valuationDates() const
const std::vector< Leg > & fundingLeg() const
std::vector< Date > valuationDates_
std::vector< Date > paymentDates_
QuantLib::ext::shared_ptr< QuantExt::BondIndex > bondIndex_
helper class building a sequence of bond trs cashflows
BondTRSLeg & withInitialPrice(Real)