Quantlib:时间单位“天”的日期提前功能错误或功能?

2024-04-26 23:38:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个关于C++ QuooLIB中日期提前函数的小问题。 我想对具有“Previous”付款工作日约定的产品使用付款补偿(以天为单位),但付款日期始终设置为周末后的第一天,即付款日期在周末。这是因为“提前”功能忽略了将“天”移交给“提前”功能时的工作日约定,请参见此处:

 Date Calendar::advance(const Date& d,
                       Integer n, TimeUnit unit,
                       BusinessDayConvention c,
                       bool endOfMonth) const {
    QL_REQUIRE(d!=Date(), "null date");
    if (n == 0) {
        return adjust(d,c);
    } else if (unit == Days) {
        Date d1 = d;
        if (n > 0) {
            while (n > 0) {
                d1++;
                while (isHoliday(d1))
                    d1++;
                n--;
            }
        } else {
            while (n < 0) {
                d1--;
                while(isHoliday(d1))
                    d1--;
                n++;
            }
        }
        return d1;
    } else if (unit == Weeks) {
        Date d1 = d + n*unit;
        return adjust(d1,c);
    } else {
        Date d1 = d + n*unit;

        // we are sure the unit is Months or Years
        if (endOfMonth && isEndOfMonth(d))
            return Calendar::endOfMonth(d1);

        return adjust(d1, c);
    }
}

这是故意的吗? P.s.“调整”-功能正确使用工作日惯例


Tags: 功能datereturnifunitelsecalendard1
2条回答

是的,如果它没有破坏客户端代码,这是我要修复的事情之一。在天的情况下,Calendar::advance表示“提前若干营业天”;该公约不适用,因为通过这种方式前进,你永远不会在度假时着陆

如果您的意思是“提前若干日历天(例如,2天),然后进行调整”,您可以准确地写下:

Date paymentDate = calendar.adjust(date + 2, convention);

是的,付款抵销始终为工作日。因此,OISRateHelper的调用有点误导,因为您可以为支付补偿提交工作日约定

ql.OISRateHelper(0,
                     ql.Period(swapMaturity),
                     ql.QuoteHandle(rate),
                     eoniaIndex,
                     termStructureHandle,
                     False,
                     paymentOffset,
                     ql.Preceding
                     )

相关问题 更多 >