如何获取时间表的 "time" 值

How to obtain the "time" values of a schedule

假设固定利率债券的时间表如下面的示例代码所示。

我可以使用 businessDaysBetween 函数获取期限之间的天数。

现在我要"time value"。有没有不创建新函数的方法?

这是预期的结果:

May 14th, 2012          .5
November 14th, 2012     .5
May 14th, 2013          .5
November 14th, 2013     .5
May 14th, 2014          .5
November 14th, 2014     .5
May 14th, 2015          .5
November 16th, 2015     .505556
May 16th, 2016          .5
November 14th, 2016     .49444

代码如下:

from QuantLib import *
import pandas as pd


effective_date = Date(14, 11, 2011)
termination_date = Date(14, 11, 2016)
tenor = Period(Semiannual)
calendar = UnitedStates()
business_convention = ModifiedFollowing
termination_business_convention = Following
date_generation = DateGeneration.Forward
end_of_month = False
day_count = Thirty360()
schedule = Schedule(effective_date,
                    termination_date,
                    tenor,
                    calendar,
                    business_convention,
                    termination_business_convention,
                    date_generation,
                    end_of_month)
t = []
for i, d in  enumerate(schedule):
    tmp = i+1, d,
    t.append(tmp)
df = pd.DataFrame(t,columns = ['tenorNo','tenorDate'])

nbDays = []
for x in df['tenorNo'] :
    if  x == 1:
        tmp = 0
    else:
        tmp = calendar.businessDaysBetween(df['tenorDate'][x-2],df['tenorDate'][x-1])
        nbDays.append(tmp)

    df['nbDays'] = nbDays

print df
    tenorNo            tenorDate  nbDays
0         1  November 14th, 2011       0
1         2       May 14th, 2012     125
2         3  November 14th, 2012     127
3         4       May 14th, 2013     124
4         5  November 14th, 2013     127
5         6       May 14th, 2014     124
6         7  November 14th, 2014     127
7         8       May 14th, 2015     124
8         9  November 16th, 2015     127
9        10       May 16th, 2016     125
10       11  November 14th, 2016     125

这就是 DayCounter 实例的用途。时间将取决于您选择的天数规则(例如,您似乎使用的是 30/360)。

通话中

day_count.yearFraction(date1, date2)

将 return date1date2 之间的时间。