A closer look at the sectors

Introduction to Python for Finance

Adina Howe

Instructor

Your mission

Given

NumPy arrays of data describing the S&P 100: names, prices, earnings, sectors

Objective Part II

Explore and analyze sector-specific P/E ratios within companies of the S&P 100

Introduction to Python for Finance

Step 1: Create a boolean filtering array

stock_prices = np.array([100, 200, 300])
filter_array = (stock_prices >= 150)
print(filter_array)
[ False True  True]
Introduction to Python for Finance

Step 2: Apply filtering array to subset another array

stock_prices = np.array([100, 200, 300])
filter_array = (stock_prices >= 150)
print(stock_prices[filter_array])
[200 300]
Introduction to Python for Finance

Step 3: Summarize P/E ratios

Calculate the average and standard deviation of these sector-specific P/E ratios

import numpy as np
average_value = np.mean(my_array)
std_value = np.std(my_array)
Introduction to Python for Finance

Let's practice!

Introduction to Python for Finance

Preparing Video For Download...