Search code examples
python-3.xquantlib

Date Difference QuantLib


I want to calculate days difference between the dates using 360 days basis .Code is as per below but is not working

import QuantLib as ql
import pandas as pd
issueDate = ql.Date(15, 3, 2020)
maturityDate = ql.Date(15, 1, 2025)
tenor = ql.Period(ql.Semiannual)
calendar = ql.UnitedStates()
businessConvention = ql.Unadjusted
dateGeneration = ql.DateGeneration.Backward
monthEnd = False

schedule = ql.Schedule (issueDate, maturityDate, tenor, calendar, businessConvention,
                            businessConvention, dateGeneration, monthEnd)
dateList  =  list(schedule)
def calculateInterOrderTime(dateList):
   result = map(lambda x: [i / np.timedelta64(1, 'D') for i in np.diff([c for c in x])[0]],dateList)
   print(list(result))

I want to achieve results as per below

[120,180,180,180,180,180,180,180,180,180,180]

I will appreciate if someone can help me in achieving the results. Thanking you in advance.


Solution

  • For example:

    dates = [*schedule]
    [int(ql.Thirty360().yearFraction(start, end)*360) for start, end in zip(dates[:-1], dates[1:])]
    

    [120, 180, 180, 180, 180, 180, 180, 180, 180, 180]