BaşlayınÜcretsiz Başlayın

Portfolio standard deviation

In order to calculate portfolio volatility, you will need the covariance matrix, the portfolio weights, and knowledge of the transpose operation. The transpose of a numpy array can be calculated using the .T attribute. The np.dot() function is the dot-product of two arrays.

The formula for portfolio volatility is:

$$ \sigma_{Portfolio} = \sqrt{ w_T \cdot \Sigma \cdot w } $$

  • \( \sigma_{Portfolio} \): Portfolio volatility
  • \( \Sigma \): Covariance matrix of returns
  • w: Portfolio weights (\( w_T \) is transposed portfolio weights)
  • \( \cdot \) The dot-multiplication operator

portfolio_weights and cov_mat_annual are available in your workspace.

Bu egzersiz

Introduction to Portfolio Risk Management in Python

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

Calculate the portfolio volatility assuming you use the portfolio_weights by following the formula above.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Import numpy as np
import numpy as np

# Calculate the portfolio standard deviation
portfolio_volatility = ____(np.dot(portfolio_weights.T, np.dot(cov_mat_annual, portfolio_weights)))
print(portfolio_volatility)
Kodu Düzenle ve Çalıştır