2023-05-10 11:55:07 +00:00
|
|
|
import pandas as pd
|
|
|
|
|
|
|
|
def get_peg(ticker: str):
|
|
|
|
# Read current ratios .csv
|
|
|
|
current_ratios = pd.read_csv(f'Companies_Data/{ticker}_Data/{ticker}_current_ratios.csv', index_col=[0])
|
|
|
|
|
|
|
|
# Convert Object to DateTime
|
|
|
|
current_ratios['asOfDate'] = pd.to_datetime(current_ratios['asOfDate'])
|
|
|
|
|
|
|
|
# Sorting per Date
|
|
|
|
current_ratios = current_ratios.sort_values('asOfDate', ascending=False)
|
|
|
|
|
|
|
|
# Drop NaN pandas values
|
|
|
|
current_ratios = current_ratios.dropna()
|
|
|
|
|
|
|
|
# Take first value (the last peg ratio)
|
|
|
|
peg_ratio = current_ratios['PegRatio'][:1]
|
|
|
|
|
|
|
|
return peg_ratio.values[0]
|
|
|
|
|
|
|
|
def get_financial_health(ticker: str):
|
|
|
|
# Read balance sheet .csv
|
|
|
|
balance_sheet = pd.read_csv(f'Companies_Data/{ticker}_Data/{ticker}_balance_sheet_4Y+4Q.csv', index_col=[0])
|
|
|
|
|
|
|
|
# Convert Object to DateTime
|
|
|
|
balance_sheet['asOfDate'] = pd.to_datetime(balance_sheet['asOfDate'])
|
|
|
|
|
|
|
|
# Sorting per Date
|
|
|
|
balance_sheet = balance_sheet.sort_values('asOfDate', ascending=False)
|
|
|
|
|
|
|
|
# Drop NaN pandas values
|
|
|
|
balance_sheet = balance_sheet.dropna()
|
|
|
|
|
|
|
|
# Create financial health column
|
|
|
|
balance_sheet['financial_health'] = balance_sheet['TotalDebt'] / balance_sheet['TotalAssets']
|
|
|
|
|
|
|
|
# Get financial health
|
|
|
|
financial_health = balance_sheet['financial_health'][:1]
|
|
|
|
|
|
|
|
return financial_health.values[0]
|
|
|
|
|
|
|
|
def estimated_growth(ticker: str):
|
2023-05-13 14:52:31 +00:00
|
|
|
# Read 5 years growth estimates
|
2023-05-10 11:55:07 +00:00
|
|
|
growth_estimated = pd.read_csv(f'Companies_Data/{ticker}_Data/{ticker}5YGrowthEstimates.csv', index_col=[0])['5Y Growth estimate'].values[0]
|
|
|
|
|
|
|
|
return growth_estimated
|
|
|
|
|
2023-05-13 14:52:31 +00:00
|
|
|
def past_performance_earnings(ticker: str):
|
|
|
|
# Read earnings csv
|
|
|
|
earnings = pd.read_csv(f'Companies_Data/{ticker}_Data/{ticker}earnings.csv', index_col=[0])
|
|
|
|
|
|
|
|
# Performance
|
|
|
|
performance_index = round((earnings['epsActual'].sum() - earnings['epsEstimate'].sum()) / earnings['epsEstimate'].sum() * 100, 2)
|
|
|
|
|
|
|
|
return performance_index
|
|
|
|
|
2023-05-10 11:55:07 +00:00
|
|
|
if __name__ == '__main__':
|
2023-05-13 14:52:31 +00:00
|
|
|
print(get_peg('GOOGL')) # < 1 (GREEN); > 1 (RED); = 1 (ORANGE)
|
|
|
|
print(get_financial_health('GOOGL')) # < 1 (GREEN); > 1 (RED); = 1 (ORANGE)
|
|
|
|
print(estimated_growth('GOOGL')) # < 0 (RED); 0 < x < 8% (ORANGE); < 8 % (GREEN)
|
|
|
|
print(past_performance_earnings('GOOGL'), "%") # -100 < x < 0 (RED); = 0 (ORANGE); 0 < x < 100 (GREEN)
|
2023-05-10 11:55:07 +00:00
|
|
|
|