1

I am trying to run this in quantlib-python:

import QuantLib as ql
date = ql.Date(31, 3, 2015)
date

returning: Date(31,3,2015)

but it is supposed to return: March 31st, 2015

I am new to quantlib-python. What am I missing? Thank you.

I am using VC2015/quantlib 1.8/quantlib-swig-1.8

Jamie Starke
  • 8,776
  • 3
  • 38
  • 58

1 Answers1

1

When you only write date, your interpreter calls the __repr__ method and displays the result. If you say print date, instead, it calls the __str__ method, which is what you're looking for. The two methods have different purposes in Python (see e.g. Purpose of Python's __repr__) and are often implemented differently; you can try the same thing with datetime.date and see what happens.

Luigi Ballabio
  • 4,128
  • 21
  • 29