定義投資組合最佳化問題
我們要定義一個投資組合最佳化問題:在滿倉投資與僅做多的限制下,將投資組合的標準差最小化。本題會根據這個問題來建立投資組合規格。接下來本章的練習都會以此處建立的初始投資組合規格為基礎繼續擴充。
本練習屬於課程
R 中級投資組合分析
練習說明
- 使用
asset_returns資料集中的資產建立一個投資組合規格物件,並將其命名為port_spec。 - 在
port_spec物件中新增滿倉投資限制,使權重總和為 1。 - 在
port_spec物件中新增僅做多限制,使每個資產的權重介於 0 到 1 之間。 - 在
port_spec物件中新增一個目標,將投資組合的標準差最小化。 - 列印該投資組合規格物件。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Create the portfolio specification
# Add a full investment constraint such that the weights sum to 1
# Add a long only constraint such that the weight of an asset is between 0 and 1
# Add an objective to minimize portfolio standard deviation
# Print the portfolio specification