开始使用免费开始使用

无法预测白噪声

白噪声时间序列只是由相互不相关且同分布的随机变量构成的一串序列。股票收益常被建模为白噪声。遗憾的是,对于白噪声,无法依据过去观测来预测未来——所有滞后期的自相关都为 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()
编辑并运行代码