Cumulative return on $1,000 invested in google vs apple I
To put your new ability to do cumulative return calculations to practical use, let's compare how much $1,000 would be worth if invested in Google ('GOOG') or Apple ('AAPL') in 2010.
This exercise is part of the course
Manipulating Time Series Data in Python
Exercise instructions
We have already imported pandas as pd, and matplotlib.pyplot as plt. We have also loaded Google and Apple stock prices in a variable data.
- Define a variable
investmentwith the value1000. - Calculate
returnsby applying.pct_change()todata. - Add 1 to
returnsand assign this toreturns_plus_one, then apply.cumprod()toreturns_plus_oneand assign the result tocumulative_return. - Multiply
cumulative_returnbyinvestment, and plot the result.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Define your investment
investment = ____
# Calculate the daily returns here
returns = ____
# Calculate the cumulative returns here
returns_plus_one = ____
cumulative_return = ____
# Calculate and plot the investment return here