LoslegenKostenlos loslegen

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

Diese Übung ist Teil des Kurses

Python for MATLAB Users

Kurs anzeigen

Anleitung zur Übung

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

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# 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.____()
Code bearbeiten und ausführen