When I am learning the python version of QuantLib, the first program failed. I am just trying to use the ql.calendar
. No matter I write calendar = ql.UnitedStates()
or calendar = ql.UnitedStates(ql.UnitedStates.NYSE)
, I won't work.
In the first way, it will show: TypeError: UnitedStates.init() missing 1 required positional argument: 'm'.
Here is my code:
import QuantLib as ql
date = ql.Date(2,6,2023)
calendar = ql.UnitedStates()
date1 = ql.Date(1,6,2023)
date2 = ql.Date(1,6,2024)
tenor = ql.Period(ql.Monthly)
schedual = ql.Schedule(date1,date2,tenor,calendar,ql.Following,
ql.Following,ql.DateGeneration.Forward, False)
print(schedual)
I use the conda environment, with the , and install QuantLib through it, everything seems to work well when I am testing the basic functions, but calendar seems the only that failed. Here is all the packages in this environment:
# Name Version Build Channel
blas 1.0 mkl
boost-cpp 1.78.0 h5b4e17d_0 conda-forge
bottleneck 1.3.5 py311h5bb9823_0
bzip2 1.0.8 he774522_0
ca-certificates 2023.5.7 h56e8100_0 conda-forge
intel-openmp 2023.1.0 h59b6b97_46319
libffi 3.4.4 hd77b12b_0
lz4-c 1.9.4 hcfcfb64_0 conda-forge
mkl 2023.1.0 h8bd8f75_46356
mkl-service 2.4.0 py311h2bbff1b_1
mkl_fft 1.3.6 py311hf62ec03_1
mkl_random 1.2.2 py311hf62ec03_1
numexpr 2.8.4 py311h1fcbade_1
numpy 1.24.3 py311hdab7c0b_1
numpy-base 1.24.3 py311hd01c5d8_1
openssl 1.1.1u hcfcfb64_0 conda-forge
pandas 1.5.3 py311heda8569_0
pip 23.0.1 py311haa95532_0
python 3.11.3 h966fe2a_0
python-dateutil 2.8.2 pyhd3eb1b0_0
python_abi 3.11 2_cp311 conda-forge
pytz 2022.7 py311haa95532_0
quantlib-python 1.29 py311hacdd394_3 conda-forge
setuptools 67.8.0 py311haa95532_0
six 1.16.0 pyhd3eb1b0_1
sqlite 3.41.2 h2bbff1b_0
tbb 2021.8.0 h59b6b97_0
tk 8.6.12 h2bbff1b_0
tzdata 2023c h04d1e81_0
ucrt 10.0.22621.0 h57928b3_0 conda-forge
vc 14.2 h21ff451_1
vc14_runtime 14.34.31931 h5081d32_16 conda-forge
vs2015_runtime 14.34.31931 hed1258a_16 conda-forge
wheel 0.38.4 py311haa95532_0
xz 5.4.2 h8cc25b3_0
zlib 1.2.13 h8cc25b3_0
zstd 1.5.5 hd43e919_0
Then I tried to change the ql.UnitedStates()
into ql.UnitedStates
, like:
import QuantLib as ql
date = ql.Date(2,6,2023)
calendar = ql.UnitedStates(ql.UnitedStates.NYSE)
date1 = ql.Date(1,6,2023)
date2 = ql.Date(1,6,2024)
tenor = ql.Period(ql.Monthly)
schedual = ql.Schedule(date1,date2,tenor,calendar,ql.Following,
ql.Following,ql.DateGeneration.Forward, False)
print(schedual)
but it still failed:
<QuantLib.QuantLib.Schedule; proxy of <Swig Object of type 'Schedule *' at 0x00000252E21ED110> >
The constructor of UnitedStates
requires a market, as you guessed.
The message you're getting after passing UnitedStates.NYSE
is not a failure. You did build the schedule object correctly, but it doesn't have a specific string representation to be used when you call print
so it outputs a generic one. Use something like this instead:
for d in schedual:
print(d)