bugfixing win rate of hedge fund

This commit is contained in:
MuslemRahimi 2024-05-31 19:00:26 +02:00
parent 75cbcd0b5d
commit 5bcd5d7e12
2 changed files with 8 additions and 9 deletions

View File

@ -175,11 +175,12 @@ class InstituteDatabase:
self.conn.commit() self.conn.commit()
return return
performance_percentages = [item.get("performancePercentage", 0) for item in holdings_data]
#Filter information out that is not needed (yet)! #Filter information out that is not needed (yet)!
holdings_data = [{"symbol": item["symbol"], "securityName": item["securityName"], 'weight': item['weight'], 'sharesNumber': item['sharesNumber'], 'changeInSharesNumberPercentage': item['changeInSharesNumberPercentage'], 'putCallShare': item['putCallShare'], "marketValue": item["marketValue"], 'avgPricePaid': item['avgPricePaid']} for item in holdings_data] holdings_data = [{"symbol": item["symbol"], "securityName": item["securityName"], 'weight': item['weight'], 'sharesNumber': item['sharesNumber'], 'changeInSharesNumberPercentage': item['changeInSharesNumberPercentage'], 'putCallShare': item['putCallShare'], "marketValue": item["marketValue"], 'avgPricePaid': item['avgPricePaid']} for item in holdings_data]
number_of_stocks = len(holdings_data) number_of_stocks = len(holdings_data)
performance_percentages = [item.get("performancePercentage", 0) for item in holdings_data]
positive_performance_count = sum(1 for percentage in performance_percentages if percentage > 0) positive_performance_count = sum(1 for percentage in performance_percentages if percentage > 0)
win_rate = round(positive_performance_count / len(performance_percentages) * 100, 2) if performance_percentages else 0 win_rate = round(positive_performance_count / len(performance_percentages) * 100, 2) if performance_percentages else 0
@ -262,7 +263,7 @@ class InstituteDatabase:
tasks.append(self.save_portfolio_data(session, cik)) tasks.append(self.save_portfolio_data(session, cik))
i += 1 i += 1
if i % 400 == 0: if i % 300 == 0:
await asyncio.gather(*tasks) await asyncio.gather(*tasks)
tasks = [] tasks = []
print('sleeping mode: ', i) print('sleeping mode: ', i)

View File

@ -113,7 +113,7 @@ async def get_stock_screener(con,symbols):
cursor.execute("SELECT symbol, name, price, changesPercentage FROM stocks WHERE price IS NOT NULL AND changesPercentage IS NOT NULL") cursor.execute("SELECT symbol, name, price, changesPercentage FROM stocks WHERE price IS NOT NULL AND changesPercentage IS NOT NULL")
raw_data = cursor.fetchall() raw_data = cursor.fetchall()
searchbar_data = [{ stocks_data = [{
'symbol': row[0], 'symbol': row[0],
'name': row[1], 'name': row[1],
'price': row[2], 'price': row[2],
@ -121,15 +121,15 @@ async def get_stock_screener(con,symbols):
} for row in raw_data] } for row in raw_data]
# Create a dictionary to map symbols to 'price' and 'changesPercentage' from searchbar_data # Create a dictionary to map symbols to 'price' and 'changesPercentage' from stocks_data
searchbar_data_map = {entry['symbol']: (entry['price'], entry['changesPercentage']) for entry in searchbar_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 # Iterate through stock_screener_data and update 'price' and 'changesPercentage' if symbols match
# Add VaR value to stock screener # Add VaR value to stock screener
for item in stock_screener_data: for item in stock_screener_data:
symbol = item['symbol'] symbol = item['symbol']
if symbol in searchbar_data_map: if symbol in stocks_data_map:
item['price'], item['changesPercentage'] = searchbar_data_map[symbol] item['price'], item['changesPercentage'] = stocks_data_map[symbol]
try: try:
with open(f"json/var/{symbol}.json", 'r') as file: with open(f"json/var/{symbol}.json", 'r') as file:
item['var'] = ujson.load(file)['var'] item['var'] = ujson.load(file)['var']
@ -147,12 +147,10 @@ async def get_stock_screener(con,symbols):
item['ratingRecommendation'] = 2 item['ratingRecommendation'] = 2
else: else:
item['ratingRecommendation'] = None item['ratingRecommendation'] = None
except: except:
item['ratingRecommendation'] = None item['ratingRecommendation'] = None
return stock_screener_data return stock_screener_data