skfolio.factor_exposure.FixedWeightedFactor#

class skfolio.factor_exposure.FixedWeightedFactor(*, descriptors, family='style', weights=None, min_coverage=0.0, outlier_transformer=None, scoring_transformer=None, transform_by_group=None, n_jobs=1)[source]#

Factor exposure as a fixed weighted combination of descriptors.

Computes descriptor values, applies cross-sectional outlier and scoring transforms to each descriptor, then combines the resulting scores into a single factor exposure matrix with shape (n_observations, n_assets).

For descriptor \(i\), let \(s_{i,t,j}\) be its score for observation \(t\) and asset \(j\) after the cross-sectional transforms, \(w_i\) its fixed non-negative weight and \(V_{t,j}\) the set of descriptors with a finite score. The weighted composite is:

\[c_{t,j} = \frac{\sum_{i \in V_{t,j}} w_i \, s_{i,t,j}} {\sum_{i \in V_{t,j}} w_i}\]

Weights are renormalized over available scores for each asset-observation pair. This allows assets with structurally unavailable descriptor values (e.g., Gross Margin for financial firms, which do not report cost of goods sold) to receive a composite score from the remaining descriptors. When all descriptor scores are non-finite for a pair, the composite is NaN.

The min_coverage parameter controls the minimum fraction of total descriptor weight that must be valid for the composite to be computed. If the valid weight fraction falls below this threshold, the composite is set to NaN instead. This guards against low-quality exposures based on too few descriptors.

The default min_coverage=0.0 uses any available descriptor (no threshold), which maximizes coverage. A value of 0.5 requires at least half the descriptor weight to be valid.

When multiple descriptors are combined and scoring_transformer is not "passthrough", the composite is scored again cross-sectionally so assets with different descriptor coverage are on the same scale. The final exposure is this re-scored composite, or the weighted composite when scoring is skipped.

weights are fixed inputs and are not learned by this estimator. They can be set from economic priors or selected by hyperparameter tuning.

Parameters:
descriptorslist of tuple (str, BaseDescriptor)

List of (name, descriptor) pairs. Each descriptor computes values from the AssetPanel.

familystr, default=”style”

The factor family this exposure belongs to (e.g., “market”, “style”, “industry”, “country”). Factor families group related factors for basket-neutral constraints, neutralization, attribution and reporting. The default is "style".

weightsarray-like of shape (n_descriptors,), optional

Non-negative descriptor combination weights. Must sum to 1. If None (default), equal weights are used.

min_coveragefloat, default=0.0

Minimum fraction of total descriptor weight that must be finite for the composite to be computed. Values where the valid weight fraction is below this threshold are set to NaN. Must be in [0, 1].

  • 0.0 (default): use any available descriptor. Maximizes cross-sectional coverage.

  • 0.5: require at least half the descriptor weight to be valid.

The threshold is weight-based, not count-based. If descriptor weights are [0.8, 0.2] and only the first descriptor is valid, the valid weight fraction is 0.8, so a min_coverage=0.5 threshold is satisfied even though only 1 out of 2 descriptors is present.

outlier_transformerBaseCSTransformer or “passthrough”, optional

Cross-sectional transformer for outlier handling. If None, defaults to CSWinsorizer(). Use “passthrough” to skip.

scoring_transformerBaseCSTransformer or “passthrough”, optional

Cross-sectional transformer for scoring applied after outlier handling. If None, defaults to CSStandardScaler(). Use “passthrough” to skip.

transform_by_groupstr, optional

Name of a categorical characteristic in the AssetPanel to use for group-wise transformations. If provided, outlier and scoring transformations are applied within each group separately.

n_jobsint, default=1

Number of parallel jobs for descriptor computation.

Attributes:
descriptors_list of BaseDescriptor

Fitted descriptor estimators.

named_descriptors_dict of {str: BaseDescriptor}

Dictionary mapping descriptor names to fitted estimators.

outlier_transformer_BaseCSTransformer or str

The fitted outlier transformer.

scoring_transformer_BaseCSTransformer or str

The fitted scoring transformer.

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])

Compute factor exposure from a clean descriptor state.

get_metadata_routing()

Return metadata routing for descriptor estimators.

get_params([deep])

Get the parameters of an estimator from the ensemble.

partial_fit_transform(X[, y])

Update descriptor state and compute factor exposure.

set_params(**params)

Set the parameters of a factor from the ensemble.

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

Compute factor exposure from a clean descriptor state.

Parameters:
XAssetPanel

Input panel containing “benchmark_weights”, descriptor fields and optional grouping fields.

yNone

Ignored. Present for compatibility with scikit-learn’s API.

**fit_paramsdict

Additional fit parameters passed to descriptors through metadata routing.

Returns:
exposurendarray of shape (n_observations, n_assets)

Fixed-weighted factor exposure.

get_metadata_routing()#

Return metadata routing for descriptor estimators.

get_params(deep=True)#

Get the parameters of an estimator from the ensemble.

Returns the parameters given in the constructor as well as the estimators contained within the estimators parameter.

Parameters:
deepbool, default=True

Setting it to True gets the various estimators and the parameters of the estimators as well.

Returns:
paramsdict

Parameter and estimator names mapped to their values or parameter names mapped to their values.

property named_descriptors#

Dictionary to access any fitted factors by name.

Returns:
Bunch
partial_fit_transform(X, y=None, **fit_params)[source]#

Update descriptor state and compute factor exposure.

Parameters:
XAssetPanel

Input panel containing benchmark weights, descriptor fields and optional grouping fields.

yNone

Ignored. Present for compatibility with scikit-learn’s API.

**fit_paramsdict

Additional fit parameters passed to descriptors through metadata routing.

Returns:
exposurendarray of shape (n_observations, n_assets)

Fixed-weighted factor exposure for the new observations.

set_params(**params)#

Set the parameters of a factor from the ensemble.

Valid parameter keys can be listed with get_params(). Note that you can directly set the parameters of the estimators contained in estimators.

Parameters:
**paramskeyword arguments

Specific parameters using e.g. set_params(parameter_name=new_value). In addition, to setting the parameters of the estimator, the individual estimator of the estimators can also be set, or can be removed by setting them to ‘drop’.

Returns:
selfobject

Estimator instance.