Skip to content

gecBurton/pydantic-quantlib

Repository files navigation

Pydantic QuantLib

Documentation Status

QuantLib Python Objects with Typing

Features

This package uses pydantic to wrap QuantLib to provide a set of Typed class factories.

The pydantic models are auto-generated from the QuantLib SWIG bindings. The autogen code is available on request.

In the following example we construct a European Option.

import pydantic_quantlib as pql

payoff = pql.PlainVanillaPayoff(type=pql.OptionType.Put, strike=40)

european_exercise = pql.EuropeanExercise(date=pql.Date(d=4, m=1, y=2022))

european_option = pql.VanillaOptionBase(payoff=payoff, exercise=european_exercise)

The option can be converted to the usual QuantLib object for computation as seen in this fuller example.

>>> european_option.to_quantlib()
'<QuantLib.QuantLib.VanillaOption; proxy of <Swig Object of type 'ext::shared_ptr< VanillaOption > *' at 0x7f6559ddabd0> >'

it can also be printed:

>>> print(european_option)
'PlainVanillaPayoff(type=<OptionType.Put: -1>, strike=40.0) exercise=EuropeanExercise(date=Date0(d=4.0, m=1.0, y=2022.0))'

it can be converted to JSON:

>>> european_option.json()
'{"resource_name": "VanillaOption", "payoff": {"resource_name": "PlainVanillaPayoff", "type": -1, "strike": 40.0}, "exercise": {"resource_name": "EuropeanExercise", "date": {"resource_name": "Date", "d": 4, "m": 1, "y": 2022}}}'

and it can be loaded from JSON:

>>> json_repr = '{"resource_name": "VanillaOption", "payoff": {"resource_name": "PlainVanillaPayoff", "type": -1, "strike": 40.0}, "exercise": {"resource_name": "EuropeanExercise", "date": {"resource_name": "Date", "d": 4, "m": 1, "y": 2022}}}'
>>> pql.VanillaOption.parse_obj(json.loads(json_repr))

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published