Portfolio Empirical Covariance Matrix

perfana.monte_carlo.risk.portfolio_cov(data, freq)[source]

Forms the empirical portfolio covariance matrix from the simulation data cube

Parameters
  • data (ndarray) – Monte carlo simulation data. This must be 3 dimensional with the axis representing time, trial and asset respectively.

  • freq (Union[str, int]) – Frequency of the data. Can either be a string (‘week’, ‘month’, ‘quarter’, ‘semi-annual’, ‘year’) or an integer specifying the number of units per year. Week: 52, Month: 12, Quarter: 4, Semi-annual: 6, Year: 1.

Returns

Empirical portfolio covariance matrix

Return type

array_like of float

Examples

>>> from perfana.datasets import load_cube
>>> from perfana.monte_carlo import portfolio_cov
>>> data = load_cube()[..., :3]  # first 3 asset classes only
>>> portfolio_cov(data, 'quarterly').round(4)
array([[0.0195, 0.0356, 0.021 ],
       [0.0356, 0.0808, 0.0407],
       [0.021 , 0.0407, 0.0239]])