sample_covΒΆ

Defined in fynance.portfolio.covariance

sample_cov(X, ddof=1)[source]

Sample covariance matrix of a returns panel.

Thin, validated wrapper around numpy.cov: a 1-D input is treated as a single asset (returns [[var]]); non-finite values raise.

Parameters:
Xarray_like

Returns panel, shape (T,) or (T, N).

ddofint, optional

Delta degrees of freedom (ddof=1 is the unbiased sample covariance, ddof=0 the population/maximum-likelihood one). Default 1.

Returns:
np.ndarray

Symmetric (N, N) covariance matrix.

Examples

>>> import numpy as np
>>> X = np.array([[1.0, 2.0], [2.0, 1.0], [3.0, 4.0]])
>>> sample_cov(X, ddof=1)
array([[1.        , 1.        ],
       [1.        , 2.33333333]])