【问题标题】:Quantlib passing a date vector to Schedule classQuantlib 将日期向量传递给 Schedule 类
【发布时间】:2016-11-23 17:11:05
【问题描述】:

我很欣赏 Quantlib Schedule 类可以将日期向量作为构造函数。我已经通过这种方式成功地建立了一个时间表。但是,当我将此计划传递给 vanillaswap 构造函数时,代码开始在 schedule.cpp 中的函数 bool Schedule::isRegular(Size i) const 上生成错误。这是我与此错误相关的部分代码:

vector<Date> fixedDates;
vector<Date> floatDates;

fixedDates.push_back(Date(15, April, 2016));
fixedDates.push_back(Date(18, April, 2017));
floatDates.push_back(Date(15, April, 2016));
floatDates.push_back(Date(15, July, 2016));
floatDates.push_back(Date(17, October, 2016));
floatDates.push_back(Date(17, January, 2017));
floatDates.push_back(Date(18, April, 2017));

Schedule fixedSchedule(fixedDates);
Schedule floatSchedule(floatDates);

VanillaSwap::Type swapType = VanillaSwap::Payer;
VanillaSwap swap(swapType, nominal, fixedSchedule, fixedRate, Actual365Fixed(), floatSchedule, libor, spread, Actual365Fixed());

当我运行我的代码时,由于 isRegular_.size() 返回 0,它失败了。

我发现这个链接很有用: http://www.implementingquantlib.com/2014/11/odds-and-ends-date-calculations.html

但是,我不确定我是否完全理解关于如何解决此问题的最后一段。有没有人可以在这里举个例子?

非常感谢

【问题讨论】:

    标签: c++ quantlib


    【解决方案1】:

    自几个版本以来,采用日期向量的构造函数已被扩展(如您引用的链接中所建议)以采用其他参数。现在声明为:

    Schedule(const std::vector<Date>&,
             const Calendar& calendar = NullCalendar(),
             const BusinessDayConvention
                                    convention = Unadjusted,
             boost::optional<BusinessDayConvention>
                     terminationDateConvention = boost::none,
             const boost::optional<Period> tenor = boost::none,
             boost::optional<DateGeneration::Rule> rule = boost::none,
             boost::optional<bool> endOfMonth = boost::none,
             const std::vector<bool>& isRegular = std::vector<bool>(0));
    

    这样您就可以传递日程安排无法从日期中找出的任何缺失信息;例如,您可以将isRegular 传递为vector&lt;bool&gt;(n, true),其中n 是计划中的日期数(当然,假设期间是定期的;如果您有短期或长期优惠券,您应该放一个@ 987654325@在向量中的对应位置)。

    【讨论】:

    • 使用 QuantLib 1.16,我正在尝试使用 Python 绑定的自定义计划来实现 FixedRateBond。我无法让它工作,它在实例化FixedRateBond 时不断抛出full interface (tenor) not available。我作为时间表传递的是ql.Schedule(interest_payment_dates, ql.NullCalendar(), ql.Unadjusted, None, None, None, True, np.repeat(False, len(interest_payment_dates)-1).tolist()),其中interest_payment_dates 是一些Dates 的数组。这是怎么来的?
    猜你喜欢
    • 2020-06-10
    • 2017-12-18
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 2015-08-08
    • 1970-01-01
    相关资源
    最近更新 更多