주가는 랜덤 워크일까요?
대부분의 주가는 (드리프트가 있을 수 있는) 랜덤 워크를 따릅니다. 이 연습에서는 DataFrame AMZN에 미리 로드된 Amazon 주가 시계열을 살펴보고, statsmodels 라이브러리의 'Augmented Dickey-Fuller Test'를 실행해 실제로 랜덤 워크를 따르는지 확인해 보겠습니다.
ADF 검정에서 "귀무가설"(우리가 기각하거나 기각하지 못하는 가설)은 시계열이 랜덤 워크를 따른다는 것입니다. 따라서 p-value가 낮다면(예: 5% 미만) 해당 시계열이 랜덤 워크라는 귀무가설을 기각할 수 있습니다.
이 연습은 강의의 일부입니다
Python으로 배우는 시계열 분석
연습 안내
- statsmodels에서
adfuller모듈을 가져오세요. - 종가 시계열(
AMZNDataFrame의'Adj Close'열)에 대해 Augmented Dickey-Fuller 검정을 실행하세요. - 검정 통계량, p-value, 그리고 1%, 5%, 10% 유의수준에 대한 임계값이 포함된 전체 출력을 출력하세요.
- 검정의 p-value만 따로 출력하세요 (
results[0]는 검정 통계량,results[1]는 p-value입니다).
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Import the adfuller module from statsmodels
from statsmodels.tsa.stattools import adfuller
# Run the ADF test on the price series and print out the results
results = adfuller(___)
print(results)
# Just print out the p-value
print('The p-value of the test on prices is: ' + str(results[___]))