From 31b34a27646be6d97a52cd32fed221bcdcdd087e Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Wed, 29 May 2024 10:20:40 +0200 Subject: [PATCH] update hedge fund --- app/cron_hedge_funds.py | 34 ++++++++++++++++++++++++++++++++++ app/main.py | 16 +++++++++------- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/app/cron_hedge_funds.py b/app/cron_hedge_funds.py index 50657de..b69559f 100644 --- a/app/cron_hedge_funds.py +++ b/app/cron_hedge_funds.py @@ -96,6 +96,40 @@ def all_hedge_funds(con): json.dump(sorted_res_list, file) +def spy_performance(): + import pandas as pd + import yfinance as yf + from datetime import datetime + + # Define the start date and end date + start_date = '1993-01-01' + end_date = datetime.today().strftime('%Y-%m-%d') + + # Generate the range of dates with quarterly frequency + date_range = pd.date_range(start=start_date, end=end_date, freq='Q') + + # Convert the dates to the desired format (end of quarter dates) + end_of_quarters = date_range.strftime('%Y-%m-%d').tolist() + + data = [] + + df = yf.download('SPY', start='1993-01-01', end=datetime.today(), interval="1d").reset_index() + df = df.rename(columns={'Adj Close': 'close', 'Date': 'date'}) + + df['date'] = df['date'].dt.strftime('%Y-%m-%d') + for target_date in end_of_quarters: + original_date = target_date + # Find close price for '2015-03-31' or the closest available date prior to it + while target_date not in df['date'].values: + # If the target date doesn't exist, move one day back + target_date = (pd.to_datetime(target_date) - pd.Timedelta(days=1)).strftime('%Y-%m-%d') + + # Get the close price for the found or closest date + close_price = round(df[df['date'] == target_date]['close'].values[0],2) + data.append({'date': original_date, 'price': close_price}) + print(data) + + if __name__ == '__main__': con = sqlite3.connect('institute.db') diff --git a/app/main.py b/app/main.py index 6f00059..585c5e3 100755 --- a/app/main.py +++ b/app/main.py @@ -1410,19 +1410,21 @@ async def get_hedge_funds_data(data: GetCIKData): cursor = con_inst.cursor() # Execute a SQL query to select the top 10 best performing cik entries by winRate - cursor.execute("SELECT cik, name, numberOfStocks, performancePercentage3year, averageHoldingPeriod, turnover, marketValue, winRate, holdings, summary FROM institutes WHERE cik = ?", (cik,)) + cursor.execute("SELECT cik, name, numberOfStocks, performancePercentage3year, performancePercentage5year, performanceSinceInceptionPercentage, averageHoldingPeriod, turnover, marketValue, winRate, holdings, summary FROM institutes WHERE cik = ?", (cik,)) cik_data = cursor.fetchall() res = [{ 'cik': row[0], 'name': row[1], 'numberOfStocks': row[2], 'performancePercentage3year': row[3], - 'averageHoldingPeriod': row[4], - 'turnover': row[5], - 'marketValue': row[6], - 'winRate': row[7], - 'holdings': ujson.loads(row[8]), - 'summary': ujson.loads(row[9]), + 'performancePercentage5year': row[4], + 'performanceSinceInceptionPercentage': row[5], + 'averageHoldingPeriod': row[6], + 'turnover': row[7], + 'marketValue': row[8], + 'winRate': row[9], + 'holdings': ujson.loads(row[10]), + 'summary': ujson.loads(row[11]), } for row in cik_data] res_json = ujson.dumps(res[0]).encode('utf-8')