Aan de slagGa gratis aan de slag

Arrays and NumPy

NumPy is a scientific computing package in Python that helps you to work with arrays. Let's use array operations to calculate price to earning ratios of the S&P 100 stocks.

The S&P 100 data is available as the lists: prices (stock prices per share) and earnings (earnings per share).

Deze oefening maakt deel uit van de cursus

Introduction to Python for Finance

Cursus bekijken

Oefeninstructies

  • Import the numpy as np.
  • Convert the prices and earnings lists to arrays, prices_array and earnings_array, respectively.
  • Calculate the price to earnings ratio as pe.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Import numpy as np
import ____ as ____

# Convert lists to arrays
prices_array = ____(prices)
earnings_array = ____(earnings)

# Calculate P/E ratio 
pe = ____
print(pe)
Code bewerken en uitvoeren