1919#include < orea/engine/cashflowreportgenerator.hpp>
2020
2121#include < ored/utilities/indexnametranslator.hpp>
22+ #include < ored/utilities/marketdata.hpp>
2223
2324#include < qle/cashflows/averageonindexedcoupon.hpp>
2425#include < qle/cashflows/cappedflooredaveragebmacoupon.hpp>
@@ -54,6 +55,13 @@ std::vector<TradeCashflowReportData> generateCashflowReportData(const ext::share
5455 const std::string& configuration,
5556 const bool includePastCashflows) {
5657
58+ string specificDiscount = trade->envelope ().additionalField (" discount_curve" , false );
59+
60+ Handle<YieldTermStructure> specificDiscountCurve;
61+
62+ if (!specificDiscount.empty ())
63+ specificDiscountCurve = indexOrYieldCurve (market, specificDiscount, configuration);
64+
5765 Date asof = Settings::instance ().evaluationDate ();
5866
5967 std::vector<TradeCashflowReportData> result;
@@ -78,6 +86,7 @@ std::vector<TradeCashflowReportData> generateCashflowReportData(const ext::share
7886
7987 // additional result based cashflow reporting
8088
89+
8190 QL_REQUIRE (cashFlowResults->second .type () == typeid (std::vector<CashFlowResults>),
8291 " internal error: cashflowResults type does not match CashFlowResults: '"
8392 << cashFlowResults->second .type ().name () << " '" );
@@ -110,9 +119,10 @@ std::vector<TradeCashflowReportData> generateCashflowReportData(const ext::share
110119 if (cf.discountFactor != Null<Real>())
111120 discountFactor = cf.discountFactor ;
112121 else if (!cf.currency .empty () && cf.payDate != Null<Date>() && market) {
122+ auto discountCurve = specificDiscount.empty ()? market->discountCurve (cf.currency , configuration):specificDiscountCurve;
113123 discountFactor = cf.payDate < asof
114124 ? 0.0
115- : market-> discountCurve (cf. currency , configuration) ->discount (cf.payDate );
125+ : discountCurve->discount (cf.payDate );
116126 }
117127 if (cf.presentValue != Null<Real>()) {
118128 presentValue = cf.presentValue * multiplier;
@@ -191,10 +201,11 @@ std::vector<TradeCashflowReportData> generateCashflowReportData(const ext::share
191201 for (size_t i = 0 ; i < legs.size (); i++) {
192202 const QuantLib::Leg& leg = legs[i];
193203 bool payer = trade->legPayers ()[i];
204+
194205 string ccy = trade->legCurrencies ()[i];
195206 Handle<YieldTermStructure> discountCurve;
196207 if (market)
197- discountCurve = market->discountCurve (ccy, configuration);
208+ discountCurve = specificDiscount. empty ()? market->discountCurve (ccy, configuration):specificDiscountCurve ;
198209 for (size_t j = 0 ; j < leg.size (); j++) {
199210 QuantLib::ext::shared_ptr<QuantLib::CashFlow> ptrFlow = leg[j];
200211 Date payDate = ptrFlow->date ();
@@ -361,7 +372,8 @@ std::vector<TradeCashflowReportData> generateCashflowReportData(const ext::share
361372 effectiveAmount = amount * multiplier;
362373
363374 if (market) {
364- discountFactor = ptrFlow->hasOccurred (asof) ? 0.0 : discountCurve->discount (payDate);
375+ auto dcurve=specificDiscount.empty ()? discountCurve: specificDiscountCurve;
376+ discountFactor = ptrFlow->hasOccurred (asof) ? 0.0 : dcurve->discount (payDate);
365377 if (effectiveAmount != Null<Real>())
366378 presentValue = discountFactor * effectiveAmount;
367379 try {
0 commit comments