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\)
Deze oefening maakt deel uit van de cursus
Python for MATLAB Users
Oefeninstructies
- 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.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# 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.____()