開始使用免費開始

Monte Carlo VaR

報酬率與 Monte Carlo 模擬路徑都可以用來分析許多議題,從選擇權定價模型與避險,到投資組合最佳化與交易策略。

請在每次迭代時彙總報酬資料,並使用所得數值來預測參數式 VaR(99)。

參數 muvolTS0 可從前一個練習取得。

本練習屬於課程

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),"%")
編輯並執行程式碼