Skip to content

quantpylib.hft.utils

exponential_weights(arr, unique_values=False, normalize=False)

Generates exponential weights for an array.

Parameters:

Name Type Description Default
arr ndarray or list

The input array.

required
unique_values bool

If True, weights are generated based on the number of unique values in the array. Duplicate values share the same weight.

False
normalize bool

If True, the weights are normalized to sum to 1.

False

Returns:

Type Description

np.ndarray: An array of exponential weights.

rolling_ema(arr, n)

Calculate the rolling Exponential Moving Average (EMA).

Parameters:

Name Type Description Default
arr ndarray

The input array.

required
n int

The size of the rolling window.

required

Returns:

Type Description

np.ndarray: An array of rolling EMAs.

rolling_window(a, window)

Create a rolling window view of the array a.

Parameters:

Name Type Description Default
a ndarray

The input array.

required
window int

The size of the rolling window.

required

Returns:

Type Description

np.ndarray: A view of the input array with the specified rolling window.

rolling_zscore(arr, n)

Calculate the rolling Z-score.

Parameters:

Name Type Description Default
arr ndarray

The input array.

required
n int

The size of the rolling window.

required

Returns:

Type Description

np.ndarray: An array of rolling Z-scores.

simple_weights(arr, normalize=False)

Generates simple weights for an array.

Parameters:

Name Type Description Default
arr ndarray or list

The input array.

required
normalize bool

If True, the weights are normalized to sum to 1.

False

Returns:

Type Description

np.ndarray: An array of simple weights.