1. Learn
  2. /
  3. Courses
  4. /
  5. Monte Carlo Simulations in Python

Connected

Exercise

The Law of Large Numbers

You learned in the previous exercise that due to the stochastic nature of Monte Carlo simulations, each simulation result can be very different. In this exercise, you'll leverage the Law of Large Numbers to simulate inflation in 2050 based on the average of a large number of simulations.

The monte_carlo_inflation() function you wrote in the previous exercise is available for use. As a reminder, this is the function code:

def monte_carlo_inflation(year, seed):
    random.seed(seed)
    inflation_rate = 8.6
    yearly_increase = random.randint(1, 3)
    for i in range(year - 2022):
        inflation_rate = inflation_rate * ((100 + yearly_increase)/100)
    return(inflation_rate)

The numpy and random packages have been imported for you.

Instructions

100 XP
  • Calculate the average of 1,000 simulations where a seed between 0 and 20,000 is randomly chosen each time.
  • Calculate the average of 10,000 simulations where a seed between 0 and 20,000 is randomly chosen each time.