Skip to content

Commit

Permalink
bugfixing
Browse files Browse the repository at this point in the history
  • Loading branch information
MuslemRahimi committed Dec 4, 2024
1 parent 8703541 commit b16a91b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 223 deletions.
25 changes: 19 additions & 6 deletions app/cron_hedge_funds.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import orjson
import time
from datetime import datetime
from collections import Counter
from tqdm import tqdm

Expand All @@ -19,6 +20,7 @@

quote_cache = {}

cutoff_date = datetime.strptime("2015-01-01", "%Y-%m-%d")

def get_quote_data(symbol):
"""Get quote data for a symbol from JSON file"""
Expand Down Expand Up @@ -101,22 +103,33 @@ def all_hedge_funds(con):


def get_data(cik, stock_sectors):
cursor.execute("SELECT cik, name, numberOfStocks, performancePercentage3year, performancePercentage5year, performanceSinceInceptionPercentage, averageHoldingPeriod, turnover, marketValue, winRate, holdings, summary FROM institutes WHERE cik = ?", (cik,))
cursor.execute("SELECT cik, name, numberOfStocks, performancePercentage3year, averageHoldingPeriod, marketValue, winRate, holdings FROM institutes WHERE cik = ?", (cik,))
cik_data = cursor.fetchall()
res = [{
'cik': row[0],
'name': row[1],
'numberOfStocks': row[2],
'performancePercentage3Year': row[3],
'averageHoldingPeriod': row[6],
'marketValue': row[8],
'winRate': row[9],
'holdings': orjson.loads(row[10]),
'averageHoldingPeriod': row[4],
'marketValue': row[5],
'winRate': row[6],
'holdings': orjson.loads(row[7]),
} for row in cik_data]

if not res:
return None # Exit if no data is found

'''
filtered_data = []
for item in res:
try:
filtered_data+=item['holdings']
except:
pass
filtered_data = [item for item in filtered_data if datetime.strptime(item['date'], "%Y-%m-%d") >= cutoff_date]
print(filtered_data)
'''

res = res[0] #latest data

filtered_holdings = [
Expand Down Expand Up @@ -196,7 +209,7 @@ def get_data(cik, stock_sectors):
cursor.execute("SELECT DISTINCT cik FROM institutes")
cik_symbols = [row[0] for row in cursor.fetchall()]
#Test mode
#cik_symbols = ['0000102909']
#cik_symbols = ['0001649339']
try:
stock_cursor = stock_con.cursor()
stock_cursor.execute("SELECT DISTINCT symbol, sector FROM stocks")
Expand Down
1 change: 1 addition & 0 deletions app/primary_cron_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ def run_threaded(job_func):

schedule.every(2).minutes.do(run_threaded, run_dashboard).tag('dashboard_job')


schedule.every(20).seconds.do(run_threaded, run_if_not_running(run_cron_options_flow, 'options_flow_job')).tag('options_flow_job')


Expand Down
11 changes: 9 additions & 2 deletions app/restart_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import sqlite3
import pandas as pd
import numpy as np
import math
from collections import defaultdict
from collections import Counter
import re
Expand Down Expand Up @@ -193,7 +194,7 @@ def process_financial_data(file_path, key_list):
value = float(res[key])
if 'growth' in file_path or key in ['grossProfitMargin','netProfitMargin','pretaxProfitMargin','operatingProfitMargin','longTermDebtToCapitalization','totalDebtToCapitalization']:
value *= 100 # Multiply by 100 for percentage
data[key] = round(value, 2)
data[key] = round(value, 2) if value is not None else None
except (ValueError, TypeError):
# If there's an issue converting the value, leave it as None
data[key] = None
Expand Down Expand Up @@ -446,7 +447,6 @@ def get_financial_statements(item, symbol):
item['operatingMargin'] = None
item['ebitMargin'] = None



return item

Expand Down Expand Up @@ -819,6 +819,13 @@ async def get_stock_screener(con):
item['netIncomeGrowthYears'] = None
item['grossProfitGrowthYears'] = None

for item in stock_screener_data:
for key, value in item.items():
if isinstance(value, float):
if math.isnan(value) or math.isinf(value):
item[key] = None
print(key)

return stock_screener_data


Expand Down
221 changes: 6 additions & 215 deletions app/test.py

Large diffs are not rendered by default.

0 comments on commit b16a91b

Please sign in to comment.