update stock screener
This commit is contained in:
parent
055d6b61fb
commit
32c82ec0cb
@ -19,6 +19,7 @@ from collections import Counter
|
||||
import re
|
||||
import hashlib
|
||||
import glob
|
||||
from tqdm import tqdm
|
||||
|
||||
from dotenv import load_dotenv
|
||||
import os
|
||||
@ -59,6 +60,7 @@ async def get_stock_screener(con,symbols):
|
||||
cursor.execute("PRAGMA journal_mode = wal")
|
||||
|
||||
#Stock Screener Data
|
||||
|
||||
cursor.execute("SELECT symbol, name, avgVolume, change_1W, change_1M, change_3M, change_6M, change_1Y, change_3Y, sma_50, sma_200, ema_50, ema_200, rsi, atr, stoch_rsi, mfi, cci, priceToSalesRatio, priceToBookRatio, eps, pe, ESGScore, marketCap, revenue, netIncome, grossProfit, costOfRevenue, costAndExpenses, interestIncome, interestExpense, researchAndDevelopmentExpenses, ebitda, operatingExpenses, operatingIncome, growthRevenue, growthNetIncome, growthGrossProfit, growthCostOfRevenue, growthCostAndExpenses, growthInterestExpense, growthResearchAndDevelopmentExpenses, growthEBITDA, growthEPS, growthOperatingExpenses, growthOperatingIncome, beta FROM stocks WHERE eps IS NOT NULL AND revenue IS NOT NULL AND marketCap IS NOT NULL AND beta IS NOT NULL")
|
||||
raw_data = cursor.fetchall()
|
||||
stock_screener_data = [{
|
||||
@ -109,7 +111,7 @@ async def get_stock_screener(con,symbols):
|
||||
'growthOperatingExpenses': growthOperatingExpenses,
|
||||
'growthOperatingIncome': growthOperatingIncome,
|
||||
'beta': beta,
|
||||
} for (symbol, name, avgVolume, change_1W, change_1M, change_3M, change_6M, change_1Y, change_3Y, sma_50, sma_200, ema_50, ema_200, rsi, atr, stoch_rsi, mfi, cci, priceToSalesRatio, priceToBookRatio, eps, pe, ESGScore, marketCap, revenue, netIncome, grossProfit,costOfRevenue, costAndExpenses, interestIncome, interestExpense, researchAndDevelopmentExpenses, ebitda, operatingExpenses, operatingIncome, growthRevenue, growthNetIncome, growthGrossProfit, growthCostOfRevenue, growthCostAndExpenses, growthInterestExpense, growthResearchAndDevelopmentExpenses, growthEBITDA, growthEPS, growthOperatingExpenses, growthOperatingIncome, beta) in raw_data if name != 'SP 500']
|
||||
} for (symbol, name, avgVolume, change_1W, change_1M, change_3M, change_6M, change_1Y, change_3Y, sma_50, sma_200, ema_50, ema_200, rsi, atr, stoch_rsi, mfi, cci, priceToSalesRatio, priceToBookRatio, eps, pe, ESGScore, marketCap, revenue, netIncome, grossProfit,costOfRevenue, costAndExpenses, interestIncome, interestExpense, researchAndDevelopmentExpenses, ebitda, operatingExpenses, operatingIncome, growthRevenue, growthNetIncome, growthGrossProfit, growthCostOfRevenue, growthCostAndExpenses, growthInterestExpense, growthResearchAndDevelopmentExpenses, growthEBITDA, growthEPS, growthOperatingExpenses, growthOperatingIncome, beta) in raw_data]
|
||||
|
||||
stock_screener_data = [{k: round(v, 2) if isinstance(v, (int, float)) else v for k, v in entry.items()} for entry in stock_screener_data]
|
||||
|
||||
@ -126,12 +128,14 @@ async def get_stock_screener(con,symbols):
|
||||
# Create a dictionary to map symbols to 'price' and 'changesPercentage' from stocks_data
|
||||
stocks_data_map = {entry['symbol']: (entry['price'], entry['changesPercentage']) for entry in stocks_data}
|
||||
|
||||
|
||||
# Iterate through stock_screener_data and update 'price' and 'changesPercentage' if symbols match
|
||||
# Add VaR value to stock screener
|
||||
for item in stock_screener_data:
|
||||
for item in tqdm(stock_screener_data):
|
||||
symbol = item['symbol']
|
||||
if symbol in stocks_data_map:
|
||||
item['price'], item['changesPercentage'] = stocks_data_map[symbol]
|
||||
|
||||
try:
|
||||
with open(f"json/var/{symbol}.json", 'r') as file:
|
||||
item['var'] = ujson.load(file)['var']
|
||||
@ -153,6 +157,27 @@ async def get_stock_screener(con,symbols):
|
||||
item['ratingRecommendation'] = None
|
||||
|
||||
|
||||
try:
|
||||
with open(f"json/trend-analysis/{symbol}.json", 'r') as file:
|
||||
res = ujson.load(file)[-1]
|
||||
if abs(res['accuracy'] - res['precision']) <=15:
|
||||
item['trendAnalysis'] = {"accuracy": res['accuracy'], 'sentiment': res['sentiment']}
|
||||
else:
|
||||
item['trendAnalysis'] = {"accuracy": None, "sentiment": None}
|
||||
except:
|
||||
item['trendAnalysis'] = {"accuracy": None, "sentiment": None}
|
||||
|
||||
try:
|
||||
with open(f"json/fundamental-predictor-analysis/{symbol}.json", 'r') as file:
|
||||
res = ujson.load(file)
|
||||
if abs(res['accuracy'] - res['precision']) <=15:
|
||||
item['fundamentalAnalysis'] = {"accuracy": res['accuracy'], 'sentiment': res['sentiment']}
|
||||
else:
|
||||
item['fundamentalAnalysis'] = {"accuracy": None, "sentiment": None}
|
||||
except:
|
||||
item['fundamentalAnalysis'] = {"accuracy": None, "sentiment": None}
|
||||
|
||||
|
||||
return stock_screener_data
|
||||
|
||||
|
||||
@ -1125,8 +1150,6 @@ async def get_most_shorted_stocks(con):
|
||||
return sorted_list
|
||||
|
||||
async def save_json_files():
|
||||
week = datetime.today().weekday()
|
||||
if week <= 7:
|
||||
con = sqlite3.connect('stocks.db')
|
||||
etf_con = sqlite3.connect('etf.db')
|
||||
crypto_con = sqlite3.connect('crypto.db')
|
||||
@ -1146,6 +1169,7 @@ async def save_json_files():
|
||||
crypto_cursor.execute("SELECT DISTINCT symbol FROM cryptos")
|
||||
crypto_symbols = [row[0] for row in crypto_cursor.fetchall()]
|
||||
|
||||
|
||||
data = await get_most_shorted_stocks(con)
|
||||
with open(f"json/most-shorted-stocks/data.json", 'w') as file:
|
||||
ujson.dump(data, file)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user