Portfolio Volatility

perfana.monte_carlo.risk.volatility_m(cov_or_data, weights, freq=None)[source]

Calculates the portfolio volatility given a simulated returns cube or a covariance matrix

Notes

If a simulated returns data cube is given, the frequency of the data must be specified. In this case, the empirical covariance matrix would be used to derive the volatility.

Parameters
  • cov_or_data (ndarray) – Covariance matrix or simulated returns data cube.

  • weights (Union[Iterable[Union[int, float]], ndarray, Series]) – Weights of the portfolio. This must be 1 dimensional and must match the dimension of the covariance matrix shape or the simulated data’s last axis.

  • freq (Union[str, int, None]) – 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

Portfolio volatility.

Return type

float

Examples

>>> from perfana.datasets import load_cube
>>> from perfana.monte_carlo import portfolio_cov, volatility_m
>>> data = load_cube()[..., :3]  # first 3 asset classes only
>>> weights = [0.33, 0.34, 0.33]
>>> freq = 'quarterly'
>>> cov_mat = portfolio_cov(data, freq).round(4)  # empirical covariance matrix
>>> # Using covariance matrix
>>> volatility_m(cov_mat, weights)
0.1891091219375734
>>> # Using the simulated returns data cube
>>> volatility_m(data, weights, freq)
0.1891091219375734