Aan de slagGa gratis aan de slag

Import index component price information

Now you'll use the stock symbols for the companies you selected in the last exercise to calculate returns for each company.

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 for you. We have also made the variable tickers available to you, which contains the Stock Symbol for each index component as a list.

  • Print tickers to verify the content matches your result from the last exercise.
  • Use pd.read_csv() to import 'stock_prices.csv', parsing the 'Date' column and also setting the 'Date' column as index before assigning the result to stock_prices. Inspect the result using .info().
  • Calculate the price return for the index components by dividing the last row of stock_prices by the first, subtracting 1 and multiplying by 100. Assign the result to price_return.
  • Plot a horizontal bar chart of the sorted returns with the title Stock Price Returns.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Print tickers
print(____)

# Import prices and inspect result
stock_prices = ____
print(____)

# Calculate the returns
price_return = ____

# Plot horizontal bar chart of sorted price_return   


Code bewerken en uitvoeren