quantdata.utils.backbone#
Abstract Numerical Backbone#
Consistent wrapper around numpy and torch, and in the future jax for being able to write
unified model code where
sensible (e.g. outside jax.scan loops).
The backbone also has a black scholes function and a verify function.
- class quantdata.utils.backbone.Backbone[source]#
Bases:
objectGeneralized compute backbone:
numpy,torch, (soon)jax.- static are_broadcastable(*shapes)[source]#
Check if
shapesare broadcastable according to numpy broadcasting rules.
- BS_EPS = 1e-10#
- EPS_VOL = 1e-10#
- bs_price(strikes, sqrtVars, *, mask=None, spot=None, logK=None, high_precision=False, debug_verify_bounds=False, eps=1e-06)[source]#
Black-Scholes price of call options with given spot, strikes and sqrtVars.
- Parameters:
strikes (Array) – Strike prices for each option.
sqrtVars (Array) – Square root of variance for each option.
mask (Array | None) – Optional boolean mask indicating which options are valid. If provided, the function will return 0 for invalid options and compute prices only for valid options. This can be used to handle cases where some options are not traded or not relevant without affecting the computed prices of valid options.
spot (Array | None) – Spot prices, or
Nonefor1.high_precision (bool) – If
True, perform calculations in higher precision (float64) to improve accuracy for deep OTM options. The output will be cast back to the input dtype.debug_verify_bounds (bool) – If
True, perform additional checks to verify that the computed option prices are within theoretical bounds (intrinsic value and spot price).eps (float) – Tolerance for numerical checks when
debug_verify_boundsisTrue.
- Returns:
prices – The Black-Scholes price of the call options.
- Return type:
- quantdata.utils.backbone.are_broadcastable(*shapes)[source]#
Check if
shapesor arrays are broadcastable according to torch/numpy broadcasting rules.
- class quantdata.utils.backbone.BackboneNumpy[source]#
Bases:
BackboneNumpy compute backbone
- to_array(data, dtype=None)[source]#
Create an array; do not copy if data is already an array of the correct dtype
- verify(condition, message, exception=<class 'RuntimeError'>)[source]#
Verify a condition, raise an error with message if not satisfied.