1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to Financial Concepts in Python

Connected

Exercise

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.

Instructions

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