開始使用免費開始

觀察波動叢聚

在金融市場資料中常可觀察到波動叢聚,這會增加時間序列建模的難度。

在這個練習中,你會先熟悉 S&P 500 的日價資料。你將把日報酬計算為價格的百分比變化,繪製結果,並觀察其隨時間的變化情形。

歷史的 S&P 500 日價資料已預先載入為 sp_price

本練習屬於課程

Python 中的 GARCH 模型

檢視課程

練習說明

  • 將日報酬計算為價格的百分比變化,並將結果存入 DataFrame sp_price 的新欄位 Return
  • 透過列印最後 10 列來檢視資料。
  • 繪製 Return 欄位的圖,並觀察是否出現波動叢聚的跡象。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Calculate daily returns as percentage price changes
sp_price['____'] = 100 * (sp_price['Close'].____())

# View the data
print(sp_price.____(____))

# plot the data
plt.plot(sp_price['____'], color = 'tomato', label = 'Daily Returns')
plt.legend(loc='upper right')
plt.show()
編輯並執行程式碼