|
From: Luigi B. <lui...@gm...> - 2019-02-22 22:03:25
|
You might also export to Python the function `daysBetween`, that returns
the number of days between two dates including the fractional part due to
time. Adding its declaration:
Time daysBetween(const Date&, const Date&);
to QuantLib-SWIG/SWIG/date.i and recompiling the Python module will make it
available.
Luigi
On Fri, Feb 22, 2019 at 5:49 PM Klaus Spanderen <kl...@sp...> wrote:
> 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
>
>
>
>
> _______________________________________________
> QuantLib-dev mailing list
> Qua...@li...
> https://lists.sourceforge.net/lists/listinfo/quantlib-dev
>
|