skfolio.factor_exposure.DerivedFactor#
- class skfolio.factor_exposure.DerivedFactor(*, source, func, family='style', outlier_transformer='passthrough', scoring_transformer=None, transform_by_group=None)[source]#
Factor exposure derived from another factor’s computed exposure.
The derived exposure is computed by applying
functo the source factor’s exposure, then optionally applying outlier and scoring transformations.- Parameters:
- sourcestr
Name of the source factor whose exposure will be transformed. The source factor must be defined in the factors list of
CharacteristicsFactorModel. Dependency ordering is handled automatically via topological sorting.- funcCallable[[np.ndarray], np.ndarray]
Function to apply to the source exposure. Receives a 2D array of shape (n_observations, n_assets) and should return an array of the same shape. The source exposure is passed directly. If
funcuses in-place operations, it should copy the input first unless mutating the source exposure is intended.- 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".- outlier_transformerBaseCSTransformer or “passthrough” or None, default=”passthrough”
Cross-sectional transformer for outlier handling applied after
func. If None, defaults toCSWinsorizer(). 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.
- Attributes:
- 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, source_exposure])Fit and transform the source exposure.
Get metadata routing of this object.
get_params([deep])Get parameters for this estimator.
partial_fit_transform(X[, y])Stateless class delegation to
fit_transform.set_params(**params)Set the parameters of this estimator.
Examples
>>> from skfolio.factor_exposure import DerivedFactor, FixedWeightedFactor >>> from skfolio.descriptor import LogMarketCap >>> from skfolio.prior import CharacteristicsFactorModel >>> >>> # Non linear size factor >>> factors = [ ... ("size", FixedWeightedFactor(descriptors=[("log_mcap", LogMarketCap())])), ... ("non_linear_size", DerivedFactor(source="size", func=lambda x: x**3)), ... ] >>> >>> # Orthogonalize non_linear_size vs size >>> model = CharacteristicsFactorModel( ... factors=factors, ... neutralize_against={"non_linear_size": ["size"]}, ... )
- fit_transform(X, y=None, source_exposure=None, **fit_params)[source]#
Fit and transform the source exposure.
- Parameters:
- XAssetPanel
Input panel containing benchmark weights and optional grouping.
- yNone
Ignored. Present for compatibility with scikit-learn’s API.
- source_exposurendarray of shape (n_observations, n_assets)
The computed exposure from the source factor. This is passed automatically by
CharacteristicsFactorModel.- **fit_paramsdict
Additional fit parameters (unused).
- Returns:
- exposurendarray of shape (n_observations, n_assets)
The derived factor exposure.
- get_metadata_routing()#
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:
- routingMetadataRequest
A
MetadataRequestencapsulating 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.
- partial_fit_transform(X, y=None, **fit_params)#
Stateless class delegation to
fit_transform.
- 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.