Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Manipulating Time Series Data in Python

Cursus bekijken

Oefeninstructies

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 investment with the value 1000.
  • Calculate returns by applying .pct_change() to data.
  • Add 1 to returns and assign this to returns_plus_one, then apply .cumprod() to returns_plus_one and assign the result to cumulative_return.
  • Multiply cumulative_return by investment, and plot the result.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# 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 

Code bewerken en uitvoeren