bugfixing

This commit is contained in:
MuslemRahimi 2025-04-02 10:38:39 +02:00
parent 733cb3f8b4
commit 1eeb9556bb
2 changed files with 220 additions and 96 deletions

View File

@ -20,12 +20,12 @@ 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',
'priceEarningsToGrowthRatio','priceEarningsRatio','forwardPE','priceToSalesRatio','forwardPS','priceToBookRatio','priceToFreeCashFlowsRatio', 'priceToEarningsGrowthRatio','priceToEarningsRatio','forwardPE','priceToSalesRatio','forwardPS','priceToBookRatio','priceToFreeCashFlowRatio',
'sharesShort','shortOutStandingPercent','shortFloatPercent','shortRatio', 'sharesShort','shortOutStandingPercent','shortFloatPercent','shortRatio',
'enterpriseValue','evEarnings','evSales','evEBITDA','evEBIT','evFCF', 'enterpriseValue','evToSales','evToEBITDA','evToOperatingCashFlow','evToFreeCashFlow',
'currentRatio','quickRatio','debtRatio','debtEquityRatio','interestCoverage','cashFlowToDebtRatio','totalDebtToCapitalization', 'currentRatio','quickRatio','debtRatio','debtToEquityRatio','interestCoverageRatio','cashFlowToDebtRatio','debtToMarketCap',
'returnOnEquity','returnOnAssets','returnOnCapital','revenuePerEmployee','profitPerEmployee', 'returnOnEquity','returnOnAssets','returnOnInvestedCapital','revenuePerEmployee','profitPerEmployee',
'employees','assetTurnover','inventoryTurnover','incomeTaxExpense','effectiveTaxRate','beta','returnOnInvestedCapital', 'employees','assetTurnover','inventoryTurnover','incomeTaxExpense','effectiveTaxRate','beta',
'change1Y','sma50','sma200','rsi','avgVolume','revenue','netIncome','grossProfit','operatingIncome','ebitda','ebit','eps', 'change1Y','sma50','sma200','rsi','avgVolume','revenue','netIncome','grossProfit','operatingIncome','ebitda','ebit','eps',
'cashAndCashEquivalents','totalDebt','retainedEarnings','totalAssets','workingCapital','operatingCashFlow', 'cashAndCashEquivalents','totalDebt','retainedEarnings','totalAssets','workingCapital','operatingCashFlow',
'capitalExpenditure','freeCashFlow','freeCashFlowPerShare','grossProfitMargin','operatingProfitMargin','pretaxProfitMargin', 'capitalExpenditure','freeCashFlow','freeCashFlowPerShare','grossProfitMargin','operatingProfitMargin','pretaxProfitMargin',

View File

