update peg ratio

This commit is contained in:
MuslemRahimi 2025-02-15 11:17:21 +01:00
parent 82360fa11c
commit 7cf63dd536
2 changed files with 16 additions and 15 deletions

View File

@ -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

View File

@ -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: