update hedge fund
This commit is contained in:
parent
68080ac0d4
commit
31b34a2764
@ -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')
|
||||
|
||||
16
app/main.py
16
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')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user