使用 PyPortfolioOpt 練習:報酬率
現代投資組合理論(Modern Portfolio Theory)是投資組合風險管理的基石,因為效率前緣是評估投資人風險偏好與市場風險—報酬權衡的標準方法。這個練習中,你將使用 PyPortfolioOpt 的 pypfopt Python 函式庫,開發能探索投資組合效率前緣的實用工具。
要計算效率前緣,需要同時具備投資組合的期望報酬率與共變異數矩陣。
在練習載入投資銀行價格資料之後,你會使用 pypfopt.expected_returns 的 mean_historical_return 方法,從每日資產價格計算並視覺化各家銀行的年化平均報酬率。下一題將會介紹共變異數矩陣。
本練習屬於課程
Python 量化風險管理
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Load the investment portfolio price data into the price variable.
prices = pd.____("portfolio.csv")
# Convert the 'Date' column to a datetime index
prices['Date'] = pd.to_datetime(____['Date'], format='%d/%m/%Y')
prices.____(['Date'], inplace = True)