เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

ราคาหุ้นเป็น Random Walk หรือไม่?

ราคาหุ้นส่วนใหญ่เป็นไปตามแบบจำลอง random walk (อาจมี drift ร่วมด้วย) ในแบบฝึกหัดนี้ จะได้ดูข้อมูล time series ของราคาหุ้น Amazon ซึ่งโหลดไว้ล่วงหน้าใน DataFrame AMZN แล้วรัน 'Augmented Dickey-Fuller Test' จากไลบรารี statsmodels เพื่อยืนยันว่าราคาหุ้นดังกล่าวเป็นไปตาม random walk จริง

สำหรับ ADF test นั้น "null hypothesis" (สมมติฐานที่เราจะปฏิเสธหรือไม่ปฏิเสธ) คือ time series เป็น random walk ดังนั้น หาก p-value ต่ำ (เช่น น้อยกว่า 5%) หมายความว่าเราสามารถปฏิเสธ null hypothesis ที่ว่า time series นั้นเป็น random walk ได้

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

การวิเคราะห์อนุกรมเวลาด้วย Python

ดูคอร์ส

คำแนะนำการฝึกหัด

  • Import โมดูล adfuller จาก statsmodels
  • รัน Augmented Dickey-Fuller test บน time series ของราคาปิดหุ้น ซึ่งอยู่ในคอลัมน์ 'Adj Close' ของ DataFrame AMZN
  • แสดงผลลัพธ์ทั้งหมด ซึ่งประกอบด้วย test statistic, p-value และ critical values สำหรับระดับนัยสำคัญ 1%, 10% และ 5%
  • แสดงเฉพาะ p-value ของการทดสอบ (โดยที่ results[0] คือ test statistic และ 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[___]))
แก้ไขและรันโค้ด