【问题标题】:Quantlib: Date Advance Function for TimeUnit "days" - Bug or Feature?Quantlib:TimeUnit“天”的日期提前功能-错误还是功能?
【发布时间】:2020-06-18 07:55:13
【问题描述】:

关于 C++ Quantlib 中的 date-advance 函数,我有一个小问题。 我想为具有付款工作日约定“在先”的产品使用付款抵消(以天为单位),但付款日期始终设置为周末后的第一天,而付款日期在周末。这是因为当“days”被移交给“advance”函数时,“advance”函数会忽略工作日约定,请参见此处:

 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);
    }
}

这是故意实施的吗? 附: “调整”- 函数正确使用工作日约定!

【问题讨论】:

    标签: python c++ quantlib quantlib-swig


    【解决方案1】:

    是的,如果它不破坏客户端代码,这是我要解决的问题之一。对于天数,Calendar::advance 表示“提前数营业天”;约定不适用,因为通过这种方式前进,您永远不会进入假期。

    如果您的意思是“提前数日历天(例如,2)然后调整”,您可以这样写:

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

    【讨论】:

      【解决方案2】:

      是的,付款抵消始终是工作日。所以 OISRateHelper 的调用有点误导,因为你可以交出一个工作日约定来进行支付抵消。

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-05-08
        • 1970-01-01
        • 1970-01-01
        • 2015-01-20
        • 2021-02-08
        • 1970-01-01
        • 1970-01-01
        • 2011-04-06
        相关资源
        最近更新 更多