QuantLib 金融计算——基本组件之 Schedule 类
如果未做特别说明,文中的程序都是 Python3 代码。
QuantLib 金融计算——基本组件之 Schedule 类
Schedule 类用于构造一个特定的日期列表,例如债券的付息日列表,是 QuantLib 中固定收益类产品分析最常用到的组件。
载入 QuantLib:
import QuantLib as ql
print(ql.__version__)
1.10
Schedule 对象的构造
Schedule 类对象的构造依赖于之前介绍的几个基本组件。
Schedule(effectiveDate ,
terminationDate ,
tenor,
calendar,
convention,
terminationDateConvention,
rule,
endOfMonth,
firstDate = Date (),
nextToLastDate = Date ())
这些变量的类型和解释如下:
effectiveDate、terminationDate:日期,日历列表的起始、结束日期,例如债券的起息日和到期日。tenor:Period对象,相邻两个日期的间隔,例如债券的付息频率(1 年或 6 个月)或利率互换的利息重置频率(3 个月)。calendar:日历表,生成日期所遵循的特定日历表。convention:整数,如何调整非工作日(除最后一个日期外),取值范围是 quantlib-python 的一些预留变量。terminationDateConvention:整数,如果最后一个日期是非工作日,该如何调整,取值范围是 quantlib-python 的一些预留变量。rule:DateGeneration的成员,生成日期的规则。endOfMonth:如果起始日期在月末,是否要求其他日期也要安排在月末(除最后一个日期外)。firstDate,nextToLastDate(可选):日期,专门为生成方法rule提供的起始、结束日期(不常用)。
作为“容器”的 Schedule 对象
Schedule 对象的行为和 Python 中的 list 非常相似,作为一种存储 Date 对象的序列容器存在。因此下面两个函数是可用的:
len(sch):返回Schedule对象sch内日期的个数。[i]:返回第i个日期。
作为序列容器,和 list 一样,Schedule 对象也是可迭代的。
假设想要获得 2017 年每月首个工作日的列表:
- 起始、结束日期分别是 2017-01-01 和 2017-12-01。
- 时间间隔是一个月。
- 日历表遵循中国银行间市场的规定
- 遇到非工作日就递延到下一工作日
例子 1:
def testingSchedule1():
effectiveDate = ql.Date(1, ql.January, 2017)
terminationDate = ql.Date(1, ql.December, 2017)
tenor = ql.Period(1, ql.Months)
calendar = ql.China(ql.China.IB)
convention = ql.Following
terminationDateConvention = ql.Following
rule = ql.DateGeneration.Forward
endOfMonth = False
mySched = ql.Schedule(
effectiveDate,
terminationDate,
tenor,
calendar,
convention,
terminationDateConvention,
rule,
endOfMonth)
for i in range(len(mySched)):
print(mySched[i])
print('------')
for i in mySched:
print(i)
January 3rd, 2017
February 3rd, 2017
March 1st, 2017
April 1st, 2017
May 2nd, 2017
June 1st, 2017
July 3rd, 2017
August 1st, 2017
September 1st, 2017
October 9th, 2017
November 1st, 2017
December 1st, 2017
------
January 3rd, 2017
February 3rd, 2017
March 1st, 2017
April 1st, 2017
May 2nd, 2017
June 1st, 2017
July 3rd, 2017
August 1st, 2017
September 1st, 2017
October 9th, 2017
November 1st, 2017
December 1st, 2017
一些常用的成员函数
until(d):从日期列表中截取前半部分,并保证最后一个日期是d。isRegular(i):判断第i个区间是否完整。这个概念需要解释以下:如果一个Schedule对象含有n个日期,那么这个对象就含有n-1个区间。如果第i个区间的长度和事先规定的时间间隔一致,那么这个区间就是完整的(Regular)。
例子 2:
def testingSchedule2():
effectiveDate = ql.Date(1, ql.January, 2017)
terminationDate = ql.Date(1, ql.December, 2017)
tenor = ql.Period(1, ql.Months)
calendar = ql.China(ql.China.IB)
convention = ql.Following
terminationDateConvention = ql.Following
rule = ql.DateGeneration.Forward
endOfMonth = False
mySched = ql.Schedule(
effectiveDate,
terminationDate,
tenor,
calendar,
convention,
terminationDateConvention,
rule,
endOfMonth)
mySched = mySched.until(ql.Date(15, ql.June, 2017))
for i in mySched:
print(i)
print('------')
for i in range(len(mySched) - 1):
print('{}-th internal is regular? {}'.format(
i + 1, mySched.isRegular(i + 1)))
January 3rd, 2017
February 3rd, 2017
March 1st, 2017
April 1st, 2017
May 2nd, 2017
June 1st, 2017
June 15th, 2017
------
1-th internal is regular? True
2-th internal is regular? True
3-th internal is regular? True
4-th internal is regular? True
5-th internal is regular? True
6-th internal is regular? False
最后一个区间的长度只有 15 天,所以是“不完整的”。
QuantLib 金融计算——基本组件之 Schedule 类的更多相关文章
- QuantLib 金融计算——基本组件之 Currency 类
目录 QuantLib 金融计算--基本组件之 Currency 类 概述 构造函数 成员函数 如果未做特别说明,文中的程序都是 python3 代码. QuantLib 金融计算--基本组件之 Cu ...
- QuantLib 金融计算——基本组件之 Date 类
目录 QuantLib 金融计算--基本组件之 Date 类 Date 对象的构造 一些常用的成员函数 一些常用的静态函数 为估值计算配置日期 如果未做特别说明,文中的程序都是 Python3 代码. ...
- QuantLib 金融计算——基本组件之 Calendar 类
目录 QuantLib 金融计算--基本组件之 Calendar 类 Calendar 对象的构造 一些常用的成员函数 自定义假期列表 工作日修正 如果未做特别说明,文中的程序都是 Python3 代 ...
- QuantLib 金融计算——基本组件之 DayCounter 类
目录 QuantLib 金融计算--基本组件之 DayCounter 类 DayCounter 对象的构造 一些常用的成员函数 如果未做特别说明,文中的程序都是 Python3 代码. QuantLi ...
- QuantLib 金融计算——基本组件之 DateGeneration 类
目录 QuantLib 金融计算--基本组件之 DateGeneration 类 QuantLib 金融计算--基本组件之 DateGeneration 类 许多产品的估值依赖于对未来现金流的分析,因 ...
- QuantLib 金融计算——基本组件之 Index 类
目录 QuantLib 金融计算--基本组件之 Index 类 QuantLib 金融计算--基本组件之 Index 类 Index 类用于表示已知的指数或者收益率,例如 Libor 或 Shibor ...
- QuantLib 金融计算——基本组件之 InterestRate 类
目录 QuantLib 金融计算--基本组件之 InterestRate 类 InterestRate 对象的构造 一些常用的成员函数 如果未做特别说明,文中的程序都是 Python3 代码. Qua ...
- QuantLib 金融计算——基本组件之 ExchangeRateManager 类
目录 QuantLib 金融计算--基本组件之 ExchangeRateManager 类 概述 Money 类中的汇率转换配置 ExchangeRateManager 函数 如果未做特别说明,文中的 ...
- QuantLib 金融计算——基本组件之 Money 类
目录 QuantLib 金融计算--基本组件之 Money 类 概述 构造函数 成员函数 如果未做特别说明,文中的程序都是 python3 代码. QuantLib 金融计算--基本组件之 Money ...
随机推荐
- MVC知识记录
1.完整深入分析 MVC请求机制:http://blog.jobbole.com/85033/ 2.MVC入门:http://www.aizhengli.com/givecase-aspnet-5-m ...
- Castle ActiveRecord学习(七)使用日志
暂无 参考:http://terrylee.cnblogs.com/archive/2006/04/14/374829.html
- Zookeeper 目录
Zookeeper 目录 Zookeeper 致力于提供一个高性能.高可用,且具有严格的顺序访问控制能力(主要是写操作的严格顺序性)的分布式协调服务.以下是我整理的笔记. 一.分布式理论基础 1.1 ...
- Nuget安装 Identity组件。
Install-Package Microsoft.AspNet.Identity.EntityFramework –Version 2.0.0(2.2.1) Install-Package Micr ...
- oj1089-1096总结(输入输出练习)
//无限输出类 #include<stdio.h>int main(void){ int a,b; while((scanf("%d %d",&a,&b ...
- Problem of Uninstall Cloudera: Cannot Add Hdfs and Reported Cannot Find CDH's bigtop-detect-javahome
1. Problem We wrote a shell script to uninstall Cloudera Manager(CM) that run in a cluster with 3 li ...
- [react001] 使用webpack自动构建react 项目
1.react 简介 React 是一个Facebook出品的前端UI开发框架.react官方的tutorials 为了让人容易上手,并没有给在平常工作使用react的详细配置,随意学习的深入,你为了 ...
- TSQL--验证身份证是否有效
/****** Object: UserDefinedFunction [dbo].[udf_IsvalidIDCard] Script Date: 02/27/2014 16:03:20 ***** ...
- TSQL--SQL SERVER 常用系统变量
----------全局变量select @@version as '版本';---------------------------返回当前数据库的版本信息 select APP_NAME ( ) a ...
- go开源项目influxdb-relay源码分析(一)
influxdb-relay项目地址: https://github.com/influxdata/influxdb-relay,主要作为负载均衡节点,写入多个influxdb节点,起到高可用效果. ...