MulaiMulai sekarang secara gratis

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.

Latihan ini adalah bagian dari kursus

Monte Carlo Simulations in Python

Lihat Kursus

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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)
Edit dan Jalankan Kode