Efficient Frontier กับวิกฤตการณ์ทางการเงิน
ก่อนหน้านี้ได้ศึกษา covariance matrix ของพอร์ตโฟลิโอธนาคารเพื่อการลงทุนในช่วงก่อน ระหว่าง และหลังวิกฤตการณ์ทางการเงิน ในแบบฝึกหัดนี้จะมาแสดงผลการเปลี่ยนแปลงของ efficient frontier เพื่อให้เห็นว่าวิกฤตการณ์ทำให้ระดับความเสี่ยงขั้นต่ำสำหรับ ทุก ระดับผลตอบแทนสูงขึ้นอย่างมีนัยสำคัญ
โดยใช้ Critical Line Algorithm (CLA) จากไลบรารี PyPortfolioOpt (pypfopt) เพื่อคำนวณและแสดงผล efficient frontier ในช่วง วิกฤต จากนั้นจะนำมาเพิ่มใน scatterplot ที่แสดง efficient frontier ก่อน และ หลัง วิกฤตอยู่แล้ว
ผลตอบแทนที่คาดหวัง returns_during และ efficient covariance matrix ecov_during รวมถึงอ็อบเจกต์ CLA จาก pypfopt พร้อมใช้งานแล้ว (อย่าลืมว่ากราฟใน DataCamp สามารถขยายเปิดในหน้าต่างใหม่เพื่อให้อ่านได้ชัดขึ้น)
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การบริหารความเสี่ยงเชิงปริมาณด้วย Python
คำแนะนำการฝึกหัด
- สร้างอ็อบเจกต์ critical line algorithm (
CLA) ชื่อefficient_portfolio_duringโดยใช้ผลตอบแทนที่คาดหวังและ efficient covariance ของผลตอบแทน - แสดงผล (print) พอร์ตโฟลิโอที่มี variance ต่ำสุดของ
efficient_portfolio_during - คำนวณ efficient frontier ของ
efficient_portfolio_during - นำผลลัพธ์ของ efficient frontier มาเพิ่มใน scatterplot ที่แสดง efficient frontier ก่อนและหลังวิกฤตอยู่แล้ว
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Initialize the Crtical Line Algorithm object
efficient_portfolio_during = CLA(____, ecov_during)
# Find the minimum volatility portfolio weights and display them
print(efficient_portfolio_during.____)
# Compute the efficient frontier
(ret, vol, weights) = efficient_portfolio_during.____
# Add the frontier to the plot showing the 'before' and 'after' frontiers
plt.scatter(vol, ____, s = 4, c = 'g', marker = '.', label = 'During')
plt.legend()
plt.show()