Search code examples
pythondatequantlib

Using quantlib in python how do i get the number of days between two dates?


i have tried this but it isnt working

import QuantLib as ql

ql.Thirty360().yearFraction((6, 6, 2020),(7, 7, 2020))


Solution

  • You need to convert your tuple values to ql.Date values using

    date = ql.Date(day, month, year)
    

    So, your code would become:

    import QuantLib as ql
    
    ql.Thirty360().yearFraction(ql.Date(6, 6, 2020), ql.Date(7, 7, 2020))
    

    See the docs for more: https://quantlib-python-docs.readthedocs.io/en/latest/dates.html