Skip to content

Commit 7563627

Browse files
author
Telijas
committed
WIP
1 parent c49fedc commit 7563627

5 files changed

Lines changed: 61 additions & 14 deletions

File tree

src/data_extract/data_extract.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
def extract_market_data(symbol: str, date: datetime, day_records_negative: int,
1616
day_records_positive: int) -> pd.DataFrame:
17+
"""Returns dataframe with columns: business_date, offset, stock_price_rel, stock_traded_rel and the columns from the market_data table:\n
18+
symbol, business_date, year_month, stock_price, open, close, stock_traded, order_amount, after_hours, pre_market, market_capitalization"""
1719
connection = _get_connection()
1820
upper_date = (date + timedelta(int(day_records_positive * (7 / 5) + 10))).strftime('%Y-%m-%d')
1921
lower_date = (date - timedelta(int(day_records_negative * (7 / 5) + 10))).strftime('%Y-%m-%d')
@@ -26,6 +28,10 @@ def extract_market_data(symbol: str, date: datetime, day_records_negative: int,
2628
connection.close()
2729

2830
df['business_date'] = pd.to_datetime(df['business_date'])
31+
if df.empty:
32+
print("No data returned for symbol:", symbol)
33+
return pd.DataFrame()
34+
2935
reference_index = df[df['business_date'] == date].index[0]
3036
df['offset'] = df.index - reference_index
3137
df = df[(-1) * day_records_negative <= df['offset']]

src/displaying/__init__.py

Whitespace-only changes.

src/displaying/data_display.py

Whitespace-only changes.

src/evaluation/preprocessing.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55

66
import src.data_extract.data_extract as data_extract
77

8-
market_capitalization_lower_limit = 12700000000
8+
market_capitalization_lower_limit = 18000000000
9+
# market_capitalization_lower_limit = 30000000000
910
monthly_shares_traded_lower_limit = 250000
1011

1112

1213
def get_sp500_master_data_candidate(date: datetime) -> list[str]:
1314
candidates = data_extract.get_master_data_eligible_symbols()
1415
candidates = list(set(candidates) - set(data_extract.get_current_sp500_list(date)))
15-
return candidates
16+
return sorted(candidates)
1617

1718

1819
def fetch_data(symbol: str, include_month=6):
@@ -21,6 +22,13 @@ def fetch_data(symbol: str, include_month=6):
2122

2223
def get_sp500_candidates(date: datetime, include_month=6, tolerance=0) -> list[str]:
2324
eligible_symbols = get_sp500_master_data_candidate(date)
25+
# eligible_symbols = ['SW', 'ALNY', 'APO', 'ARES', 'ATVI', 'BCE', 'BMRN', 'BSY', 'BUD', 'CCEP', 'CHKP', 'CM', 'CP',
26+
# 'CPNG', 'CQP', 'CVE', 'DASH', 'DB', 'DDOG', 'DELL', 'EC', 'FCNCA', 'FLT', 'FWONA', 'FWONK',
27+
# 'GFS', 'GIB', 'GLD', 'HEI', 'HUBS', 'ICLR', 'ILMN', 'IMO', 'LNG', 'LPLA', 'MBLY', 'MDB', 'MELI',
28+
# 'MFC', 'MGA', 'MKL', 'MRVL', 'NET', 'NU', 'PINS', 'PKI', 'PLTR', 'PXD', 'RBLX', 'RCI', 'RS',
29+
# 'SCCO', 'SE', 'SIRI', 'SNOW', 'SPLK', 'SPOT', 'SQ', 'SUI', 'TEAM', 'TTD', 'TW', 'VEEV', 'VO',
30+
# 'WDAY', 'WLK', 'YUMC', 'ZM', 'ZS']
31+
2432
with ThreadPoolExecutor() as executor:
2533
list_sp500_el = list(executor.map(fetch_data, eligible_symbols, [include_month] * len(eligible_symbols)))
2634
sp500_list = pd.concat(list_sp500_el, ignore_index=True)

src/main.py

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ def do_show_analysis():
4141
plt.legend()
4242
plt.show()
4343

44-
for symbol, group in grouped:
45-
plt.plot(group['offset'], group['stock_traded_rel'], linestyle='-', label=symbol)
46-
plt.xlabel("Offset")
47-
plt.ylabel("Relative Change")
48-
plt.title("Relative Change vs Offset for Multiple Symbols")
49-
plt.axhline(0, color='gray', linestyle='--', linewidth=0.8) # Add a horizontal line at y=0
50-
plt.grid(True)
51-
plt.legend()
52-
plt.show()
44+
# for symbol, group in grouped:
45+
# plt.plot(group['offset'], group['stock_traded_rel'], linestyle='-', label=symbol)
46+
# plt.xlabel("Offset")
47+
# plt.ylabel("Relative Change")
48+
# plt.title("Relative Change vs Offset for Multiple Symbols")
49+
# plt.axhline(0, color='gray', linestyle='--', linewidth=0.8) # Add a horizontal line at y=0
50+
# plt.grid(True)
51+
# plt.legend()
52+
# plt.show()
5353

5454
print("done")
5555

@@ -59,7 +59,40 @@ def do_show_analysis():
5959

6060

6161
if __name__ == "__main__":
62-
# sp500_stock_quality.display_sp500_quality_of_year(2024)
63-
candidates = preprocessing.get_sp500_candidates(datetime(2023, 10, 18))
62+
sp500_stock_quality.display_sp500_quality_of_year(2024)
63+
sp500_stock_quality.display_sp500_quality_of_year(2025)
64+
check_date = datetime(2024, 7, 8)
65+
candidates = preprocessing.get_sp500_candidates(check_date, 12, 0)
6466
print("Candidates found: ", len(candidates))
65-
print("List of candidates: ", candidates)
67+
# print("List of candidates: ", candidates)
68+
sp500_entries = [(symbol, check_date) for symbol in candidates]
69+
stock_data = pd.DataFrame()
70+
stock_data: pd.DataFrame
71+
for symbol, date in sp500_entries:
72+
if stock_data is pd.DataFrame.empty:
73+
stock_data = data_extract.extract_market_data(symbol, date, 40, 10)
74+
else:
75+
symbol_stock_data = data_extract.extract_market_data(symbol, date, 40, 10)
76+
stock_data = pd.concat([stock_data, symbol_stock_data])
77+
78+
# Group by symbol
79+
grouped = stock_data.groupby('symbol')
80+
for symbol, group in grouped:
81+
plt.plot(group['offset'], group['stock_price_rel'], linestyle='-', label=symbol)
82+
plt.xlabel("Offset")
83+
plt.ylabel("Relative Change")
84+
plt.title("Relative Change vs Offset for Multiple Symbols")
85+
plt.axhline(0, color='gray', linestyle='--', linewidth=0.8) # Add a horizontal line at y=0
86+
plt.grid(True)
87+
plt.legend()
88+
plt.show()
89+
90+
# for symbol, group in grouped:
91+
# plt.plot(group['offset'], group['stock_traded_rel'], linestyle='-', label=symbol)
92+
# plt.xlabel("Offset")
93+
# plt.ylabel("Relative Change")
94+
# plt.title("Relative Change vs Offset for Multiple Symbols")
95+
# plt.axhline(0, color='gray', linestyle='--', linewidth=0.8) # Add a horizontal line at y=0
96+
# plt.grid(True)
97+
# plt.legend()
98+
# plt.show()

0 commit comments

Comments
 (0)