그렇다면 주가 수익률은요?
이전 연습 문제에서 DataFrame AMZN에 담긴 Amazon 주가가 랜덤 워크를 따른다는 것을 보였어요. 이번 연습 문제에서는 Amazon 수익률(가격의 퍼센트 변화)에 대해 같은 작업을 수행해, 수익률은 랜덤 워크를 따르지 않음을 보여 보겠습니다.
이 연습은 강의의 일부입니다
Python으로 배우는 시계열 분석
연습 안내
- statsmodels에서
adfuller모듈을 가져오세요. .pct_change()메서드를 사용해 가격의 퍼센트 변화를 계산하여 AMZN 수익률 DataFrame을 새로 만드세요.- DataFrame의
.dropna()메서드로 수익률 첫 행의 NaN을 제거하세요. AMZN_ret의'Adj Close'열에 대해 Augmented Dickey-Fuller 검정을 실행하고,results[1]에 있는 p-value를 출력하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Import the adfuller module from statsmodels
from statsmodels.tsa.stattools import adfuller
# Create a DataFrame of AMZN returns
AMZN_ret = ___
# Eliminate the NaN in the first row of returns
AMZN_ret = ___
# Run the ADF test on the return series and print out the p-value
results = adfuller(___)
print('The p-value of the test on returns is: ' + str(results[___]))