@@ -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