Get Started

Monte Carlo VaR

Both the return values and the Monte-Carlo paths can be used for analysis of everything ranging from option pricing models and hedging to portfolio optimization and trading strategies.

Aggregate the returns data at each iteration, and use the resulting values to forecast parametric VaR(99).

The parameters mu, vol, T, and S0 are available from the previous exercise.

This is a part of the course

“Introduction to Portfolio Risk Management in Python”

View Course

Exercise instructions

  • Use the .append() method to append the rand_rets to sim_returns list in each iteration.
  • Calculate the parametric VaR(99) using the np.percentile() function on sim_returns.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# 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),"%")

This exercise is part of the course

Introduction to Portfolio Risk Management in Python

IntermediateSkill Level
4.5+
11 reviews

Evaluate portfolio risk and returns, construct market-cap weighted equity portfolios and learn how to forecast and hedge market risk via scenario generation.

In this chapter, you will learn two different methods to estimate the probability of sustaining losses and the expected values of those losses for a given asset or portfolio of assets.

Exercise 1: Estimating tail riskExercise 2: Historical drawdownExercise 3: Historical value at riskExercise 4: Historical expected shortfallExercise 5: VaR extensionsExercise 6: Changing VaR and CVaR quantilesExercise 7: Parametric VaRExercise 8: Scaling risk estimatesExercise 9: Random walksExercise 10: A random walk simulationExercise 11: Monte Carlo simulationsExercise 12: Monte Carlo VaR
Exercise 13: Understanding risk

What is DataCamp?

Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.

Start Learning for Free