56 lines
1.8 KiB
Python
56 lines
1.8 KiB
Python
|
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):
|
||
|
|
||
|
# Read 5 years growth estimates
|
||
|
growth_estimated = pd.read_csv(f'Companies_Data/{ticker}_Data/{ticker}5YGrowthEstimates.csv', index_col=[0])['5Y Growth estimate'].values[0]
|
||
|
|
||
|
return growth_estimated
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
print(get_peg('MCD')) # < 1 (GREEN); > 1 (RED); = 1 (ORANGE)
|
||
|
print(get_financial_health('MCD')) # < 1 (GREEN); > 1 (RED); = 1 (ORANGE)
|
||
|
print(estimated_growth('MCD')) # < 0 (RED); 0 < x < 8% (ORANGE); < 8 % (GREEN)
|
||
|
|