Skip to content

Commit 37fe6cc

Browse files
author
O'Brien
committed
QPR-13736: use nthWeekday function
1 parent f4e15d7 commit 37fe6cc

1 file changed

Lines changed: 3 additions & 12 deletions

File tree

OREData/ored/utilities/marketdata.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -333,22 +333,13 @@ std::pair<Date, Date> getOiFutureStartEndDate(QuantLib::Month expiryMonth, Quant
333333
}
334334

335335
Date getMmFutureExpiryDate(QuantLib::Month expiryMonth, QuantLib::Natural expiryYear,
336-
FutureConvention::DateGenerationRule rule) {
336+
FutureConvention::DateGenerationRule rule) {
337337
Date refDate(1, expiryMonth, expiryYear);
338-
338+
339339
if (rule == FutureConvention::DateGenerationRule::IMM) {
340340
return IMM::nextDate(refDate, false); // Third Wednesday
341341
} else if (rule == FutureConvention::DateGenerationRule::SecondThursday) {
342-
// Calculate second Thursday of the month
343-
// Find the first Thursday
344-
Weekday targetWeekday = Thursday;
345-
Integer dayOfWeek = refDate.weekday();
346-
Integer daysToThursday = (targetWeekday - dayOfWeek + 7) % 7;
347-
Date firstThursday = refDate + daysToThursday * Days;
348-
349-
// Add 7 days to get second Thursday
350-
Date secondThursday = firstThursday + 7 * Days;
351-
return secondThursday;
342+
return Date::nthWeekday(2, Thursday, refDate.month(), refDate.year());
352343
} else {
353344
QL_FAIL("getMmFutureExpiryDate: DateGenerationRule '" << rule << "' not supported for MM Futures");
354345
}

0 commit comments

Comments
 (0)