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

Second moment: Variance

Just like you estimated the first moment of the returns distribution in the last exercise, you can can also estimate the second moment, or variance of a return distribution using numpy.

In this case, you will first need to calculate the daily standard deviation ( \( \sigma \) ), or volatility of the returns using np.std(). The variance is simply \( \sigma ^ 2 \).

StockPrices from the previous exercise is available in your workspace, and numpy is imported as np.

Bu egzersiz

Introduction to Portfolio Risk Management in Python

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

Egzersiz talimatları

  • Calculate the daily standard deviation of the 'Returns' column and set it equal to sigma_daily.
  • Derive the daily variance (second moment, \( \sigma ^ {2} \)) by squaring the standard deviation.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Calculate the standard deviation of daily return of the stock
sigma_daily = ____(StockPrices['Returns'])
print(sigma_daily)

# Calculate the daily variance
variance_daily = ____
print(variance_daily)
Kodu Düzenle ve Çalıştır