Portfolio Beta against Asset

perfana.monte_carlo.risk.beta_m(cov_or_data, weights, freq=None, aid=0)[source]

Derives the portfolio beta with respect to the specified asset class

Notes

The asset is identified by its index (aid) on the covariance matrix / simulated returns cube / weight vector. 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.

  • aid – Asset index

Returns

Portfolio beta with respect to asset class.

Return type

float

Examples

>>> from perfana.datasets import load_cube
>>> from perfana.monte_carlo import portfolio_cov, beta_m
>>> data = load_cube()[..., :3]  # first 3 asset classes only
>>> weights = [0.33, 0.34, 0.33]
>>> freq = 'quarterly'
>>> dm_eq_id = 0  # calculate correlation with respect to developing markets equity
>>> beta_m(data, weights, freq, dm_eq_id)
1.3047194776321622