<a id="skfolio-factor-exposure-derivedfactor"></a>

# skfolio.factor_exposure.DerivedFactor

<a id="skfolio.factor_exposure.DerivedFactor"></a>

### *class* skfolio.factor_exposure.DerivedFactor(\*, source, func, family='style', outlier_transformer='passthrough', scoring_transformer=None, transform_by_group=None)

Factor exposure derived from another factor’s computed exposure.

The derived exposure is computed by applying `func` to the source factor’s
exposure, then optionally applying outlier and scoring transformations.

* **Parameters:**
  **source** *str*
  : 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.

  **func** *Callable[[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 `func` uses in-place operations,
    it should copy the input first unless mutating the source exposure is intended.

  **family** *str, 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_transformer** *BaseCSTransformer or “passthrough” or None, default=”passthrough”*
  : Cross-sectional transformer for outlier handling applied after `func`. If None,
    defaults to `CSWinsorizer()`. Use “passthrough” to skip.

  **scoring_transformer** *BaseCSTransformer or “passthrough”, optional*
  : Cross-sectional transformer for scoring applied after outlier handling.
    If None, defaults to `CSStandardScaler()`. Use “passthrough” to skip.

  **transform_by_group** *str, 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`](#skfolio.factor_exposure.DerivedFactor.fit_transform)(X[, y, source_exposure])   | Fit and transform the source exposure.         |
|-------------------------------------------------------------------------------------------|------------------------------------------------|
| [`get_metadata_routing`](#skfolio.factor_exposure.DerivedFactor.get_metadata_routing)()                   | Get metadata routing of this object.           |
| [`get_params`](#skfolio.factor_exposure.DerivedFactor.get_params)([deep])                       | Get parameters for this estimator.             |
| [`partial_fit_transform`](#skfolio.factor_exposure.DerivedFactor.partial_fit_transform)(X[, y])            | Stateless class delegation to `fit_transform`. |
| [`set_params`](#skfolio.factor_exposure.DerivedFactor.set_params)(\*\*params)                   | Set the parameters of this estimator.          |

### Examples

```pycon
>>> 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"]},
... )
```

<a id="skfolio.factor_exposure.DerivedFactor.fit_transform"></a>

#### fit_transform(X, y=None, source_exposure=None, \*\*fit_params)

Fit and transform the source exposure.

* **Parameters:**
  **X** *AssetPanel*
  : Input panel containing benchmark weights and optional grouping.

  **y** *None*
  : Ignored. Present for compatibility with scikit-learn’s API.

  **source_exposure** *ndarray of shape (n_observations, n_assets)*
  : The computed exposure from the source factor. This is passed automatically
    by `CharacteristicsFactorModel`.

  **\*\*fit_params** *dict*
  : Additional fit parameters (unused).
* **Returns:**
  **exposure** *ndarray of shape (n_observations, n_assets)*
  : The derived factor exposure.

<a id="skfolio.factor_exposure.DerivedFactor.get_metadata_routing"></a>

#### get_metadata_routing()

Get metadata routing of this object.

Please check [User Guide](https://skfolio.org/user_guide/metadata_routing.html.md#metadata-routing) on how the routing
mechanism works.

* **Returns:**
  **routing** *MetadataRequest*
  : A `MetadataRequest` encapsulating
    routing information.

<a id="skfolio.factor_exposure.DerivedFactor.get_params"></a>

#### get_params(deep=True)

Get parameters for this estimator.

* **Parameters:**
  **deep** *bool, default=True*
  : If True, will return the parameters for this estimator and
    contained subobjects that are estimators.
* **Returns:**
  **params** *dict*
  : Parameter names mapped to their values.

<a id="skfolio.factor_exposure.DerivedFactor.partial_fit_transform"></a>

#### partial_fit_transform(X, y=None, \*\*fit_params)

Stateless class delegation to `fit_transform`.

<a id="skfolio.factor_exposure.DerivedFactor.set_params"></a>

#### 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:**
  **\*\*params** *dict*
  : Estimator parameters.
* **Returns:**
  **self** *estimator instance*
  : Estimator instance.

