Stochastic nature of Monte Carlo simulation
In the previous exercise, you modeled information deterministically. You'll now attempt to estimate future inflation with a stochastic model, using a Monte Carlo simulation.
Recall that stochastic models simulate randomness in variables by using sampling. This randomness means that each simulation will likely arrive at a different expected outcome, even if the inputs are the same. We saw this in the video by running Monte Carlo simulations with different seeds.
In this exercise, assume 8.6% inflation in 2022 and a stochastic increase of 1%, 2%, or 3% each year over the previous year (with equal probabilities of 1%, 2%, or 3%) for the following years. What will the inflation rate look like in 2050 under these assumptions?
The random
package has already been imported for you as random
.
This exercise is part of the course
Monte Carlo Simulations in Python
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Complete the function definition by defining the yearly_increase variable
def monte_carlo_inflation(year, seed):
random.seed(seed)
inflation_rate = 8.6
yearly_increase = ____
for i in range(year - 2022):
inflation_rate = inflation_rate*((100 + yearly_increase)/100)
return(inflation_rate)