From 7cf63dd5368220cfeaee03f7c3225dfb13173d81 Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Sat, 15 Feb 2025 11:17:21 +0100 Subject: [PATCH] update peg ratio --- app/cron_statistics.py | 8 +++++--- app/restart_json.py | 23 +++++++++++------------ 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/app/cron_statistics.py b/app/cron_statistics.py index c3d396e..63428fc 100644 --- a/app/cron_statistics.py +++ b/app/cron_statistics.py @@ -20,7 +20,7 @@ async def save_json(symbol, data): async def get_data(symbol): """Extract specified columns data for a given symbol.""" columns = ['sharesOutStanding', 'sharesQoQ', 'sharesYoY','institutionalOwnership','floatShares', - 'peg','priceEarningsRatio','forwardPE','priceToSalesRatio','forwardPS','priceToBookRatio','priceToFreeCashFlowsRatio', + 'priceEarningsToGrowthRatio','priceEarningsRatio','forwardPE','priceToSalesRatio','forwardPS','priceToBookRatio','priceToFreeCashFlowsRatio', 'sharesShort','shortOutStandingPercent','shortFloatPercent','shortRatio', 'enterpriseValue','evEarnings','evSales','evEBITDA','evEBIT','evFCF', 'currentRatio','quickRatio','debtRatio','debtEquityRatio','interestCoverage','cashFlowToDebtRatio','totalDebtToCapitalization', @@ -37,12 +37,14 @@ async def get_data(symbol): if symbol in stock_screener_data_dict: result = {} for column in columns: - result[column] = stock_screener_data_dict[symbol].get(column, None) + try: + result[column] = stock_screener_data_dict[symbol].get(column, None) + except: + pass return result return {} - async def run(): """Main function to run the data extraction process.""" # Connect to SQLite database diff --git a/app/restart_json.py b/app/restart_json.py index b78f116..58d7ea3 100755 --- a/app/restart_json.py +++ b/app/restart_json.py @@ -968,21 +968,20 @@ async def get_stock_screener(con): try: with open(f"json/analyst-estimate/{symbol}.json", 'r') as file: - res = orjson.loads(file.read()) + res = orjson.loads(file.read())[-1] item['forwardPS'] = None - item['peg'] = None - for analyst_item in res: - if analyst_item['date'] == next_year and item['marketCap'] > 0 and analyst_item['estimatedRevenueAvg'] > 0: - # Calculate forwardPS: marketCap / estimatedRevenueAvg - item['forwardPS'] = round(item['marketCap'] / analyst_item['estimatedRevenueAvg'], 1) - if item['eps'] > 0: - cagr = ((analyst_item['estimatedEpsHigh']/item['eps'] ) -1)*100 - item['peg'] = round(item['priceEarningsRatio'] / cagr,2) if cagr > 0 else None - break # Exit the loop once the desired item is found + #item['peg'] = None + #for analyst_item in res: + if item['marketCap'] > 0 and res['estimatedRevenueAvg'] > 0: #res['date'] == next_year and + # Calculate forwardPS: marketCap / estimatedRevenueAvg + item['forwardPS'] = round(item['marketCap'] / res['estimatedRevenueAvg'], 1) + if item['eps'] > 0: + cagr = ((res['estimatedEpsAvg']/item['eps'] ) -1)*100 + #item['peg'] = round(item['priceEarningsRatio'] / cagr,2) if cagr > 0 else None except: item['forwardPS'] = None - item['peg'] = None - + #item['peg'] = None + try: item['halalStocks'] = get_halal_compliant(item) except: