Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
bondtrscashflow.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2020 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
20
21namespace QuantExt {
22
23BondTRSCashFlow::BondTRSCashFlow(const Date& paymentDate, const Date& fixingStartDate, const Date& fixingEndDate,
24 const Real bondNotional, const QuantLib::ext::shared_ptr<BondIndex>& bondIndex,
25 const Real initialPrice, const QuantLib::ext::shared_ptr<FxIndex>& fxIndex)
26 : TRSCashFlow(paymentDate, fixingStartDate, fixingEndDate, bondNotional, bondIndex, initialPrice, fxIndex) {}
27
28const Real BondTRSCashFlow::notional(Date date) const {
29 auto bondIndex = ext::dynamic_pointer_cast<BondIndex>(index_);
30 QL_REQUIRE(bondIndex, "BondTRSCashFlow::notional index must be a BondIndex");
31 return bondIndex->bond()->notional(fixingStartDate_);
32}
33
34void BondTRSCashFlow::setFixingStartDate(QuantLib::Date fixingDate) {
35 QL_REQUIRE(fixingDate < fixingEndDate_, "BondTRSCashFlow fixingStartDate must be before fixingEndDate");
36 fixingStartDate_ = fixingDate;
37}
38
39BondTRSLeg::BondTRSLeg(const std::vector<Date>& valuationDates, const std::vector<Date>& paymentDates,
40 const Real bondNotional, const QuantLib::ext::shared_ptr<BondIndex>& bondIndex,
41 const QuantLib::ext::shared_ptr<FxIndex>& fxIndex)
42 : valuationDates_(valuationDates), paymentDates_(paymentDates), bondNotional_(bondNotional), bondIndex_(bondIndex),
43 fxIndex_(fxIndex) {}
44
46 initialPrice_ = initialPrice;
47 return *this;
48}
49
50BondTRSLeg::operator Leg() const {
51 Leg leg;
52 Real initialPrice;
53
54 for (Size i = 0; i < valuationDates_.size() - 1; ++i) {
55 initialPrice = i == 0 ? initialPrice_ : Null<Real>();
56 leg.push_back(QuantLib::ext::make_shared<BondTRSCashFlow>(paymentDates_[i], valuationDates_[i], valuationDates_[i + 1],
57 bondNotional_, bondIndex_, initialPrice, fxIndex_));
58 }
59 return leg;
60}
61
62} // namespace QuantExt
cashflow paying the total return of a bond
BondTRSCashFlow(const Date &paymentDate, const Date &fixingStartDate, const Date &fixingEndDate, const Real bondNotional, const QuantLib::ext::shared_ptr< BondIndex > &bondIndex, const Real initialPrice=Null< Real >(), const QuantLib::ext::shared_ptr< FxIndex > &fxIndex=nullptr)
void setFixingStartDate(QuantLib::Date fixingDate)
const Real notional() const override
helper class building a sequence of bond trs cashflows
BondTRSLeg & withInitialPrice(Real)
BondTRSLeg(const std::vector< Date > &valuationDates, const std::vector< Date > &paymentDates, const Real bondNotional, const QuantLib::ext::shared_ptr< BondIndex > &bondIndex, const QuantLib::ext::shared_ptr< FxIndex > &fxIndex=nullptr)
bond trs cashflow
Definition: trscashflow.hpp:38
QuantLib::ext::shared_ptr< Index > index_
Definition: trscashflow.hpp:78