Skip to content

Commit bc63d30

Browse files
pcaspersjenkins
authored andcommitted
QPR-11773 make cf and leg no member of cashflow info class, fix
1 parent 6b1a77b commit bc63d30

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

QuantExt/qle/pricingengines/mcmultilegbaseengine.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,22 +68,24 @@ Real McMultiLegBaseEngine::time(const Date& d) const {
6868

6969
McMultiLegBaseEngine::CashflowInfo McMultiLegBaseEngine::createCashflowInfo(boost::shared_ptr<CashFlow> flow,
7070
const Currency& payCcy, Real payer,
71-
Size legNo, Size cashflowNo) const {
71+
Size legNo, Size cfNo) const {
7272

7373
constexpr Real tinyTime = 1E-10;
7474

7575
CashflowInfo info;
7676

7777
// set some common info: pay time, pay ccy index in the model, payer, exercise into decision time
7878

79+
info.legNo = legNo;
80+
info.cfNo = cfNo;
7981
info.payTime = time(flow->date());
8082
info.payCcyIndex = model_->ccyIndex(payCcy);
8183
info.payer = payer;
8284

8385
if (auto cpn = boost::dynamic_pointer_cast<Coupon>(flow)) {
8486
QL_REQUIRE(cpn->accrualStartDate() < flow->date(),
8587
"McMultiLegBaseEngine::createCashflowInfo(): coupon leg "
86-
<< legNo << " cashflow " << cashflowNo << " has accrual start date (" << cpn->accrualStartDate()
88+
<< legNo << " cashflow " << cfNo << " has accrual start date (" << cpn->accrualStartDate()
8789
<< ") >= pay date (" << flow->date()
8890
<< "), which breaks an assumption in the engine. This situation is unexpected.");
8991
info.exIntoCriterionTime = time(cpn->accrualStartDate()) + tinyTime;
@@ -237,8 +239,7 @@ McMultiLegBaseEngine::CashflowInfo McMultiLegBaseEngine::createCashflowInfo(boos
237239
effectiveRate = RandomVariable(n, ibor->gearing()) * fixing + RandomVariable(n, ibor->spread());
238240
}
239241

240-
return RandomVariable(states.at(0).at(0)->size(), ibor->nominal() * ibor->accrualPeriod()) * effectiveRate *
241-
fxFixing;
242+
return RandomVariable(n, ibor->nominal() * ibor->accrualPeriod()) * effectiveRate * fxFixing;
242243
};
243244
return info;
244245
}
@@ -267,7 +268,7 @@ McMultiLegBaseEngine::CashflowInfo McMultiLegBaseEngine::createCashflowInfo(boos
267268
// if (auto cms = boost::dynamic_pointer_cast<CmsCoupon>(flow)) {
268269
// }
269270

270-
QL_FAIL("McMultiLegBaseEngine::createCashflowInfo(): unhandled coupon leg " << legNo << " cashflow " << cashflowNo);
271+
QL_FAIL("McMultiLegBaseEngine::createCashflowInfo(): unhandled coupon leg " << legNo << " cashflow " << cfNo);
271272
} // createCashflowInfo()
272273

273274
Size McMultiLegBaseEngine::timeIndex(const Time t, const std::set<Real>& times) const {
@@ -334,10 +335,11 @@ void McMultiLegBaseEngine::calculate() const {
334335

335336
std::vector<CashflowInfo> cashflowInfo;
336337

337-
Size legNo = 0, cashflowNo = 0;
338+
Size legNo = 0;
338339
for (auto const& leg : leg_) {
339340
Currency currency = currency_[legNo];
340341
Real payer = payer_[legNo];
342+
Size cashflowNo = 0;
341343
for (auto const& cashflow : leg) {
342344
// we can skip cashflows that are paid
343345
if (cashflow->date() <= today_)

QuantExt/qle/pricingengines/mcmultilegbaseengine.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class McMultiLegBaseEngine {
8787
private:
8888
// data structure storing info needed to generate the amount for a cashflow
8989
struct CashflowInfo {
90+
Size legNo = Null<Size>(), cfNo = Null<Size>();
9091
Real payTime = Null<Real>();
9192
Real exIntoCriterionTime = Null<Real>();
9293
Size payCcyIndex = Null<Size>();
@@ -102,7 +103,7 @@ class McMultiLegBaseEngine {
102103

103104
// create the info for a given flow
104105
CashflowInfo createCashflowInfo(boost::shared_ptr<CashFlow> flow, const Currency& payCcy, Real payer, Size legNo,
105-
Size cashflowNo) const;
106+
Size cfNo) const;
106107

107108
// get the index of a time in the given simulation times set
108109
Size timeIndex(const Time t, const std::set<Real>& simulationTimes) const;

0 commit comments

Comments
 (0)