|
From: Klaus S. <kl...@sp...> - 2019-02-22 16:49:13
|
Hi
maybe the following function is of help, which adds a fraction of a year to a date.
def plusDt(date, dt):
return ql.Date(date.dayOfMonth(), date.month(), date.year(),
date.hours(), date.minutes(),
date.seconds() + round(dt*365*24*60*60),
date.milliseconds(), date.microseconds())
This function returns the following dates
plusDt(ql.Date(1,1, 2019), 1)
--> 2020-01-01T00:00:00,000000
plusDt(ql.Date(1,1, 2019), 1.0/365.0)
--> 2019-01-02T00:00:00,000000
print(plusDt(ql.Date(1,1, 2019), 0.5/365.0))
--> 2019-01-01T12:00:00,000000
For the reverse operation (or subtracting two date time stamps) IMO you can use
ql.Actual365Fixed().yearFraction(date1, date2), e.g.
ql.Actual365Fixed().yearFraction(
ql.Date(1,1,2019), plusDt(ql.Date(1,1,2019),0.5/365.))
--> 0.001369863
best regards
Klaus
|