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): async def get_data(symbol):
"""Extract specified columns data for a given symbol.""" """Extract specified columns data for a given symbol."""
columns = ['sharesOutStanding', 'sharesQoQ', 'sharesYoY','institutionalOwnership','floatShares', columns = ['sharesOutStanding', 'sharesQoQ', 'sharesYoY','institutionalOwnership','floatShares',
'peg','priceEarningsRatio','forwardPE','priceToSalesRatio','forwardPS','priceToBookRatio','priceToFreeCashFlowsRatio', 'priceEarningsToGrowthRatio','priceEarningsRatio','forwardPE','priceToSalesRatio','forwardPS','priceToBookRatio','priceToFreeCashFlowsRatio',
'sharesShort','shortOutStandingPercent','shortFloatPercent','shortRatio', 'sharesShort','shortOutStandingPercent','shortFloatPercent','shortRatio',
'enterpriseValue','evEarnings','evSales','evEBITDA','evEBIT','evFCF', 'enterpriseValue','evEarnings','evSales','evEBITDA','evEBIT','evFCF',
'currentRatio','quickRatio','debtRatio','debtEquityRatio','interestCoverage','cashFlowToDebtRatio','totalDebtToCapitalization', 'currentRatio','quickRatio','debtRatio','debtEquityRatio','interestCoverage','cashFlowToDebtRatio','totalDebtToCapitalization',
@ -37,12 +37,14 @@ async def get_data(symbol):
if symbol in stock_screener_data_dict: if symbol in stock_screener_data_dict:
result = {} result = {}
for column in columns: 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 result
return {} return {}
async def run(): async def run():
"""Main function to run the data extraction process.""" """Main function to run the data extraction process."""
# Connect to SQLite database # Connect to SQLite database

View File

@ -968,21 +968,20 @@ async def get_stock_screener(con):
try: try:
with open(f"json/analyst-estimate/{symbol}.json", 'r') as file: 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['forwardPS'] = None
item['peg'] = None #item['peg'] = None
for analyst_item in res: #for analyst_item in res:
if analyst_item['date'] == next_year and item['marketCap'] > 0 and analyst_item['estimatedRevenueAvg'] > 0: if item['marketCap'] > 0 and res['estimatedRevenueAvg'] > 0: #res['date'] == next_year and
# Calculate forwardPS: marketCap / estimatedRevenueAvg # Calculate forwardPS: marketCap / estimatedRevenueAvg
item['forwardPS'] = round(item['marketCap'] / analyst_item['estimatedRevenueAvg'], 1) item['forwardPS'] = round(item['marketCap'] / res['estimatedRevenueAvg'], 1)
if item['eps'] > 0: if item['eps'] > 0:
cagr = ((analyst_item['estimatedEpsHigh']/item['eps'] ) -1)*100 cagr = ((res['estimatedEpsAvg']/item['eps'] ) -1)*100
item['peg'] = round(item['priceEarningsRatio'] / cagr,2) if cagr > 0 else None #item['peg'] = round(item['priceEarningsRatio'] / cagr,2) if cagr > 0 else None
break # Exit the loop once the desired item is found
except: except:
item['forwardPS'] = None item['forwardPS'] = None
item['peg'] = None #item['peg'] = None
try: try:
item['halalStocks'] = get_halal_compliant(item) item['halalStocks'] = get_halal_compliant(item)
except: except: