From 26b1b94e3be90500aa1bb22ab1f11cf34694565c Mon Sep 17 00:00:00 2001 From: Pietro Rodolfo Masera Date: Wed, 10 May 2023 13:55:07 +0200 Subject: [PATCH] Indexer con peg ratio, financial health, estimated_growth, manca past_performance --- indexer/indexer.py | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 indexer/indexer.py diff --git a/indexer/indexer.py b/indexer/indexer.py new file mode 100644 index 0000000..059042a --- /dev/null +++ b/indexer/indexer.py @@ -0,0 +1,55 @@ +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) +