White Noise ไม่สามารถพยากรณ์ได้
อนุกรมเวลาแบบ white noise คือลำดับของตัวแปรสุ่มที่ไม่มีความสัมพันธ์ต่อกันและมีการกระจายตัวแบบเดียวกัน ผลตอบแทนของหุ้นมักถูกจำลองในรูปแบบ white noise และน่าเสียดายที่สำหรับ white noise นั้น เราไม่สามารถพยากรณ์ค่าในอนาคตจากข้อมูลในอดีตได้ เนื่องจากค่า autocorrelation ทุก lag เป็นศูนย์
ในแบบฝึกหัดนี้ จะได้สร้างอนุกรม white noise และพล็อต autocorrelation function เพื่อแสดงให้เห็นว่าค่าเป็นศูนย์ในทุก lag โดยใช้ np.random.normal() ในการสุ่มค่าผลตอบแทน สำหรับกระบวนการ Gaussian white noise ค่าเฉลี่ยและส่วนเบี่ยงเบนมาตรฐานจะอธิบายลักษณะของกระบวนการทั้งหมด
ลองพล็อตอนุกรม white noise เพื่อดูว่ามีลักษณะอย่างไร จากนั้นพล็อต autocorrelation function
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การวิเคราะห์อนุกรมเวลาด้วย Python
คำแนะนำการฝึกหัด
- สุ่มค่าผลตอบแทนแบบ normal distribution จำนวน 1000 ค่า โดยใช้
np.random.normal()กำหนดค่าเฉลี่ย 2% (0.02) และส่วนเบี่ยงเบนมาตรฐาน 5% (0.05) โดยใช้อาร์กิวเมนต์locสำหรับค่าเฉลี่ย และscaleสำหรับส่วนเบี่ยงเบนมาตรฐาน - ตรวจสอบค่าเฉลี่ยและส่วนเบี่ยงเบนมาตรฐานของผลตอบแทนโดยใช้
np.mean()และnp.std() - พล็อตอนุกรมเวลา
- พล็อต autocorrelation function โดยใช้
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()