finmlkit.feature.kit module

class finmlkit.feature.kit.Compose(*transforms: SISOTransform | MISOTransform)[source]

Bases: BaseTransform

property output_name: str

Get the output name of the composed transform. The output name is a combination of the first transform’s output and the subsequent transforms’ produces. :return: Output name

class finmlkit.feature.kit.Feature(transform: BaseTransform)[source]

Bases: object

Wraps a BaseTransform and enables mathematical operations between features.

abs()[source]

Get the absolute values of the feature.

Returns:

A new Feature with absolute values

apply(func, *args, suffix=None, **kwargs)[source]

Apply an arbitrary function to the output of this feature.

Parameters:
  • func – The function to apply to the feature output

  • args – Additional positional arguments to pass to the function

  • suffix – Optional suffix to add to the feature name (default is function name)

  • kwargs – Additional keyword arguments to pass to the function

Returns:

A new Feature with the function applied

clip(lower=None, upper=None)[source]

Clip the values of the feature between lower and upper bounds.

Parameters:
  • lower – Lower boundary (optional)

  • upper – Upper boundary (optional)

Returns:

A new Feature with clipped values

ema(span, adjust=True)[source]

Calculate the Exponential Moving Average (EMA) of the feature.

Parameters:
  • span – Span for the EMA calculation

  • adjust – Whether to adjust the EMA calculation (default is True)

Returns:

A new Feature with EMA values

exp()[source]

Get the exponential of the feature.

Returns:

A new Feature with exp values

lag(period)[source]

Create a lagged version of the feature.

Parameters:

period – Number of periods to lag

Returns:

A new Feature with lagged values

log()[source]

Get the natural logarithm of the feature.

Returns:

A new Feature with log values

log1p()[source]

Get the natural logarithm of the feature.

Returns:

A new Feature with log values

static max(a, b)[source]

Calculate the element-wise maximum between two features.

Parameters:
  • a – First feature or scalar

  • b – Second feature or scalar

Returns:

A new Feature containing the element-wise maximum

static min(a, b)[source]

Calculate the element-wise minimum between two features.

Parameters:
  • a – First feature or scalar

  • b – Second feature or scalar

Returns:

A new Feature containing the element-wise minimum

property name

Get the output name from the wrapped transform

rolling_mean(window)[source]

Calculate the rolling mean of the feature.

Parameters:

window – Rolling window size

Returns:

A new Feature with rolling mean values

rolling_std(window)[source]

Calculate the rolling standard deviation of the feature.

Parameters:

window – Rolling window size

Returns:

A new Feature with rolling std values

rolling_sum(window)[source]

Calculate the rolling sum of the feature.

Parameters:

window – Rolling window size

Returns:

A new Feature with rolling sum values

sqrt()[source]

Get the square root of the feature.

Returns:

A new Feature with square root values

square()[source]

Get the square of the feature.

Returns:

A new Feature with squared values

class finmlkit.feature.kit.FeatureKit(features: list[Feature], retain: list[str] = None)[source]

Bases: object

build(df, *, backend='nb', timeit=False)[source]