CommencerCommencer gratuitement

Forecasting over time

In this exercise, you're going to use NumPy arrays to explore how an investment increases over 20 years. The forecast is calculated using the following formula:

\( balance = deposit (1 + rate)^{years} \)

You need to calculate and plot the percent gain on the investment for each month over 20 years, which is represented by the NumPy array years and has already been loaded into your workspace, along with the deposit and annual_rate of return. The calculation for percent gain is as follows:

\( gain = \dfrac{(balance-deposit)}{deposit}\times100\)

Cet exercice fait partie du cours

Python for MATLAB Users

Afficher le cours

Instructions

  • Forecast the balance in the account for each time point in the variable years.
  • Calculate the percent gain in the account.
  • Plot the percent gain as a function of years.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Calculate the balance in the account for each time in the variable years
balance =

# Calculate the percent gain in the account
percent_gain =

# Plot the percent gain as a function of years
plt.plot(____,____)
plt.____('Years')
plt.____('Percent Gain')
plt.____()
Modifier et exécuter le code