Historical and Monte Carlo Simulation

Quantitative Risk Management in Python

Jamsheed Shorish

Computational Economist

Historical simulation

  • No appropriate class of distributions?
  • Historical simulation: use past to predict future
    • No distributional assumption required
    • Data about previous losses become simulated losses for tomorrow
Quantitative Risk Management in Python

Historical simulation in Python

  • VaR: start with returns in asset_returns
  • Compute portfolio_returns using portfolio weights
  • Convert portfolio_returns into losses
  • VaR: compute np.quantile() for losses at e.g. 95% confidence level
  • Assumes future distribution of losses is exactly the same as past

 

weights = [0.25, 0.25, 0.25, 0.25]

portfolio_returns = asset_returns.dot(weights)
losses = - portfolio_returns
VaR_95 = np.quantile(losses, 0.95)
Quantitative Risk Management in Python

Monte Carlo simulation

  • Monte Carlo simulation: powerful combination of parametric estimation and simulation
    • Assumes distribution(s) for portfolio loss and/or risk factors
    • Relies upon random draws from distribution(s) to create random path, called a run
    • Repeat random draws $\Rightarrow$ creates set of simulation runs
  • Compute simulated portfolio loss over each run up to desired time
  • Find VaR estimate as quantile of simulated losses
Quantitative Risk Management in Python

Monte Carlo simulation in Python

  • Step One:
    • Import Normal distribution norm from scipy.stats
    • Define total_steps (1 day = 1440 minutes)
    • Define number of runs N
    • Compute mean mu and standard deviation sigma of portfolio_losses data
from scipy.stats import norm

total_steps = 1440
N = 10000
mu = portfolio_losses.mean() sigma = portfolio_losses.std()
Quantitative Risk Management in Python

Monte Carlo simulation in Python

  • Step Two:
    • Initialize daily_loss vector for N runs
    • Loop over N runs
      • Compute Monte Carlo simulated loss vector
        • Uses norm.rvs() to draw repeatedly from standard Normal distribution
        • Draws match data using mu and sigma scaled by 1/total_steps
daily_loss = np.zeros(N)

for n in range(N):
loss = ( mu * (1/total_steps) + norm.rvs(size=total_steps) * sigma * np.sqrt(1/total_steps) )
Quantitative Risk Management in Python

Monte Carlo simulation in Python

  • Step Three:
    • Generate cumulative daily_loss, for each run n
    • Use np.quantile() to find the VaR at e.g. 95% confidence level, over daily_loss

 

daily_loss = np.zeros(N)
for n in range(N):

loss = mu * (1/total_steps) + ... norm.rvs(size=total_steps) * sigma * np.sqrt(1/total_steps)
daily_loss[n] = sum(loss)
VaR_95 = np.quantile(daily_loss, 0.95)
Quantitative Risk Management in Python

Simulating asset returns

  • Refinement: generate random sample paths of asset returns in portfolio
    • Allows more realism: asset returns can be individually simulated
    • Asset returns can be correlated
      • Recall: efficient covariance matrix e_cov
      • Used in Step 2 to compute asset returns
  • Exercises: Monte Carlo simulation with asset return simulation
Quantitative Risk Management in Python

Let's practice!

Quantitative Risk Management in Python

Preparing Video For Download...