59 lines
No EOL
2 KiB
Python
59 lines
No EOL
2 KiB
Python
import sys
|
|
sys.path.append('../group-1')
|
|
import pandas as pd
|
|
from scraper.top100_extractor import programming_crime_list
|
|
|
|
def stock_price_time_series(ticker: str):
|
|
# Read market price csv
|
|
market_prices = pd.read_csv(f'Companies_Data/{ticker}_Data/{ticker}_price_history.csv')
|
|
|
|
return market_prices
|
|
|
|
def eps_bar_chart(ticker: str):
|
|
# Read earnings csv
|
|
earnings = pd.read_csv(f'Companies_Data/{ticker}_Data/{ticker}earnings.csv')
|
|
|
|
earnings = earnings[['symbol', 'epsActual', 'quarter']]
|
|
|
|
return earnings
|
|
|
|
def concatenate_price_history():
|
|
# Declare empty dataframe
|
|
unified_price_history = pd.DataFrame()
|
|
|
|
for ticker in programming_crime_list:
|
|
prices = stock_price_time_series(ticker)
|
|
unified_price_history = pd.concat([prices, unified_price_history], ignore_index=True, axis=0)
|
|
|
|
unified_price_history.to_csv('Elaborated_Data/price_history_data.csv')
|
|
|
|
def concatenate_eps():
|
|
# Declare empty dataframe
|
|
eps_df = pd.DataFrame()
|
|
|
|
for ticker in programming_crime_list:
|
|
eps = eps_bar_chart(ticker)
|
|
eps_df = pd.concat([eps, eps_df], ignore_index=True, axis=0)
|
|
|
|
eps_df.to_csv('Elaborated_Data/eps_quarterly_bar_chart.csv')
|
|
|
|
def eps_comparison():
|
|
# Read earnings csv
|
|
eps_comp_df = pd.DataFrame()
|
|
|
|
for ticker in programming_crime_list:
|
|
earnings = pd.read_csv(f'Companies_Data/{ticker}_Data/{ticker}earnings.csv')
|
|
earnings = earnings[['symbol', 'epsActual', 'epsEstimate', 'quarter']]
|
|
earnings['epsDifferential'] = ((earnings['epsActual'] - earnings['epsEstimate']) / earnings['epsEstimate']) * 100
|
|
earnings = earnings.drop(columns=['epsActual', 'epsEstimate'])
|
|
earnings = earnings.rename(columns={'symbol': 'Ticker'})
|
|
eps_comp_df = pd.concat([eps_comp_df, earnings], ignore_index=True, axis=0)
|
|
|
|
# Save the earnings df to Elaborated_Data
|
|
eps_comp_df.to_csv(f'Elaborated_Data/eps_comparison.csv')
|
|
|
|
return earnings
|
|
if __name__ == '__main__':
|
|
concatenate_price_history()
|
|
concatenate_eps()
|
|
eps_comparison() |