quantlib


How to obtain the “time” values of a schedule


Assuming a fixed rate bond with the schedule shown in the sample code below.
I am able to obtain the number of days between the tenors by using the businessDaysBetween function.
Now I would like the "time value". Is there a way of doing it without creating a new function?
Here is the expected result:
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
Here is the code:
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
That's what DayCounter instances are for. The time will depend on the day-count convention you choose (for example, you seem to be using 30/360).
Calling
day_count.yearFraction(date1, date2)
will return the time between date1 and date2.

Related Links

Unhandled exception in Yield Curve Quantlib .exe
How to obtain the “time” values of a schedule
Why did QuantLib introduce the Handle class?
Can't expose monotone convex interpolation in python quantlib
unable to start program QuantLib-vc120-mt-gd.lib
C++: Derive a class template from QuantLib::PiecewiseYieldCurve
clean or dirty price for FixedRateBondHelper
Which version of QuantLib is the basis for QLNet ?
xlquantlib bootstrapping Offshore KRW Curve
“end must be large than start” in Uniform1dMesher
How do I get coupon payment dates for a simple fixed bond using quantlib, quantlib-swig and python
How to calculate the local volatilty surface using QuantLib?

Categories

HOME
notepad++
gdb
polymer
string
phpmyadmin
mstest
replace
nuget-package
azure-container-service
vert.x
ibeacon-android
fhir
plist
mxgraph
xcodebuild
naivebayes
renjin
symmetricds
enterprise-architect
heat
powershell-v5.0
charles
roslyn
aggregation
jboss6.x
beautifier
surveymonkey
slidetoggle
bulletphysics
angularjs-components
outliers
ntp
panoramas
livelink
paragraph
utorrent
git-squash
gojs
activexobject
reactjs.net
navigator
xcode7.3
z-notation
attributeerror
linqpad
oim
proget
jquery-ui-draggable
rserve
tf
podscms
zenhub
payara-micro
truezip
cmp
restore
polyline
visual-studio-2008-sp1
flex-monkey
webjars
lrs
rspec2
angular-ui-typeahead
tracker-enabled-dbcontext
sklearn-pandas
atan2
character-replacement
boomerang
opserver
lasso
dulwich
amiga
graphics2d
telepat
apache-spark-1.3
primitive-types
easyrtc
teaspoon
rickshaw
rmysql
ora-00904
codeplex
matrix-inverse
ie8-compatibility-mode
gpars
font-awesome-4.0.0
chart-director
swfobject
robotlegs
os.system
iboutlet
boost-signals
subproject
fusefabric
cross-database
winmain
non-clustered-index
dot-emacs
ajax-polling
web-application-project
escrow
int64

Resources

Encrypt Message