Module pyfx.pricingscience.elasticity

Functions and utilities for elasticity.

Functions

def elasticity(prices: Union[numpy._typing._array_like._SupportsArray[numpy.dtype], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], quantities: Union[numpy._typing._array_like._SupportsArray[numpy.dtype], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], elasticity_func: Callable[..., numpy.ndarray[Any, numpy.dtype[numpy.float64]]] = <function logistic_curve>, log_price: bool = True, log_quantity: bool = True, curve_fit_parameters: Optional[dict[str, typing.Any]] = None, starting_point: Optional[list[typing.Any]] = None) ‑> tuple[numpy.ndarray[typing.Any, numpy.dtype[numpy.float64]], pandas.core.frame.DataFrame]

Fit the elasticity function parameters for the given data.

By default the elasticity function used is the logistic curve (S-curve).

This function uses scipy.optimize.curve_fit. If the elasticity function used is supported, some default curve_fit parameters and starting point will be used. Those can be overrided using the corresponding optional arguments of the function.

Args

prices
the prices data
quantities
the corresponding quantities levels
elasticity_func
the elasticity function to used (default: logistic_curve())
log_price
should the prices be converted to log-base (default: True)
log_quantity
should the demands be converted to log-base (default: True)
curve_fit_parameters
optional parameters for the curve fitting (default: None)
starting_point
optional starting for the curve fitting (default: None)

Returns

A tuple containing: - an array with the fitted function parameter value - a DataFrame with the price, quantity, and computed quantity

def logistic_curve(x: numpy.ndarray[typing.Any, numpy.dtype[numpy.float64]], max_value: float, x0: float, k: float, b: float) ‑> numpy.ndarray[typing.Any, numpy.dtype[numpy.float64]]

Implementation of the logistic curve function (or S-curve).

Args

x
the x value(s)
max_value : also called L
the supremum of the value of the functions
x0
the x value of the function's midpoint
k
the logistic growth rate
b
a constant shift value

Returns

The computed y value(s)