portfolio volatility formula

portfolio_std = np.sqrt(np.dot(weights.T, np.dot(cov_matrix, weights))) * np.sqrt(252)


what i have understood:

• in order to understand portfolio volatility one cannot just sum the volatility of each stock multiplyed by weigths because correlations between them has to be taken in consideration
• portfolio standard deviation is equal to square root of portfolio variance so np.sqrt(ptf_variance)
• in the covariance matrix i have the variance of each stock in the diagonal

what i have not understood:
the double matrix multiplication between the transpose of weigths and the covariance matrix
 np.dot(weights.T, np.dot(cov_matrix, weights)  what does it mean this double .dot and whay should it return the portfolio variance?

1 response

The portfolio standard deviation depends on three things: weights of the assets, standard deviation of them, and the degree of correlation that its assets have.
The formula for computing the portfolio standard deviation is in the next link with an explanation . Since it is done with a sum of coefficients, the fastest and optimal way for calculate this is with matrixes, thats why you need to work with matrixes algebra and transpose them to apply vectorial products.
Regards.
 https://www.wallstreetmojo.com/portfolio-standard-deviation/