<a id="skfolio-metrics-portfolio-variance-qlike-loss"></a>

# skfolio.metrics.portfolio_variance_qlike_loss

<a id="skfolio.metrics.portfolio_variance_qlike_loss"></a>

### skfolio.metrics.portfolio_variance_qlike_loss(estimator, X_test, y=None, portfolio_weights=None)

QLIKE loss for a projected portfolio variance forecast [[1]](#r7dedfcdc36e0-1).

Let $r_t$ be the one-period realized return vector at time $t$
and $w^\top r_t$ the corresponding one-period portfolio return for
weights $w$. The loss compares the forecast portfolio variance
with the realized sum of squared portfolio returns over the evaluation
window of $h$ observations:

$$
\ell = \log\left(h\, w^\top \Sigma\, w\right)
     + \frac{\sum_{t=1}^{h} (w^\top r_t)^2}{h\, w^\top \Sigma\, w}
$$

Lower values are better. In expectation, the loss is minimized by the
true conditional portfolio variance forecast.

When `X_test` contains NaNs (e.g. holidays, pre-listing, or post-delisting
periods), NaN returns for active assets contribute zero to the realized
portfolio return. The forecast covariance is scaled by the pairwise
observation count matrix $H$ (Hadamard product
$H \odot \Sigma$) so that the realized portfolio variance and
forecast variance follow the same missing-data convention. In skfolio,
NaN diagonal entries in the forecast covariance mark inactive assets,
which are excluded before the score is computed.

When multiple portfolios are provided (2D weights), the QLIKE is computed
independently for each and the mean is returned. This lets one summary
score evaluate several portfolio directions at once.

* **Parameters:**
  **estimator** *BaseEstimator*
  : Fitted estimator, must expose `covariance_` or `return_distribution_.covariance`.

  **X_test** *array-like of shape (n_observations, n_assets)*
  : Realized returns for the test window.

  **y** *Ignored*
  : Present for scikit-learn API compatibility.

  **portfolio_weights** *array-like of shape (n_assets,) or (n_portfolios, n_assets), optional*
  : Portfolio weights. If `None` (default), inverse-volatility weights are used,
    which neutralizes volatility dispersion so that high-volatility assets do not
    dominate the diagnostic. If a 2D array is provided, each row defines a test
    portfolio and the mean QLIKE across portfolios is returned.
* **Returns:**
  float
  : Mean portfolio QLIKE loss. Lower values are better; in expectation, the loss
    is minimized by the true conditional portfolio variance forecast.

#### SEE ALSO
[`portfolio_variance_calibration_ratio`](https://skfolio.org/generated/skfolio.metrics.portfolio_variance_calibration_ratio.html.md#skfolio.metrics.portfolio_variance_calibration_ratio)
: Calibration ratio for the projected portfolio variance.

[`portfolio_variance_calibration_loss`](https://skfolio.org/generated/skfolio.metrics.portfolio_variance_calibration_loss.html.md#skfolio.metrics.portfolio_variance_calibration_loss)
: Calibration loss for the projected portfolio variance.

[`qlike_loss`](https://skfolio.org/generated/skfolio.metrics.qlike_loss.html.md#skfolio.metrics.qlike_loss)
: Univariate QLIKE loss.

### References

* <a id='r7dedfcdc36e0-1'>**[1]**</a> “Volatility forecast comparison using imperfect volatility proxies” Journal of Econometrics. Patton, A. J. (2011).

