ComenzarEmpieza gratis

Monte Carlo simulations

Monte-Carlo simulations are used to model a wide range of possibilities.

Monte-Carlos can be constructed in many different ways, but all of them involve generating a large number of random variants of a given model, allowing a wide distribution of possible paths to be analyzed. This can allow you to build a comprehensive forecast of possibilities to sample from without a large amount of historical data.

Generate 100 Monte-Carlo simulations for the USO oil ETF.

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

Este ejercicio forma parte del curso

Introduction to Portfolio Risk Management in Python

Ver curso

Instrucciones del ejercicio

  • Loop from 0 to 100 (not including 100) using the range() function.
  • Call the plotting function for each iteration using the plt.plot() function, passing the range of values T (range(T)) as the first argument and the forecasted_values as the second argument.

Ejercicio interactivo práctico

Prueba este ejercicio completando el código de muestra.

# Loop through 100 simulations
for i in ____:

    # Generate the random returns
    rand_rets = np.random.normal(mu, vol, T) + 1
    
    # Create the Monte carlo path
    forecasted_values = S0*(rand_rets).cumprod()
    
    # Plot the Monte Carlo path
    plt.plot(____, ____)

# Show the simulations
plt.show()
Editar y ejecutar código