Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
cashflowresults.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
21#include <ql/cashflows/averagebmacoupon.hpp>
22#include <ql/cashflows/couponpricer.hpp>
23#include <ql/cashflows/floatingratecoupon.hpp>
24#include <ql/cashflows/indexedcashflow.hpp>
25#include <ql/cashflows/inflationcoupon.hpp>
27namespace QuantExt {
28
29using namespace QuantLib;
30
31std::ostream& operator<<(std::ostream& out, const CashFlowResults& t) {
32 if (t.amount != Null<Real>())
33 out << t.amount;
34 else
35 out << "?";
36 out << " " << t.currency;
37 if (t.payDate != Null<Date>())
38 out << " @ " << QuantLib::io::iso_date(t.payDate);
39 return out;
40}
41
42CashFlowResults standardCashFlowResults(const QuantLib::ext::shared_ptr<CashFlow>& c, const Real multiplier,
43 const std::string& type, const Size legNo, const Currency& currency,
44 const Handle<YieldTermStructure>& discountCurve) {
45
46 CashFlowResults cfResults = populateCashFlowResultsFromCashflow(c, multiplier, legNo, currency);
47
48 if (!type.empty()) {
49 cfResults.type = type;
50 }
51
52 if (!discountCurve.empty()) {
53 cfResults.discountFactor = discountCurve->discount(cfResults.payDate);
54 cfResults.presentValue = cfResults.amount * cfResults.discountFactor;
55 }
56 return cfResults;
57}
58
59CashFlowResults populateCashFlowResultsFromCashflow(const QuantLib::ext::shared_ptr<QuantLib::CashFlow>& c,
60 const QuantLib::Real multiplier, const QuantLib::Size legNo,
61 const QuantLib::Currency& currency) {
62
63 Date today = Settings::instance().evaluationDate();
64
65 CashFlowResults cfResults;
66
67 cfResults.amount = c->amount() * multiplier;
68 cfResults.payDate = c->date();
69
70 if (!currency.empty())
71 cfResults.currency = currency.code();
72
73 cfResults.legNumber = legNo;
74
75 if (auto cpn = QuantLib::ext::dynamic_pointer_cast<Coupon>(c)) {
76 cfResults.rate = cpn->rate();
77 cfResults.accrualStartDate = cpn->accrualStartDate();
78 cfResults.accrualEndDate = cpn->accrualEndDate();
79 cfResults.accrualPeriod = cpn->accrualPeriod();
80 cfResults.accruedAmount = cpn->accruedAmount(today);
81 cfResults.notional = cpn->nominal();
82 cfResults.type = "Interest";
83 if (auto ptrFloat = QuantLib::ext::dynamic_pointer_cast<QuantLib::FloatingRateCoupon>(cpn)) {
84 cfResults.fixingDate = ptrFloat->fixingDate();
85 cfResults.fixingValue = ptrFloat->index()->fixing(cfResults.fixingDate);
86 if (cfResults.fixingDate > today)
87 cfResults.type = "InterestProjected";
88 } else if (auto ptrInfl = QuantLib::ext::dynamic_pointer_cast<QuantLib::InflationCoupon>(cpn)) {
89 // We return the last fixing inside the coupon period
90 cfResults.fixingDate = ptrInfl->fixingDate();
91 cfResults.fixingValue = ptrInfl->indexFixing();
92 cfResults.type = "Inflation";
93 } else if (auto ptrBMA = QuantLib::ext::dynamic_pointer_cast<QuantLib::AverageBMACoupon>(cpn)) {
94 // We return the last fixing inside the coupon period
95 cfResults.fixingDate = ptrBMA->fixingDates().end()[-2];
96 cfResults.fixingValue = ptrBMA->pricer()->swapletRate();
97 if (cfResults.fixingDate > today)
98 cfResults.type = "BMAaverage";
99 }
100 } else {
101 cfResults.type = "Notional";
102 if (auto ptrIndCf = QuantLib::ext::dynamic_pointer_cast<QuantLib::IndexedCashFlow>(c)) {
103 cfResults.fixingDate = ptrIndCf->fixingDate();
104 cfResults.fixingValue = ptrIndCf->index()->fixing(cfResults.fixingDate);
105 cfResults.type = "Index";
106 } else if (auto ptrFxlCf = QuantLib::ext::dynamic_pointer_cast<QuantExt::FXLinkedCashFlow>(c)) {
107 // We return the last fixing inside the coupon period
108 cfResults.fixingDate = ptrFxlCf->fxFixingDate();
109 cfResults.fixingValue = ptrFxlCf->fxRate();
110 }
111 }
112 return cfResults;
113}
114} // namespace QuantExt
class holding cashflow-related results
An FX linked cashflow.
CashFlowResults standardCashFlowResults(const QuantLib::ext::shared_ptr< CashFlow > &c, const Real multiplier, const std::string &type, const Size legNo, const Currency &currency, const Handle< YieldTermStructure > &discountCurve)
std::ostream & operator<<(std::ostream &out, EquityReturnType t)
CashFlowResults populateCashFlowResultsFromCashflow(const QuantLib::ext::shared_ptr< QuantLib::CashFlow > &c, const QuantLib::Real multiplier, const QuantLib::Size legNo, const QuantLib::Currency &currency)