開始使用免費開始

無法預測 White Noise

白噪音(white noise)時間序列就是一串彼此不相關且同分配的隨機變數。股票報酬常被建模為白噪音。不幸的是,對白噪音而言,我們無法根據過去來預測未來的觀測值——所有落後期的自相關都為 0。

你將產生一個白噪音序列,並繪製自相關函數來顯示在所有落後期都為 0。你可以使用 np.random.normal() 產生隨機報酬。對高斯白噪音流程而言,平均數與標準差即可描述整個流程。

先把這個白噪音序列畫出來看看長什麼樣子,然後再繪製自相關函數。

本練習屬於課程

Python 中的時間序列分析

檢視課程

練習說明

  • 使用 np.random.normal() 產生 1000 筆常態分佈的隨機報酬,平均數 2%(0.02)、標準差 5%(0.05),其中平均數用參數 loc,標準差用參數 scale
  • 使用 np.mean()np.std() 驗證報酬的平均數與標準差。
  • 繪製時間序列圖。
  • 使用 plot_acf 並設定 lags=20 繪製自相關函數。

動手互動練習

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

# Import the plot_acf module from statsmodels
from statsmodels.graphics.tsaplots import plot_acf

# Simulate white noise returns
returns = np.random.normal(loc=___, scale=___, size=___)

# Print out the mean and standard deviation of returns
mean = np.mean(___)
std = np.std(___)
print("The mean is %5.3f and the standard deviation is %5.3f" %(mean,std))

# Plot returns series
plt.plot(___)
plt.show()

# Plot autocorrelation function of white noise returns
plot_acf(___, lags=___)
plt.show()
編輯並執行程式碼