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\)

This exercise is part of the course

Python for MATLAB Users

View Course

Exercise 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.

Hands-on interactive exercise

Have a go at this exercise by completing this sample 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.____()