Introd u cing the dataset IN TR OD U C TION TO P YTH ON FOR FIN AN C E Adina Ho w e Instr u ctor
O v erall Re v ie w P y thon shell and scripts Variables and data t y pes Lists Arra y s Methods and f u nctions Inde x ing and s u bse � ing Matplotlib INTRODUCTION TO PYTHON FOR FINANCE
S & P 100 Companies Standard and Poor ' s S & P 100: made u p of major companies that span m u ltiple ind u str y gro u ps u sed to meas u re stock performance of large companies INTRODUCTION TO PYTHON FOR FINANCE
S & P 100 Case St u d y Sectors of Companies w ithin the S & P 100 in 2017 INTRODUCTION TO PYTHON FOR FINANCE
The data INTRODUCTION TO PYTHON FOR FINANCE
Price to Earnings Ratio Market price Price to earning ratio = Earnings per share The ratio for v al u ing a compan y that meas u res its c u rrent share price relati v e to its per - share earnings In general , higher P / E ratio indicates higher gro w th e x pectations INTRODUCTION TO PYTHON FOR FINANCE
Yo u r mission GIVEN Lists of data describing the S & P 100: names , prices , earnings , sectors OBJECTIVE PART I E x plore and anal yz e the S & P 100 data , speci � call y the P / E ratios of S & P 100 companies INTRODUCTION TO PYTHON FOR FINANCE
Step 1: e x amine the lists In [1]: my_list = [1, 2, 3, 4, 5] # first element In [2]: print(my_list[0]) 1 # last element In [3]: print(my_list[-1]) 5 # range of elements In [4]: print(my_list[0:3]) [1, 2, 3] INTRODUCTION TO PYTHON FOR FINANCE
Step 2: Con v ert lists to arra y s # Convert lists to arrays import numpy as np my_array = np.array(my_list) INTRODUCTION TO PYTHON FOR FINANCE
Step 3: Element w ise arra y operations # Elementwise array operations array_ratio = array1 / array2 INTRODUCTION TO PYTHON FOR FINANCE
Let ' s anal yz e ! IN TR OD U C TION TO P YTH ON FOR FIN AN C E
A closer look at the sectors IN TR OD U C TION TO P YTH ON FOR FIN AN C E Adina Ho w e Instr u ctor
Yo u r mission GIVEN N u mp y arra y s of data describing the S & P 100: names , prices , earnings , sectors OBJECTIVE PART II E x plore and anal yz e sector - speci � c P / E ratios w ithin companies of the S & P 100 INTRODUCTION TO PYTHON FOR FINANCE
Step 1: Create a boolean filtering arra y 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: Appl y filtering arra y to s u bset another arra y 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: S u mmari z e P / E ratios Calc u late the a v erage and standard de v iation of these sector - speci � c 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 ! IN TR OD U C TION TO P YTH ON FOR FIN AN C E
Vis u ali z ing trends IN TR OD U C TION TO P YTH ON FOR FIN AN C E Adina Ho w e Instr u ctor
Yo u r mission - o u tlier ? INTRODUCTION TO PYTHON FOR FINANCE
Step 1: Make a histogram import matplotlib.pyplot as plt plt.hist(hist_data, bins = 8) plt.show() INTRODUCTION TO PYTHON FOR FINANCE
Step 2: Identif y the O u tlier Identif y the o u tlier P / E ratio Create a boolean arra y � lter to s u bset this compan y Filter o u t this compan y information from the pro v ided datasets INTRODUCTION TO PYTHON FOR FINANCE
Let ' s practice ! IN TR OD U C TION TO P YTH ON FOR FIN AN C E
Recommend
More recommend