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

เปรียบเทียบโมเดล AR กับ Random Walk

บางครั้งอาจแยกความแตกต่างระหว่าง time series ที่มีการ mean revert เล็กน้อยกับ time series ที่ไม่ mean revert เลย เช่น random walk ได้ค่อนข้างยาก ในแบบฝึกหัดนี้จะได้เปรียบเทียบ ACF ของชุดข้อมูลอัตราดอกเบี้ยที่มีการ mean revert เล็กน้อยจากแบบฝึกหัดก่อนหน้า กับ random walk ที่จำลองขึ้นมาโดยมีจำนวนข้อสังเกตเท่ากัน

เมื่อพล็อต autocorrelation ของทั้งสองชุดข้อมูลไว้เคียงกัน จะสังเกตได้ว่าทั้งสองมีลักษณะคล้ายกันมาก

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

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

ดูคอร์ส

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

  • นำเข้าฟังก์ชัน plot_acf จากโมดูล statsmodels
  • สร้าง axes สองแกนสำหรับกราฟย่อยทั้งสอง
  • พล็อตฟังก์ชัน autocorrelation สำหรับ 12 lag ของชุดข้อมูลอัตราดอกเบี้ย interest_rate_data ในกราฟด้านบน
  • พล็อตฟังก์ชัน autocorrelation สำหรับ 12 lag ของชุดข้อมูล simulated_data ในกราฟด้านล่าง

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# Import the plot_acf module from statsmodels
from statsmodels.graphics.tsaplots import plot_acf

# Plot the interest rate series and the simulated random walk series side-by-side
fig, axes = plt.subplots(2,1)

# Plot the autocorrelation of the interest rate series in the top plot
fig = plot_acf(___, alpha=1, lags=12, ax=axes[0])

# Plot the autocorrelation of the simulated random walk series in the bottom plot
fig = plot_acf(___, alpha=1, lags=12, ax=axes[1])

# Label axes
axes[0].set_title("Interest Rate Data")
axes[1].set_title("Simulated Random Walk Data")
plt.show()
แก้ไขและรันโค้ด