HOMEWORK 2

docx

School

Illinois Institute Of Technology *

*We aren’t endorsed by this school

Course

503

Subject

Finance

Date

Apr 3, 2024

Type

docx

Pages

4

Uploaded by BarristerInternet1945

Report
Tanvi Vikas Patil CWID A20563265 MSF 503 Financial Modeling Spring, 2024 HOMEWORK 2 1.) import numpy as np def sum_range(arr, start, end): total = 0 for i in range(start, end + 1): total += arr[i] return total arr = np.array([1, 2, 3, 4, 5, 6]) start_index = 2 end_index = 4 result = sum_range(arr, start_index, end_index) Result is 12
2.) Following is the data dictionary Field name Data type Description Valid Values sym string Symbol or abbreviation used to uniquely identify a stock on a stock exchange gics string Global industry classification standard. It's a method for grouping companies into sectors and industries . FIN, IT, UTIL year int The year to which the financial data pertains. EPS float earning per share. It's a company's profit divided by its number of outstanding shares . P/B float price to book ratio. It compares a company's market value to its book value. ROE float return on equity. It measures a company's profitability by revealing how much profit a company generates with the money shareholders have invested. SPY string S&P 500 index inclusion (Y/N). This is the ticker symbol for the SPDR S&P 500 ETF, which tracks the S&P 500 stock market index. Y, N 3.) import pandas as pd data = { 'dt': ['1/1/2022', '1/2/2022', '1/3/2022', '1/4/2022', '1/5/2022', '1/6/2022', '1/7/2022', '1/8/2022', '1/9/2022', '1/10/2022', '1/10/2022', '1/11/2022', '1/12/2022', '1/13/2022', '1/14/2022'], 'd': ['S', 'U', 'M', 'T', 'W', 'R', 'F', 'S', 'U', 'M', 'M', 'T', '', 'R', 'F'], 't_fahr': [13, 19, None, 25, 26, 22, 23, 13, None, -5, -5, -2, 3, 10, 18], 'precip': ['N', 'N', None, 'Y', 'Y', None, 'N', 'N', None, 'N', 'N', 'N', None, 'N', 'Y'] } df = pd.DataFrame(data) df['t_celsius'] = (df['t_fahr'] - 32) * 5/9 df['t_celsius'] = df['t_celsius'].apply(lambda x: 0 if x < 0 else x) print(df) OR
import pandas as pd data = { 'dt': ['1/1/2022', '1/2/2022', '1/3/2022', '1/4/2022', '1/5/2022', '1/6/2022', '1/7/2022', '1/8/2022', '1/9/2022', '1/10/2022', '1/10/2022', '1/11/2022', '1/12/2022', '1/13/2022', '1/14/2022'], 'd': ['S', 'U', 'M', 'T', 'W', 'R', 'F', 'S', 'U', 'M', 'M', 'T', None, 'R', 'F'], 't_fahr': [13, 19, None, 25, 26, 22, 23, 13, None, -5, -5, -2, 3, 10, 18], 'precip': ['N', 'N', None, 'Y', 'Y', None, 'N', 'N', None, 'N', 'N', 'N', 'N', 'N', 'Y'] } df = pd.DataFrame(data) df['dt'] = pd.to_datetime(df['dt'], errors='coerce') df['d'].fillna('Unknown', inplace=True) df['t_fahr'].fillna(df['t_fahr'].mean(), inplace=True) df['t_celsius'] = (df['t_fahr'] - 32) * 5/9 print("Cleaned DataFrame:") print(df) dt d t_fahr precip t_celsiu s 1/1/2022 S 13 N -10.55 1/2/2022 U 19 N -7.22 1/3/2022 M 12 N -10.94 1/4/2022 T 25 Y -3.88 1/5/2022 W 26 Y -3.33 1/6/2022 R 22 N -5.55 1/7/2022 F 23 N -5 1/8/2022 S 13 N -10.55 1/9/2022 U 12 N -10.94 1/10/2022 M -5 N -20.55 1/10/2022 M -5 N -20.55 1/11/2022 T -2 N -18.88 1/12/2022 unknow n 3 N -16.11 1/13/2022 R 10 N -12.22 1/14/2022 F 18 Y -7.77
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help