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 exercício faz parte do curso
Introduction to Portfolio Risk Management in Python
Instruções do exercício
- 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 theforecasted_valuesas the second argument.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# 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()