bugfixing
This commit is contained in:
parent
f694ec6dc1
commit
0bb4ea6903
@ -54,22 +54,13 @@ async def save_json(symbol, period, data_type, data):
|
||||
with open(f"json/financial-statements/{data_type}/{period}/{symbol}.json", 'w') as file:
|
||||
ujson.dump(data, file)
|
||||
|
||||
async def calculate_margins(symbol):
|
||||
async def add_ratio_elements(symbol):
|
||||
for period in ['annual', 'quarter']:
|
||||
try:
|
||||
# Load income statement data
|
||||
income_path = f"json/financial-statements/income-statement/{period}/{symbol}.json"
|
||||
with open(income_path, "r") as file:
|
||||
income_data = ujson.load(file)
|
||||
|
||||
# Load cash flow statement data
|
||||
cash_flow_path = f"json/financial-statements/cash-flow-statement/{period}/{symbol}.json"
|
||||
with open(cash_flow_path, "r") as file:
|
||||
cash_flow_data = ujson.load(file)
|
||||
|
||||
# Load key-metrics data
|
||||
cash_flow_path = f"json/financial-statements/key-metrics/{period}/{symbol}.json"
|
||||
with open(cash_flow_path, "r") as file:
|
||||
key_metrics_path = f"json/financial-statements/key-metrics/{period}/{symbol}.json"
|
||||
with open(key_metrics_path, "r") as file:
|
||||
key_metrics_data = ujson.load(file)
|
||||
|
||||
# Load ratios data
|
||||
@ -78,11 +69,8 @@ async def calculate_margins(symbol):
|
||||
ratio_data = ujson.load(file)
|
||||
|
||||
if income_data and cash_flow_data and ratio_data and key_metrics_data:
|
||||
for ratio_item, income_item, cash_flow_item, key_metrics_item in zip(ratio_data, income_data, cash_flow_data, key_metrics_data):
|
||||
for ratio_item, key_metrics_item in zip(ratio_data,key_metrics_data):
|
||||
try:
|
||||
revenue = income_item.get('revenue', 0)
|
||||
ebitda = income_item.get('ebitda', 0)
|
||||
free_cash_flow = cash_flow_item.get('freeCashFlow', 0)
|
||||
ratio_item['returnOnEquity'] = round(key_metrics_item.get('returnOnEquity',0),2)
|
||||
ratio_item['returnOnAssets'] = round(key_metrics_item.get('returnOnAssets',0),2)
|
||||
ratio_item['returnOnInvestedCapital'] = round(key_metrics_item.get('returnOnInvestedCapital',0),2)
|
||||
@ -92,10 +80,6 @@ async def calculate_margins(symbol):
|
||||
ratio_item['earningsYield'] = round(key_metrics_item.get('earningsYield',0),2)
|
||||
ratio_item['freeCashFlowYield'] = round(key_metrics_item.get('freeCashFlowYield',0),2)
|
||||
|
||||
if revenue != 0:
|
||||
ratio_item['freeCashFlowMargin'] = round((free_cash_flow / revenue) * 100, 2)
|
||||
else:
|
||||
ratio_item['freeCashFlowMargin'] = None
|
||||
except:
|
||||
pass
|
||||
|
||||
@ -141,7 +125,7 @@ async def get_financial_statements(session, symbol, semaphore, rate_limiter):
|
||||
await save_json(symbol, 'quarter', 'owner-earnings', owner_earnings_data)
|
||||
|
||||
|
||||
await calculate_margins(symbol)
|
||||
await add_ratio_elements(symbol)
|
||||
|
||||
async def run():
|
||||
con = sqlite3.connect('stocks.db')
|
||||
|
||||
@ -23,7 +23,7 @@ async def get_data(symbol):
|
||||
'priceToEarningsGrowthRatio','priceToEarningsRatio','forwardPE','priceToSalesRatio','forwardPS','priceToBookRatio','priceToFreeCashFlowRatio',
|
||||
'sharesShort','shortOutStandingPercent','shortFloatPercent','shortRatio',
|
||||
'enterpriseValue','evToSales','evToEBITDA','evToOperatingCashFlow','evToFreeCashFlow',
|
||||
'currentRatio','quickRatio','debtRatio','debtToEquityRatio','interestCoverageRatio','cashFlowToDebtRatio','debtToMarketCap',
|
||||
'currentRatio','quickRatio','debtToFreeCashFlowRatio','debtToEBITDARatio','debtToEquityRatio','interestCoverageRatio','cashFlowToDebtRatio','debtToMarketCap',
|
||||
'returnOnEquity','returnOnAssets','returnOnInvestedCapital','revenuePerEmployee','profitPerEmployee',
|
||||
'employees','assetTurnover','inventoryTurnover','incomeTaxExpense','effectiveTaxRate','beta',
|
||||
'change1Y','sma50','sma200','rsi','avgVolume','revenue','netIncome','grossProfit','operatingIncome','ebitda','ebit','eps',
|
||||
|
||||
@ -333,7 +333,7 @@ def process_financial_data(file_path, key_list):
|
||||
if key in res:
|
||||
try:
|
||||
value = float(res[key])
|
||||
if 'growth' in file_path or key in ['longTermDebtToCapitalization','totalDebtToCapitalization']:
|
||||
if 'growth' in file_path or key in ['effectiveTaxRate','grossProfitMargin','freeCashFlowMargin',"ebitMargin","ebitdaMargin","netProfitMargin","operatingProfitMargin","pretaxProfitMargin"]:
|
||||
value = value*100 # Multiply by 100 for percentage
|
||||
|
||||
data[key] = round(value, 2) if value is not None else None
|
||||
@ -686,9 +686,13 @@ def get_financial_statements(item, symbol):
|
||||
item['freeCashFlowMargin'] = None
|
||||
|
||||
try:
|
||||
item['ebitdaMargin'] = round((item['ebitda'] / item['revenue']) * 100,2)
|
||||
item['debtToFreeCashFlowRatio'] = round((item['totalDebt'] / item['freeCashFlow']),2)
|
||||
except:
|
||||
item['ebitdaMargin'] = None
|
||||
item['debtToFreeCashFlowRatio'] = None
|
||||
try:
|
||||
item['debtToEBITDARatio'] = round((item['totalDebt'] / item['ebitda']),2)
|
||||
except:
|
||||
item['debtToEBITDARatio'] = None
|
||||
try:
|
||||
item['revenuePerEmployee'] = round((item['revenue'] / item['employees']),2)
|
||||
except:
|
||||
@ -978,12 +982,13 @@ async def get_stock_screener(con):
|
||||
try:
|
||||
with open(f"json/financial-statements/key-metrics/annual/{symbol}.json", 'r') as file:
|
||||
res = orjson.loads(file.read())[0]
|
||||
item['returnOnEquity'] = round(res['returnOnEquity'],2)
|
||||
item['returnOnInvestedCapital'] = round(res['returnOnInvestedCapital'],2)
|
||||
item['returnOnAssets'] = round(res['returnOnAssets'],2)
|
||||
item['returnOnEquity'] = round(res['returnOnEquity']*100,2)
|
||||
item['returnOnInvestedCapital'] = round(res['returnOnInvestedCapital']*100,2)
|
||||
item['returnOnCapitalEmployed'] = round(res['returnOnCapitalEmployed']*100,2)
|
||||
item['returnOnAssets'] = round(res['returnOnAssets']*100,2)
|
||||
|
||||
item['earningsYield'] = round(res['earningsYield'],2)
|
||||
item['freeCashFlowYield'] = round(res['freeCashFlowYield'],2)
|
||||
item['earningsYield'] = round(res['earningsYield']*100,2)
|
||||
item['freeCashFlowYield'] = round(res['freeCashFlowYield']*100,2)
|
||||
|
||||
item['enterpriseValue'] = res['enterpriseValue']
|
||||
item['evToSales'] = round(res['evToSales'],2)
|
||||
@ -1001,6 +1006,7 @@ async def get_stock_screener(con):
|
||||
except:
|
||||
item['returnOnEquity'] = None
|
||||
item['returnOnInvestedCapital'] = None
|
||||
item['returnOnCapitalEmployed'] = None
|
||||
item['returnOnAssets'] = None
|
||||
item['earningsYield'] = None
|
||||
item['freeCashFlowYield'] = None
|
||||
@ -1131,10 +1137,12 @@ async def get_stock_screener(con):
|
||||
item['forwardPS'] = None
|
||||
#item['peg'] = None
|
||||
|
||||
'''
|
||||
try:
|
||||
item['halalStocks'] = get_halal_compliant(item)
|
||||
except:
|
||||
item['halalStocks'] = None
|
||||
'''
|
||||
|
||||
try:
|
||||
with open(f"json/financial-statements/income-statement/annual/{symbol}.json", "r") as file:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user