Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
trscashflow.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
23TRSCashFlow::TRSCashFlow(const Date& paymentDate, const Date& fixingStartDate, const Date& fixingEndDate,
24 const Real notional, const QuantLib::ext::shared_ptr<Index>& index,
25 const Real initialPrice, const QuantLib::ext::shared_ptr<FxIndex>& fxIndex)
26 : paymentDate_(paymentDate), fixingStartDate_(fixingStartDate), fixingEndDate_(fixingEndDate),
27 notional_(notional), index_(index), initialPrice_(initialPrice), fxIndex_(fxIndex) {
28 //QL_REQUIRE(!index->relative(), "TRSCashFlow: index should not use relative prices");
29 registerWith(fxIndex_);
30}
31
32Real TRSCashFlow::amount() const { return notional_ * (assetEnd() * fxEnd() - assetStart() * fxStart()); }
33
34Date TRSCashFlow::date() const { return paymentDate_; }
35
36void TRSCashFlow::accept(AcyclicVisitor& v) {
37 Visitor<TRSCashFlow>* v1 = dynamic_cast<Visitor<TRSCashFlow>*>(&v);
38 if (v1 != 0)
39 v1->visit(*this);
40 else
41 CashFlow::accept(v);
42}
43
45 return fxIndex_ ? fxIndex_->fixing(fxIndex_->fixingCalendar().adjust(fixingStartDate_, Preceding)) : 1.0;
46}
47
48Real TRSCashFlow::fxEnd() const {
49 return fxIndex_ ? fxIndex_->fixing(fxIndex_->fixingCalendar().adjust(fixingEndDate_, Preceding)) : 1.0;
50}
51
53 return initialPrice_ != Null<Real>() ? initialPrice_ * notional(fixingStartDate_)
54 : index_->fixing(fixingStartDate_);
55}
56
57Real TRSCashFlow::assetEnd() const { return index_->fixing(fixingEndDate_); }
58
59TRSLeg::TRSLeg(const std::vector<Date>& valuationDates, const std::vector<Date>& paymentDates,
60 const Real notional, const QuantLib::ext::shared_ptr<Index>& index,
61 const QuantLib::ext::shared_ptr<FxIndex>& fxIndex)
62 : valuationDates_(valuationDates), paymentDates_(paymentDates), notional_(notional), index_(index),
63 fxIndex_(fxIndex) {}
64
65TRSLeg& TRSLeg::withInitialPrice(Real initialPrice) {
66 initialPrice_ = initialPrice;
67 return *this;
68}
69
70TRSLeg::operator Leg() const {
71 Leg leg;
72 Real initialPrice;
73
74 for (Size i = 0; i < valuationDates_.size() - 1; ++i) {
75 initialPrice = i == 0 ? initialPrice_ : Null<Real>();
76 leg.push_back(QuantLib::ext::make_shared<TRSCashFlow>(paymentDates_[i], valuationDates_[i], valuationDates_[i + 1],
77 notional_, index_, initialPrice, fxIndex_));
78 }
79 return leg;
80}
81
82} // namespace QuantExt
Real assetEnd() const
Definition: trscashflow.cpp:57
QuantLib::ext::shared_ptr< FxIndex > fxIndex_
Definition: trscashflow.hpp:80
QuantLib::ext::shared_ptr< Index > index_
Definition: trscashflow.hpp:78
TRSCashFlow(const Date &paymentDate, const Date &fixingStartDate, const Date &fixingEndDate, const Real notional, const QuantLib::ext::shared_ptr< Index > &Index, const Real initialPrice=Null< Real >(), const QuantLib::ext::shared_ptr< FxIndex > &fxIndex=nullptr)
Definition: trscashflow.cpp:23
Real amount() const override
Definition: trscashflow.cpp:32
Real assetStart() const
Definition: trscashflow.cpp:52
virtual void accept(AcyclicVisitor &) override
Definition: trscashflow.cpp:36
Real fxStart() const
Definition: trscashflow.cpp:44
Date date() const override
Definition: trscashflow.cpp:34
virtual const Real notional() const
Definition: trscashflow.hpp:54
helper class building a sequence of trs cashflows
Definition: trscashflow.hpp:86
TRSLeg & withInitialPrice(Real)
Definition: trscashflow.cpp:65
TRSLeg(const std::vector< Date > &valuationDates, const std::vector< Date > &paymentDates, const Real notional, const QuantLib::ext::shared_ptr< Index > &index, const QuantLib::ext::shared_ptr< FxIndex > &fxIndex=nullptr)
Definition: trscashflow.cpp:59
cashflow paying the total return of an asset