spd_trading.utils package

Submodules

spd_trading.utils.density module

spd_trading.utils.density.density_estimation(sample, X, h, kernel='epanechnikov')[source]

Kernel Density Estimation over the sample in domain X.

Routine for sklearn.neighbors.KernelDensity.

Parameters
  • sample (np.array) – Sample of observations. shape: (n_samples, n_features) List of n_features-dimensional data points. Each row corresponds to a single data point.

  • X (np.array) – Domain in which the density is estimated. An array of points to query. Last dimension should match dimension of training data. shape: (n_estimates, n_features)

  • h (float) – Bandwidth of the kernel. Needs to be chosen wisely or estimated. Sensitive parameter.

  • kernel (str, optional) – The kernel to use for the estimation, so far only the Epanechnikov kernel is implemented. Defaults to “epanechnikov”.

Returns

The array of log(density) evaluations. These are normalized to be probability densities, so values will be low for high-dimensional data. shape: (n_estimates,)

Return type

[np.array]

spd_trading.utils.density.density_trafo_K2M(K, q_K, S)[source]

Density transformation from K (Strike Price) to M (Moneyness) domain. M = S/K

First, a spline has to be fitted to q_K, so that it is possible to extract the q_K-value at every point of interest, not just at the known points K. Then, it is iterated through the (M, S)-tuples and the density q_K is transformed to q_M.

Parameters
  • K (np.array) – Strike Price values for which the density q_K is know.

  • q_K (np.array) – Density values in Strike Price domain.

  • S (array-like) – Prices of underlying for the density points.

Returns

Density values in Moneyness domain.

Return type

[np.array]

spd_trading.utils.density.pointwise_density_trafo_K2M(K, q_K, S_vals, M_vals)[source]

Pointwise density transformation from K (Strike Price) to M (Moneyness) domain. M = S/K

First, a spline has to be fitted to q_K, so that it is possible to extract the q_K-value at every point of interest, not just at the known points K. Then, it is iterated through the (M, S)-tuples and the density q_K is transformed to q_M.

Parameters
  • K (np.array) – Strike Price values for which the density q_K is know.

  • q_K (np.array) – Density values in Strike Price domain.

  • S_vals (array-like) – Prices of underlying for the density points.

  • M_vals (array-like) – Moneyness values for the density point.

Returns

Density values in Moneyness domain.

Return type

[np.array]

spd_trading.utils.smoothing module

spd_trading.utils.smoothing.bspline(x, y, sections, degree=3)[source]
spd_trading.utils.smoothing.interpolate_to_same_interval(curve_1, curve_2, interval=[0.5, 1.5])[source]

Interpolates curve_1 and curve_2 to the same interval, especially same interval values!

Parameters
  • curve_1 (dict) – dict of np.arrays “x” and “y”

  • curve_2 (dict) – dict of np.arrays “x” and “y”

  • interval (list, optional) – Interval in which the functions are interpolated. Defaults to [0.5, 1.5].

Returns

Interpolated curves curve_1 and curve_2 to new interval.

Return type

tuple of np.arrays

spd_trading.utils.smoothing.remove_tails(base, other, cut_tail_percent)[source]

Cuts the tails of y_base if they are having a value, less than cut_tail_percent.

Important: base and other need to have same domain values! Also adjusts y_other and X to the new length of y_base.

Parameters
  • base (dict) – The reference function. The tails, that are smaller than cut_tail_percent will be cut off

  • other (dict) – Another function that will be cut at the same places as the reference function.

  • cut_tail_percent (float) – Percent threshold of when to cut off tails.

Returns

The shortened arrays in the same order as input.

Return type

tuple of np.arrays

Module contents