@ -363,62 +363,203 @@ def get_financial_statements(item, symbol):
""" """
# Define the keys to be extracted for each type of statement # Define the keys to be extracted for each type of statement
key_ratios = [ key_ratios = [
"currentRatio", "quickRatio", "cashRatio", "daysOfSalesOutstanding", "grossProfitMargin",
"daysOfInventoryOutstanding", "operatingCycle", "daysOfPayablesOutstanding", "ebitMargin",
"cashConversionCycle", "grossProfitMargin", "operatingProfitMargin", "ebitdaMargin",
"pretaxProfitMargin", "netProfitMargin", "effectiveTaxRate", "returnOnAssets", "operatingProfitMargin",
"returnOnEquity", "returnOnCapitalEmployed", "netIncomePerEBT", "ebtPerEbit", "pretaxProfitMargin",
"ebitPerRevenue", "debtRatio", "debtEquityRatio", "longTermDebtToCapitalization", "continuousOperationsProfitMargin",
"totalDebtToCapitalization", "interestCoverage", "cashFlowToDebtRatio", "netProfitMargin",
"companyEquityMultiplier", "receivablesTurnover", "payablesTurnover", "bottomLineProfitMargin",
"inventoryTurnover", "fixedAssetTurnover", "assetTurnover", "receivablesTurnover",
"operatingCashFlowPerShare", "freeCashFlowPerShare", "cashPerShare", "payoutRatio", "payablesTurnover",
"operatingCashFlowSalesRatio", "freeCashFlowOperatingCashFlowRatio", "inventoryTurnover",
"cashFlowCoverageRatios", "shortTermCoverageRatios", "capitalExpenditureCoverageRatio", "fixedAssetTurnover",
"dividendPaidAndCapexCoverageRatio", "dividendPayoutRatio", "priceBookValueRatio", "assetTurnover",
"priceToBookRatio", "priceToSalesRatio", "priceEarningsRatio", "priceToFreeCashFlowsRatio", "currentRatio",
"priceToOperatingCashFlowsRatio", "priceCashFlowRatio", "priceEarningsToGrowthRatio", "quickRatio",
"priceSalesRatio", "dividendYield", "enterpriseValueMultiple", "priceFairValue" "solvencyRatio",
] "cashRatio",
"priceToEarningsRatio",
key_cash_flow = [ "priceToEarningsGrowthRatio",
"netIncome", "depreciationAndAmortization", "deferredIncomeTax", "stockBasedCompensation", "forwardPriceToEarningsGrowthRatio",
"changeInWorkingCapital", "accountsReceivables", "inventory", "accountsPayables", "priceToBookRatio",
"otherWorkingCapital", "otherNonCashItems", "netCashProvidedByOperatingActivities", "priceToSalesRatio",
"investmentsInPropertyPlantAndEquipment", "acquisitionsNet", "purchasesOfInvestments", "priceToFreeCashFlowRatio",
"salesMaturitiesOfInvestments", "otherInvestingActivites", "netCashUsedForInvestingActivites", "priceToOperatingCashFlowRatio",
"debtRepayment", "commonStockIssued", "commonStockRepurchased", "dividendsPaid", "debtToAssetsRatio",
"otherFinancingActivites", "netCashUsedProvidedByFinancingActivities", "effectOfForexChangesOnCash", "debtToEquityRatio",
"netChangeInCash", "cashAtEndOfPeriod", "cashAtBeginningOfPeriod", "operatingCashFlow", "debtToCapitalRatio",
"capitalExpenditure", "freeCashFlow" "longTermDebtToCapitalRatio",
"financialLeverageRatio",
"workingCapitalTurnoverRatio",
"operatingCashFlowRatio",
"operatingCashFlowSalesRatio",
"freeCashFlowOperatingCashFlowRatio",
"debtServiceCoverageRatio",
"interestCoverageRatio",
"shortTermOperatingCashFlowCoverageRatio",
"operatingCashFlowCoverageRatio",
"capitalExpenditureCoverageRatio",
"dividendPaidAndCapexCoverageRatio",
"dividendPayoutRatio",
"dividendYield",
"dividendYieldPercentage",
"revenuePerShare",
"netIncomePerShare",
"interestDebtPerShare",
"cashPerShare",
"bookValuePerShare",
"tangibleBookValuePerShare",
"shareholdersEquityPerShare",
"operatingCashFlowPerShare",
"capexPerShare",
"freeCashFlowPerShare",
"netIncomePerEBT",
"ebtPerEbit",
"priceToFairValue",
"debtToMarketCap",
"effectiveTaxRate",
"enterpriseValueMultiple",
"dividendPerShare"
] ]
key_cash_flow = [
"netIncome",
"depreciationAndAmortization",
"deferredIncomeTax",
"stockBasedCompensation",
"changeInWorkingCapital",
"accountsReceivables",
"inventory",
"accountsPayables",
"otherWorkingCapital",
"otherNonCashItems",
"netCashProvidedByOperatingActivities",
"investmentsInPropertyPlantAndEquipment",
"acquisitionsNet",
"purchasesOfInvestments",
"salesMaturitiesOfInvestments",
"otherInvestingActivities",
"netCashProvidedByInvestingActivities",
"netDebtIssuance",
"longTermNetDebtIssuance",
"shortTermNetDebtIssuance",
"netStockIssuance",
"netCommonStockIssuance",
"commonStockIssuance",
"commonStockRepurchased",
"netPreferredStockIssuance",
"netDividendsPaid",
"commonDividendsPaid",
"preferredDividendsPaid",
"otherFinancingActivities",
"netCashProvidedByFinancingActivities",
"effectOfForexChangesOnCash",
"netChangeInCash",
"cashAtEndOfPeriod",
"cashAtBeginningOfPeriod",
"operatingCashFlow",
"capitalExpenditure",
"freeCashFlow",
"incomeTaxesPaid",
"interestPaid"
]
key_income = [ key_income = [
"revenue", "costOfRevenue", "grossProfit", "grossProfitRatio", "revenue",
"researchAndDevelopmentExpenses", "generalAndAdministrativeExpenses", "sellingAndMarketingExpenses", "costOfRevenue",
"sellingGeneralAndAdministrativeExpenses", "otherExpenses", "operatingExpenses", "grossProfit",
"costAndExpenses", "interestIncome", "interestExpense", "depreciationAndAmortization", "researchAndDevelopmentExpenses",
"ebitda", "ebitdaratio", "operatingIncome", "operatingIncomeRatio", "generalAndAdministrativeExpenses",
"totalOtherIncomeExpensesNet", "incomeBeforeTax", "incomeBeforeTaxRatio", "incomeTaxExpense", "sellingAndMarketingExpenses",
"netIncome", "netIncomeRatio", "eps", "epsdiluted", "weightedAverageShsOut", "sellingGeneralAndAdministrativeExpenses",
"otherExpenses",
"operatingExpenses",
"costAndExpenses",
"netInterestIncome",
"interestIncome",
"interestExpense",
"depreciationAndAmortization",
"ebitda",
"ebit",
"nonOperatingIncomeExcludingInterest",
"operatingIncome",
"totalOtherIncomeExpensesNet",
"incomeBeforeTax",
"incomeTaxExpense",
"netIncomeFromContinuingOperations",
"netIncomeFromDiscontinuedOperations",
"otherAdjustmentsToNetIncome",
"netIncome",
"netIncomeDeductions",
"bottomLineNetIncome",
"eps",
"epsDiluted",
"weightedAverageShsOut",
"weightedAverageShsOutDil" "weightedAverageShsOutDil"
] ]
key_balance_sheet = [ key_balance_sheet = [
"cashAndCashEquivalents", "shortTermInvestments", "cashAndShortTermInvestments", "cashAndCashEquivalents",
"netReceivables", "inventory", "otherCurrentAssets", "totalCurrentAssets", "shortTermInvestments",
"propertyPlantEquipmentNet", "goodwill", "intangibleAssets", "goodwillAndIntangibleAssets", "cashAndShortTermInvestments",
"longTermInvestments", "taxAssets", "otherNonCurrentAssets", "totalNonCurrentAssets", "netReceivables",
"otherAssets", "totalAssets", "accountPayables", "shortTermDebt", "taxPayables", "accountsReceivables",
"deferredRevenue", "otherCurrentLiabilities", "totalCurrentLiabilities", "longTermDebt", "otherReceivables",
"deferredRevenueNonCurrent", "deferredTaxLiabilitiesNonCurrent", "otherNonCurrentLiabilities", "inventory",
"totalNonCurrentLiabilities", "otherLiabilities", "capitalLeaseObligations", "totalLiabilities", "prepaids",
"preferredStock", "commonStock", "retainedEarnings", "accumulatedOtherComprehensiveIncomeLoss", "otherCurrentAssets",
"othertotalStockholdersEquity", "totalStockholdersEquity", "totalEquity", "totalCurrentAssets",
"totalLiabilitiesAndStockholdersEquity", "minorityInterest", "totalLiabilitiesAndTotalEquity", "propertyPlantEquipmentNet",
"totalInvestments", "totalDebt", "netDebt" "goodwill",
"intangibleAssets",
"goodwillAndIntangibleAssets",
"longTermInvestments",
"taxAssets",
"otherNonCurrentAssets",
"totalNonCurrentAssets",
"otherAssets",
"totalAssets",
"totalPayables",
"accountPayables",
"otherPayables",
"accruedExpenses",
"shortTermDebt",
"capitalLeaseObligationsCurrent",
"taxPayables",
"deferredRevenue",
"otherCurrentLiabilities",
"totalCurrentLiabilities",
"longTermDebt",
"capitalLeaseObligationsNonCurrent",
"deferredRevenueNonCurrent",
"deferredTaxLiabilitiesNonCurrent",
"otherNonCurrentLiabilities",
"totalNonCurrentLiabilities",
"otherLiabilities",
"capitalLeaseObligations",
"totalLiabilities",
"treasuryStock",
"preferredStock",
"commonStock",
"retainedEarnings",
"additionalPaidInCapital",
"accumulatedOtherComprehensiveIncomeLoss",
"otherTotalStockholdersEquity",
"totalStockholdersEquity",
"totalEquity",
"minorityInterest",
"totalLiabilitiesAndTotalEquity",
"totalInvestments",
"totalDebt",
"netDebt"
] ]
key_income_growth = [ key_income_growth = [
"growthRevenue", "growthRevenue",
"growthCostOfRevenue", "growthCostOfRevenue",
@ -543,14 +684,7 @@ def get_financial_statements(item, symbol):
item['freeCashFlowMargin'] = round((item['freeCashFlow'] / item['revenue']) * 100,2) item['freeCashFlowMargin'] = round((item['freeCashFlow'] / item['revenue']) * 100,2)
except: except:
item['freeCashFlowMargin'] = None item['freeCashFlowMargin'] = None
try:
item['earningsYield'] = round((item['eps'] / item['price']) * 100,2)
except:
item['earningsYield'] = None
try:
item['freeCashFlowYield'] = round((item['freeCashFlow'] / item['marketCap']) * 100,2)
except:
item['freeCashFlowYield'] = None
try: try:
item['ebitdaMargin'] = round((item['ebitda'] / item['revenue']) * 100,2) item['ebitdaMargin'] = round((item['ebitda'] / item['revenue']) * 100,2)
except: except:
@ -563,13 +697,6 @@ def get_financial_statements(item, symbol):
item['profitPerEmployee'] = round((item['netIncome'] / item['employees']),2) item['profitPerEmployee'] = round((item['netIncome'] / item['employees']),2)
except: except:
item['profitPerEmployee'] = None item['profitPerEmployee'] = None
try:
tax_rate = item['incomeTaxExpense'] / item['incomeBeforeTax'] if item['incomeBeforeTax'] != 0 else 0
nopat = item['operatingIncome'] * (1 - tax_rate)
invested_capital = item['totalDebt'] + item['totalEquity']
item['returnOnInvestedCapital'] = round((nopat / invested_capital)*100,2) if invested_capital != 0 else None
except:
item['returnOnInvestedCapital'] = None
try: try:
item['researchDevelopmentRevenueRatio'] = round((item['researchAndDevelopmentExpenses'] / item['revenue']) * 100,2) item['researchDevelopmentRevenueRatio'] = round((item['researchAndDevelopmentExpenses'] / item['revenue']) * 100,2)
except: except:
@ -584,11 +711,9 @@ def get_financial_statements(item, symbol):
item['interestIncomeToCapitalization'] = None item['interestIncomeToCapitalization'] = None
try: try:
item['ebit'] = item['operatingIncome']
item['operatingMargin'] = round((item['operatingIncome'] / item['revenue']) * 100,2) item['operatingMargin'] = round((item['operatingIncome'] / item['revenue']) * 100,2)
item['ebitMargin'] = item['operatingMargin'] item['ebitMargin'] = item['operatingMargin']
except: except:
item['ebit'] = None
item['operatingMargin'] = None item['operatingMargin'] = None
item['ebitMargin'] = None item['ebitMargin'] = None
@ -800,23 +925,6 @@ async def get_stock_screener(con):
item['var'] = None item['var'] = None
try:
with open(f"json/enterprise-values/{symbol}.json", 'r') as file:
ev = orjson.loads(file.read())[-1]['enterpriseValue']
item['enterpriseValue'] = ev
item['evSales'] = round(ev / item['revenue'],2)
item['evEarnings'] = round(ev / item['netIncome'],2)
item['evEBITDA'] = round(ev / item['ebitda'],2)
item['evEBIT'] = round(ev / item['ebit'],2)
item['evFCF'] = round(ev / item['freeCashFlow'],2)
except:
item['enterpriseValue'] = None
item['evSales'] = None
item['evEarnings'] = None
item['evEBITDA'] = None
item['evEBIT'] = None
item['evFCF'] = None
try: try:
with open(f"json/analyst/summary/all_analyst/{symbol}.json", 'r') as file: with open(f"json/analyst/summary/all_analyst/{symbol}.json", 'r') as file:
@ -870,21 +978,37 @@ async def get_stock_screener(con):
try: try:
with open(f"json/financial-statements/key-metrics/annual/{symbol}.json", 'r') as file: with open(f"json/financial-statements/key-metrics/annual/{symbol}.json", 'r') as file:
res = orjson.loads(file.read())[0] res = orjson.loads(file.read())[0]
item['revenuePerShare'] = round(res['revenuePerShare'],2) item['returnOnEquity'] = round(res['returnOnEquity'],2)
item['netIncomePerShare'] = round(res['netIncomePerShare'],2) item['returnOnInvestedCapital'] = round(res['returnOnInvestedCapital'],2)
item['shareholdersEquityPerShare'] = round(res['shareholdersEquityPerShare'],2) item['returnOnAssets'] = round(res['returnOnAssets'],2)
item['interestDebtPerShare'] = round(res['interestDebtPerShare'],2)
item['capexPerShare'] = round(res['capexPerShare'],2) item['earningsYield'] = round(res['earningsYield'],2)
item['freeCashFlowYield'] = round(res['freeCashFlowYield'],2)
item['enterpriseValue'] = res['enterpriseValue']
item['evToSales'] = round(res['evToSales'],2)
item['evToOperatingCashFlow'] = round(res['evToOperatingCashFlow'],2)
item['evToFreeCashFlow'] = round(res['evToFreeCashFlow'],2)
item['evToEBITDA'] = round(res['evToEBITDA'],2)
item['tangibleAssetValue'] = round(res['tangibleAssetValue'],2) item['tangibleAssetValue'] = round(res['tangibleAssetValue'],2)
item['returnOnTangibleAssets'] = round(res['returnOnTangibleAssets'],2) item['returnOnTangibleAssets'] = round(res['returnOnTangibleAssets'],2)
item['grahamNumber'] = round(res['grahamNumber'],2) item['grahamNumber'] = round(res['grahamNumber'],2)
except: except:
item['revenuePerShare'] = None item['returnOnEquity'] = None
item['netIncomePerShare'] = None item['returnOnInvestedCapital'] = None
item['shareholdersEquityPerShare'] = None item['returnOnAssets'] = None
item['interestDebtPerShare'] = None item['earningsYield'] = None
item['capexPerShare'] = None item['freeCashFlowYield'] = None
item['enterpriseValue'] = None
item['evToSales'] = None
item['evToOperatingCashFlow'] = None
item['evToFreeCashFlow'] = None
item['evToEBITDA'] = None
item['tangibleAssetValue'] = None item['tangibleAssetValue'] = None
item['returnOnTangibleAssets'] = None item['returnOnTangibleAssets'] = None
item['grahamNumber'] = None item['grahamNumber'] = None