<a id="skfolio-utils-tools-apply-window-size"></a>

# skfolio.utils.tools.apply_window_size

<a id="skfolio.utils.tools.apply_window_size"></a>

### skfolio.utils.tools.apply_window_size(X, window_size)

Return the last `window_size` observations from the array X.

* **Parameters:**
  **X** *ndarray of shape (n_observations,) or (n_observations, n_assets)*
  : Input array from which to extract the last observations.
    Can be 1D or 2D.

  **window_size** *int or None*
  : Number of observations to keep from the end of X.
    If None, returns X unchanged.
* **Returns:**
  **X_windowed** *ndarray*
  : The last `window_size` rows of X. If `window_size` is None,
    returns the original array unchanged.
* **Raises:**
  ValueError
  : If `window_size` is not a positive integer or cannot be converted to int.

  ValueError
  : If `window_size` exceeds the number of observations in X.

### Examples

```pycon
>>> import numpy as np
>>> X = np.array([[1, 2], [3, 4], [5, 6], [7, 8], [9, 10]])
>>> apply_window_size(X, window_size=3)
array([[ 5,  6],
       [ 7,  8],
       [ 9, 10]])
```

