แก้ปัญหาการปรับพอร์ตโฟลิโอให้เหมาะสมแบบง่าย
แบบฝึกหัดแรกนี้จะสอนให้รู้จักวิธีแก้ปัญหาการปรับพอร์ตโฟลิโอให้เหมาะสมแบบง่ายโดยใช้ PortfolioAnalytics โดยจะได้เรียนรู้วิธีสร้าง portfolio specification object การเพิ่ม constraint และ objective รวมถึงการแก้ปัญหาการปรับให้เหมาะสม โจทย์ในที่นี้คือการสร้างพอร์ตโฟลิโอที่มี variance ต่ำที่สุด ภายใต้เงื่อนไข full investment และ long only constraint โดยมี constraint 2 ข้อ ได้แก่ full investment constraint ที่กำหนดให้ผลรวมของน้ำหนักทุกสินทรัพย์เท่ากับ 1 และ long only constraint ที่กำหนดให้น้ำหนักทุกตัวต้องมากกว่าหรือเท่ากับ 0 (กล่าวคือ ไม่อนุญาตให้ short)
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การวิเคราะห์พอร์ตโฟลิโอระดับกลางใน R
คำแนะนำการฝึกหัด
- สร้าง portfolio specification object โดยใช้ชื่อสินทรัพย์จากชุดข้อมูล
index_returnsแล้วตั้งชื่อ object นี้ว่าport_spec - เพิ่ม full investment constraint ที่กำหนดให้ผลรวมของน้ำหนักเท่ากับ 1 ลงใน
port_spec - เพิ่ม long only constraint ที่กำหนดให้น้ำหนักของสินทรัพย์แต่ละตัวอยู่ระหว่าง 0 ถึง 1 ลงใน
port_spec - เพิ่ม objective เพื่อลด standard deviation ของพอร์ตโฟลิโอให้น้อยที่สุดลงใน
port_spec - แก้ปัญหาการปรับพอร์ตโฟลิโอให้เหมาะสมโดยใช้
optimize_method = "ROI"แล้วกำหนดผลลัพธ์ที่ได้ให้กับ object ชื่อopt
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Create the portfolio specification
port_spec <- portfolio.spec(colnames(___))
# Add a full investment constraint such that the weights sum to 1
port_spec <- add.constraint(portfolio = ___, type = "___")
# Add a long only constraint such that the weight of an asset is between 0 and 1
port_spec <- add.constraint(portfolio = ___, type = "___")
# Add an objective to minimize portfolio standard deviation
port_spec <- add.objective(portfolio = ___, type = "___", name = "___")
# Solve the optimization problem
opt <- optimize.portfolio(___, portfolio = ___, optimize_method = "___")