백색잡음은 예측할 수 없어요
백색잡음 시계열은 동일한 분포를 따르는 비상관(random, 독립) 변수들의 순서열입니다. 주식 수익률은 종종 백색잡음으로 모형화돼요. 안타깝게도 백색잡음의 경우 과거로 미래를 예측할 수 없습니다. 모든 시차에서 자기상관이 0이기 때문이죠.
백색잡음 시리즈를 생성하고 자기상관함수(ACF)를 그려 모든 시차에서 0에 가깝다는 것을 확인해 보세요. 무작위 수익률 생성에는 np.random.normal()을 사용할 수 있습니다. 가우시안 백색잡음 과정에서는 평균과 표준편차만으로 전체 과정을 설명할 수 있어요.
이 백색잡음 시리즈를 먼저 그려 형태를 살펴보고, 이어서 자기상관함수를 그려 보세요.
이 연습은 강의의 일부입니다
Python으로 배우는 시계열 분석
연습 안내
- 평균 2%(0.02), 표준편차 5%(0.05)를 갖는 정규분포에서
np.random.normal()로 무작위 수익률 1000개를 생성하세요. 평균은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()