Monte Carlo VaR
報酬率與 Monte Carlo 模擬路徑都可以用來分析許多議題,從選擇權定價模型與避險,到投資組合最佳化與交易策略。
請在每次迭代時彙總報酬資料,並使用所得數值來預測參數式 VaR(99)。
參數 mu、vol、T 與 S0 可從前一個練習取得。
本練習屬於課程
Python 投資組合風險管理入門
練習說明
- 在每次迭代中,使用
.append()方法將rand_rets加到sim_returns清單。 - 對
sim_returns使用np.percentile()函式計算參數式 VaR(99)。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Aggregate the returns
sim_returns = []
# Loop through 100 simulations
for i in range(100):
# Generate the Random Walk
rand_rets = np.random.normal(mu, vol, T)
# Save the results
sim_returns.____
# Calculate the VaR(99)
var_99 = ____
print("Parametric VaR(99): ", round(100*var_99, 2),"%")