Skip to content

Commit 1ffd511

Browse files
mgronckijenkins
authored andcommitted
QPR-9859 bugfix close out grid and dategrid
1 parent d033111 commit 1ffd511

2 files changed

Lines changed: 22 additions & 27 deletions

File tree

OREAnalytics/orea/engine/valuationengine.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,10 +357,11 @@ std::pair<double, double> ValuationEngine::populateCube(
357357
simMarket_->updateDate(d);
358358
}
359359
// We can skip this step, if we have done that above in the close-out date section
360-
if (!scenarioUpdated)
360+
if (!scenarioUpdated){
361361
simMarket_->updateScenario(d);
362+
}
362363
// Always with fixing update here, in contrast to the close-out date section
363-
simMarket_->postUpdate(d, true);
364+
simMarket_->postUpdate(d, !isStickyDate || isValueDate);
364365
// Aggregation scenario data update on valuation dates only
365366
if (isValueDate) {
366367
simMarket_->updateAsd(d);
@@ -371,12 +372,12 @@ std::pair<double, double> ValuationEngine::populateCube(
371372
updateTime += timer.elapsed().wall * 1e-9;
372373

373374
timer.start();
374-
if (isStickyDate) // switch on again, if sticky
375+
if (isStickyDate && !isValueDate) // switch on again, if sticky
375376
tradeExercisable(false, trades);
376377
// loop over trades
377378
runCalculators(!isValueDate, trades, tradeHasError, calculators, outputCube, outputCubeNettingSet, d, cubeDateIndex,
378379
sample, simMarket_->label());
379-
if (isStickyDate) // switch on again, if sticky
380+
if (isStickyDate && !isValueDate) // switch on again, if sticky
380381
tradeExercisable(true, trades);
381382
// loop over counterparty names
382383
if (isValueDate) {

OREData/ored/utilities/dategrid.cpp

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -219,38 +219,32 @@ void DateGrid::addCloseOutDates(const QuantLib::Period& p) {
219219
}
220220
}
221221
} else {
222-
std::vector<Date> tmpDates;
223-
std::vector<bool> tmpIsCloseOutDate, tmpIsValuationDate;
222+
std::set<QuantLib::Date> tmpDates;
223+
std::set<QuantLib::Date> tmpValueDates;
224224
for (Size i = 0; i < dates_.size(); ++i) {
225225
Date c;
226226
if (p.units() == Days)
227227
c = calendar_.adjust(dates_[i] + p);
228228
else
229229
c = calendar_.advance(dates_[i], p, Following, false);
230230
closeOutDates_[c] = dates_[i];
231-
if (i < dates_.size() - 1) {
232-
// adjust the grid to ensure no overlap in valuation and closeout dates
233-
if (c >= dates_[i + 1]) {
234-
dates_[i + 1] = calendar_.advance(c, QuantLib::Period(1, QuantLib::Days));
235-
// check that the grid is still monotonic
236-
if ((i + 2) < dates_.size()) {
237-
QL_REQUIRE(dates_[i + 1] < dates_[i + 2],
238-
"date grid is no longer monotonic: " << dates_[i + 1] << ", " << dates_[i + 2]);
239-
}
240-
}
241-
QL_REQUIRE(c < dates_[i + 1],
242-
"close out date " << c << " does not lie before next grid date " << dates_[i + 1]);
231+
tmpDates.insert(dates_[i]);
232+
tmpDates.insert(c);
233+
tmpValueDates.insert(dates_[i]);
234+
}
235+
dates_.clear();
236+
dates_.assign(tmpDates.begin(), tmpDates.end());
237+
isCloseOutDate_ = std::vector<bool>(dates_.size(), false);
238+
isValuationDate_ = std::vector<bool>(dates_.size(), true);
239+
for(size_t i = 0; i < dates_.size(); ++i){
240+
Date d = dates_[i];
241+
if(closeOutDates_.count(d) == 1){
242+
isCloseOutDate_[i] = true;
243+
}
244+
if(tmpValueDates.count(d) == 0){
245+
isValuationDate_[i] = false;
243246
}
244-
tmpDates.push_back(dates_[i]);
245-
tmpDates.push_back(c);
246-
tmpIsCloseOutDate.push_back(false);
247-
tmpIsCloseOutDate.push_back(true);
248-
tmpIsValuationDate.push_back(true);
249-
tmpIsValuationDate.push_back(false);
250247
}
251-
dates_ = tmpDates;
252-
isCloseOutDate_ = tmpIsCloseOutDate;
253-
isValuationDate_ = tmpIsValuationDate;
254248
// FIXME ... (is that needed anywhere ?)
255249
tenors_ = std::vector<QuantLib::Period>(dates_.size(), 0 * Days);
256250
times_.resize(dates_.size());

0 commit comments

Comments
 (0)