skfolio.base.BaseAssetPanelTransformer#

class skfolio.base.BaseAssetPanelTransformer[source]#

Base class for estimators that transform asset panel data.

Descriptors and factor exposure estimators take an AssetPanel and return transformed values indexed by observation and asset. Most transformers return an array with shape (n_observations, n_assets). Transformers that produce multiple values per asset, such as OneHotCategoricalFactors, return an array with shape (n_observations, n_assets, n_categories).

In scikit-learn, fit and partial_fit update fitted state, stored in trailing underscore attributes, while transform returns transformed input data using that state. This separation is not suitable for every AssetPanel transformer. For some estimators, the transformed value is produced by the same state transition that updates the estimator. A separate transform method would either need to mutate state or depend on a preceding partial_fit call, so the API exposes the combined operation directly. For example, the exponentially weighted momentum descriptor EWMomentum needs to update its internal EWMA state to compute the transformed value on each observation.

Other transformers are independent across observations. For example, the DividendToPrice descriptor depends only on the current dividends_ttm and market_cap values and can therefore be declared stateless.

Accordingly, fit_transform is used for full-batch computation and partial_fit_transform for online computation. Subclasses must implement fit_transform. Downstream meta-estimators use the presence of partial_fit_transform to determine whether a transformer supports online transformation.

Supported implementation patterns are:

  • Batch-only transformers implement only fit_transform.

  • Stateless transformers declare stateless=True and implement only fit_transform. The base class adds partial_fit_transform as a direct delegation to fit_transform.

  • Online transformers implement both fit_transform and partial_fit_transform.

Attributes:
n_assets_int

Number of assets seen during fitting.

asset_names_ndarray of shape (n_assets,)

Asset names seen during fitting.

Methods

fit_transform(X[, y])

Fit the transformer if needed and return transformed values.

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get parameters for this estimator.

set_params(**params)

Set the parameters of this estimator.

See also

BaseDescriptor

Computes raw descriptor values.

BaseFactorExposure

Computes factor exposures.

abstractmethod fit_transform(X, y=None, **fit_params)[source]#

Fit the transformer if needed and return transformed values.

Parameters:
XAssetPanel

Input panel data.

yNone

Ignored. Present for API consistency.

**fit_paramsdict

Additional fit parameters. Metadata routing may pass these parameters to sub-estimators when applicable.

Returns:
valuesndarray of shape (n_observations, n_assets) or (n_observations, n_assets, n_components)

Transformed values.

get_metadata_routing()#

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

get_params(deep=True)#

Get parameters for this estimator.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

set_params(**params)#

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters:
**paramsdict

Estimator parameters.

Returns:
selfestimator instance

Estimator instance.