Skip to content

Commit

Permalink
bugfixing win rate of hedge fund
Browse files Browse the repository at this point in the history
  • Loading branch information
MuslemRahimi committed May 31, 2024
1 parent 75cbcd0 commit 5bcd5d7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
5 changes: 3 additions & 2 deletions app/create_institute_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,12 @@ async def save_portfolio_data(self, session, cik):
self.conn.commit()
return

performance_percentages = [item.get("performancePercentage", 0) for item in holdings_data]

#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]

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)
win_rate = round(positive_performance_count / len(performance_percentages) * 100, 2) if performance_percentages else 0

Expand Down Expand Up @@ -262,7 +263,7 @@ async def save_insitute(self, institutes):
tasks.append(self.save_portfolio_data(session, cik))

i += 1
if i % 400 == 0:
if i % 300 == 0:
await asyncio.gather(*tasks)
tasks = []
print('sleeping mode: ', i)
Expand Down
12 changes: 5 additions & 7 deletions app/restart_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,23 +113,23 @@ 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")
raw_data = cursor.fetchall()
searchbar_data = [{
stocks_data = [{
'symbol': row[0],
'name': row[1],
'price': row[2],
'changesPercentage': row[3],
} for row in raw_data]


# Create a dictionary to map symbols to 'price' and 'changesPercentage' from searchbar_data
searchbar_data_map = {entry['symbol']: (entry['price'], entry['changesPercentage']) for entry in searchbar_data}
# 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:
symbol = item['symbol']
if symbol in searchbar_data_map:
item['price'], item['changesPercentage'] = searchbar_data_map[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']
Expand All @@ -147,12 +147,10 @@ async def get_stock_screener(con,symbols):
item['ratingRecommendation'] = 2
else:
item['ratingRecommendation'] = None

except:
item['ratingRecommendation'] = None



return stock_screener_data


Expand Down

0 comments on commit 5bcd5d7

Please sign in to comment.