<a id="skfolio-descriptor-changetoscale"></a>

# skfolio.descriptor.ChangeToScale

<a id="skfolio.descriptor.ChangeToScale"></a>

### *class* skfolio.descriptor.ChangeToScale(field, scale_field, lag)

Lagged change normalized by a positive scale.

Computes the change in `field` over a fixed lag, divided by the current value of
`scale_field`:

$$
\text{ChangeToScale}_\ell(t) = \frac{A(t) - A(t - \ell)}{S(t)}
$$

where $A$ is the `field` value and $S$ is the `scale_field` value.

The first `lag` observations are NaN because no lagged history is available.

This descriptor is appropriate when the numerator field can be negative or cross
zero, such as earnings, capex or cash flows, and the change should be scaled by the
firm’s current size or valuation. NaNs are allowed as missing observations and
propagate when the current, lagged or scale value is missing.

Non-missing numerator values must be finite. Non-missing scale values must be finite
and strictly positive. A `ValueError` is raised otherwise.

* **Parameters:**
  **field** *str*
  : Field name in the [`AssetPanel`](https://skfolio.org/generated/skfolio.containers.AssetPanel.html.md#skfolio.containers.AssetPanel) to compute the
    change for. Non-missing values must be finite.

  **scale_field** *str*
  : Field name in the [`AssetPanel`](https://skfolio.org/generated/skfolio.containers.AssetPanel.html.md#skfolio.containers.AssetPanel) used as the current
    positive denominator. Non-missing values must be finite and strictly positive.

  **lag** *int*
  : Number of observations to look back. The interpretation depends on the data
    frequency: `lag=12` means 1 year for monthly data, `lag=252` for daily data,
    `lag=4` for quarterly data.
* **Attributes:**
  **n_assets_** *int*
  : Number of assets seen during fitting.

  **asset_names_** *ndarray of shape (n_assets,)*
  : Asset names seen during fitting.

  **change_to_scale_** *ndarray of shape (n_assets,)*
  : Last change-to-scale value for each asset.

### Methods

| [`fit_transform`](#skfolio.descriptor.ChangeToScale.fit_transform)(X[, y])         | Compute changes in level normalized by current scale.   |
|--------------------------------------------------------------------------------|---------------------------------------------------------|
| [`get_metadata_routing`](#skfolio.descriptor.ChangeToScale.get_metadata_routing)()        | Get metadata routing of this object.                    |
| [`get_params`](#skfolio.descriptor.ChangeToScale.get_params)([deep])            | Get parameters for this estimator.                      |
| [`partial_fit_transform`](#skfolio.descriptor.ChangeToScale.partial_fit_transform)(X[, y]) | Compute changes in level normalized by current scale.   |
| [`set_params`](#skfolio.descriptor.ChangeToScale.set_params)(\*\*params)        | Set the parameters of this estimator.                   |

#### SEE ALSO
[`ChangeInIntensity`](https://skfolio.org/generated/skfolio.descriptor.ChangeInIntensity.html.md#skfolio.descriptor.ChangeInIntensity)
: Change in the ratio $A/S$ (intensity change).

[`GrowthRate`](https://skfolio.org/generated/skfolio.descriptor.GrowthRate.html.md#skfolio.descriptor.GrowthRate)
: Simple growth rate for positive-definite characteristics.

### Examples

```pycon
>>> from skfolio.descriptor import ChangeToScale
>>>
>>> # Earnings change to price (equivalent to EarningsChangeToPrice)
>>> earnings_chg = ChangeToScale("net_income_ttm", "market_cap", lag=12)
>>>
>>> # Capex change to total assets
>>> capex_chg = ChangeToScale("capex_ttm", "total_assets", lag=12)
```

<a id="skfolio.descriptor.ChangeToScale.fit_transform"></a>

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

Compute changes in level normalized by current scale.

* **Parameters:**
  **X** *AssetPanel*
  : Input panel containing the `field` and `scale_field` characteristics
    configured at construction.

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

  **\*\*fit_params** *dict*
  : Additional fit parameters. Ignored.
* **Returns:**
  **change_to_scale** *ndarray of shape (n_observations, n_assets)*
  : Change in `field` over the lag window, divided by current `scale_field`
    for each observation and asset.

<a id="skfolio.descriptor.ChangeToScale.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.descriptor.ChangeToScale.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.descriptor.ChangeToScale.partial_fit_transform"></a>

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

Compute changes in level normalized by current scale.

This method supports online updates by continuing from the current fitted state.
Use `fit_transform` to start from a clean state.

* **Parameters:**
  **X** *AssetPanel*
  : Input panel containing the `field` and `scale_field` fields configured at
    construction.

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

  **\*\*fit_params** *dict*
  : Additional fit parameters. Ignored.
* **Returns:**
  **change_to_scale** *ndarray of shape (n_observations, n_assets)*
  : Change in `field` over the lag window, divided by current `scale_field`
    for each observation and asset.

<a id="skfolio.descriptor.ChangeToScale.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.

