Quantlib将日期向量传递给Schedule类 [英] Quantlib passing a date vector to Schedule class

查看:147
本文介绍了Quantlib将日期向量传递给Schedule类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I appreciate that Quantlib Schedule class can take a date vector as constructor. I have successfully built a schedule via this way. However, when I pass this schedule to vanillaswap constructor, the code starts to generate error on function bool Schedule::isRegular(Size i) const in schedule.cpp. Here is part of my code related to this error:

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而失败.

When I run my code, it fails due to this isRegular_.size() return 0.

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

I found this link is useful: http://www.implementingquantlib.com/2014/11/odds-and-ends-date-calculations.html

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

However, I am not sure if I am complete understand the last paragraph about how to fix this problem. Is there anyone can give me an example here?

非常感谢

推荐答案

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

Since a few releases, the constructor that takes a vector of dates has been expanded (as suggested in the link you quoted) to take additional parameters. It is now declared as:

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<bool>(n, true)传递,其中n是计划中的日期数(当然,假设期间是固定的;如果您使用的是短期或长期优惠券,则应放置false在相应位置的向量中.)

so you can pass any missing information that the schedule is not able to figure out from the dates; for example, you can pass isRegular as vector<bool>(n, true) where n is the number of dates in the schedule (assuming the periods are regular, of course; in case you have a short or long coupon, you should put a false in the vector at the corresponding position).

这篇关于Quantlib将日期向量传递给Schedule类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