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

# skfolio.descriptor.DaysToCover

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

### *class* skfolio.descriptor.DaysToCover(half_life=21.0, min_periods=None)

Exponentially weighted days-to-cover descriptor.

Computes the ratio of shares sold short to exponentially weighted average daily
volume:

$$
\[
\begin{aligned}
\text{EWMA\_volume}(t)
    &= \lambda \cdot \text{EWMA\_volume}(t-1)
       + (1 - \lambda) \cdot \text{adj\_volume}(t) \\[0.75em]
\text{days\_to\_cover}(t)
    &= \frac{\text{short\_interest}(t)}{\text{EWMA\_volume}(t)}
\end{aligned}
\]
$$

where $\lambda = \exp(-\ln(2) / \text{half\_life})$ is the EWMA decay factor.

Days to cover measures how many trading days it would take short sellers to buy back
their positions at the current trading rate. High values indicate crowded short
positions relative to liquidity [[1]](#rba227fd45f66-1) [[2]](#rba227fd45f66-2).

EWMA smoothing is preferred over a fixed rolling average because daily volume can
spike around earnings, index rebalances or news events. EWMA dampens these spikes
gradually, producing more stable factor exposures.

* **Parameters:**
  **half_life** *float, default=21.0*
  : EWMA half-life in observations for volume smoothing. With daily data, common
    choices are:
    - `half_life=21`: ~1 month
    - `half_life=63`: ~3 months
    - `half_life=252`: ~1 year

  **min_periods** *int, optional*
  : Minimum number of valid positive-volume observations required for each asset.
    Until an asset reaches this count, its output is NaN. This warm-up period avoids
    exposing early EWMA values before the volume estimate has sufficiently converged
    from its zero initialization. If `None`, defaults to
    $\lceil\text{half\_life}\rceil$, with a minimum of 1.
* **Attributes:**
  **n_assets_** *int*
  : Number of assets seen during fitting.

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

  **days_to_cover_** *ndarray of shape (n_assets,)*
  : Last days-to-cover value for each asset.

### Methods

| [`fit_transform`](#skfolio.descriptor.DaysToCover.fit_transform)(X[, y])         | Compute exponentially weighted days to cover.         |
|--------------------------------------------------------------------------------|-------------------------------------------------------|
| [`get_metadata_routing`](#skfolio.descriptor.DaysToCover.get_metadata_routing)()        | Get metadata routing of this object.                  |
| [`get_params`](#skfolio.descriptor.DaysToCover.get_params)([deep])            | Get parameters for this estimator.                    |
| [`partial_fit_transform`](#skfolio.descriptor.DaysToCover.partial_fit_transform)(X[, y]) | Update state and return days to cover for this batch. |
| [`set_params`](#skfolio.descriptor.DaysToCover.set_params)(\*\*params)        | Set the parameters of this estimator.                 |

#### SEE ALSO
[`ShortInterest`](https://skfolio.org/generated/skfolio.descriptor.ShortInterest.html.md#skfolio.descriptor.ShortInterest)
: Short interest as fraction of shares outstanding.

[`EWShareTurnover`](https://skfolio.org/generated/skfolio.descriptor.EWShareTurnover.html.md#skfolio.descriptor.EWShareTurnover)
: EWMA share turnover (volume / shares outstanding).

### Notes

`short_interest` is the number of shares held short. Non-missing values must be
finite and non-negative.

`adj_volume` is split-adjusted trading volume. Non-missing values must be finite and
non-negative.

The EWMA state is updated only for positive-volume observations. NaN or zero
`adj_volume` holds the EWMA state and does not increment the valid-observation
count. NaN `short_interest` propagates to the output but does not prevent the volume
state from updating.

The `active_mask` property of the [`AssetPanel`](https://skfolio.org/generated/skfolio.containers.AssetPanel.html.md#skfolio.containers.AssetPanel)
distinguishes holidays from delistings.

### References

* <a id='rba227fd45f66-1'>**[1]**</a> “An investigation of the informational role of short interest in the Nasdaq market” The Journal of Finance. Desai, H., Ramesh, K., Thiagarajan, S. R., & Balachandran, B. V. (2002).
* <a id='rba227fd45f66-2'>**[2]**</a> “Short interest, institutional ownership, and stock returns” Journal of Financial Economics. Asquith, P., Pathak, P. A., & Ritter, J. R. (2005).

### Examples

```pycon
>>> from skfolio.datasets import make_synthetic_characteristics
>>> from skfolio.descriptor import DaysToCover
>>>
>>> X = make_synthetic_characteristics()
>>>
>>> # 1-month EWMA volume smoothing (default)
>>> descriptor = DaysToCover()
>>> days_to_cover = descriptor.fit_transform(X)
>>>
>>> # 3-month EWMA volume smoothing
>>> descriptor = DaysToCover(half_life=63)
>>> days_to_cover = descriptor.fit_transform(X)
```

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

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

Compute exponentially weighted days to cover.

* **Parameters:**
  **X** *AssetPanel*
  : Input panel containing `short_interest` and `adj_volume`.

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

  **\*\*fit_params** *dict*
  : Additional fit parameters. Ignored.
* **Returns:**
  **days_to_cover** *ndarray of shape (n_observations, n_assets)*
  : Short interest divided by EWMA-smoothed daily volume for each observation
    and asset.

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

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

Update state and return days to cover for this batch.

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 `short_interest` and `adj_volume`.

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

  **\*\*fit_params** *dict*
  : Additional fit parameters. Ignored.
* **Returns:**
  **days_to_cover** *ndarray of shape (n_observations, n_assets)*
  : Short interest divided by EWMA-smoothed daily volume for each observation
    and asset.

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

