Get startedGet started for free

Investing a percentage of your income (II)

To finish up your investment simulation, you will need to loop through each time period, calculate the growth of any investments you have already made, add your new monthly deposit, and calculate your net worth at each point in time.

You can do it!

Cumulative savings (cumulative_savings_new) from the previous exercise is available, and investment_portfolio and net_worth are pre-allocated empty numpy arrays of length equal to forecast_months.

This exercise is part of the course

Introduction to Financial Concepts in Python

View Course

Exercise instructions

  • For each period, set your previous_investment equal to the previous value of investment_portfolio, unless it is the first iteration, in which case you have no investments yet.
  • Calculate your net worth at each time period by summing your cumulative savings and investment portfolio at that same time period.
  • Run the provided code to see a plot of net worth vs. savings and investments.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

import numpy as np

# Loop through each forecast period
for i in range(forecast_months):
    
    # Find the previous investment deposit amount
    if i == 0: 
        previous_investment = ____
    else:
        previous_investment = ____
        
    # Calculate the value of your previous investments, which have grown
    previous_investment_growth = previous_investment*(1 + investment_rate_monthly)
    
    # Add your new deposit to your investment portfolio
    investment_portfolio[i] =  previous_investment_growth + investment_deposit_forecast[i]
    
    # Calculate your net worth at each point in time
    net_worth[i] = ____
         
# Plot your forecasted cumulative savings vs investments and net worth
plot_investments(investment_portfolio, cumulative_savings_new, net_worth)
Edit and Run Code