lecrapaud 0.4.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of lecrapaud might be problematic. Click here for more details.
- lecrapaud/__init__.py +0 -0
- lecrapaud/config.py +16 -0
- lecrapaud/db/__init__.py +0 -0
- lecrapaud/db/alembic/README +1 -0
- lecrapaud/db/alembic/env.py +78 -0
- lecrapaud/db/alembic/script.py.mako +26 -0
- lecrapaud/db/alembic/versions/2025_04_06_1738-7390745388e4_initial_setup.py +295 -0
- lecrapaud/db/alembic/versions/2025_04_06_1755-40cd8d3e798e_unique_constraint_for_data.py +30 -0
- lecrapaud/db/alembic/versions/2025_05_23_1724-2360941fa0bd_longer_string.py +52 -0
- lecrapaud/db/alembic/versions/2025_05_27_1159-b96396dcfaff_add_env_to_trading_tables.py +34 -0
- lecrapaud/db/alembic/versions/2025_05_27_1337-40cbfc215f7c_fix_nb_character_on_portfolio.py +39 -0
- lecrapaud/db/alembic/versions/2025_05_27_1526-3de994115317_to_datetime.py +36 -0
- lecrapaud/db/alembic/versions/2025_05_27_2003-25c227c684f8_add_fees_to_transactions.py +30 -0
- lecrapaud/db/alembic/versions/2025_05_27_2047-6b6f2d38e9bc_double_instead_of_float.py +132 -0
- lecrapaud/db/alembic/versions/2025_05_31_1111-c175e4a36d68_generalise_stock_to_group.py +36 -0
- lecrapaud/db/alembic/versions/2025_05_31_1256-5681095bfc27_create_investment_run_and_portfolio_.py +62 -0
- lecrapaud/db/alembic/versions/2025_05_31_1806-339927587383_add_investment_run_id.py +107 -0
- lecrapaud/db/alembic/versions/2025_05_31_1834-52b809a34371_make_nullablee.py +38 -0
- lecrapaud/db/alembic/versions/2025_05_31_1849-3b8550297e8e_change_date_to_datetime.py +44 -0
- lecrapaud/db/alembic/versions/2025_05_31_1852-e6b8c95d8243_add_date_to_portfolio_history.py +30 -0
- lecrapaud/db/alembic/versions/2025_06_10_1136-db8cdd83563a_addnewsandoptiontodata.py +32 -0
- lecrapaud/db/crud.py +179 -0
- lecrapaud/db/models/__init__.py +11 -0
- lecrapaud/db/models/base.py +6 -0
- lecrapaud/db/models/dataset.py +124 -0
- lecrapaud/db/models/feature.py +46 -0
- lecrapaud/db/models/feature_selection.py +126 -0
- lecrapaud/db/models/feature_selection_rank.py +80 -0
- lecrapaud/db/models/model.py +41 -0
- lecrapaud/db/models/model_selection.py +56 -0
- lecrapaud/db/models/model_training.py +54 -0
- lecrapaud/db/models/score.py +62 -0
- lecrapaud/db/models/target.py +59 -0
- lecrapaud/db/services.py +0 -0
- lecrapaud/db/setup.py +58 -0
- lecrapaud/directory_management.py +28 -0
- lecrapaud/feature_engineering.py +1119 -0
- lecrapaud/feature_selection.py +1229 -0
- lecrapaud/jobs/__init__.py +13 -0
- lecrapaud/jobs/config.py +17 -0
- lecrapaud/jobs/scheduler.py +36 -0
- lecrapaud/jobs/tasks.py +57 -0
- lecrapaud/model_selection.py +1571 -0
- lecrapaud/predictions.py +292 -0
- lecrapaud/search_space.py +844 -0
- lecrapaud/services/__init__.py +0 -0
- lecrapaud/services/embedding_categorical.py +71 -0
- lecrapaud/services/indicators.py +309 -0
- lecrapaud/speed_tests/experiments.py +139 -0
- lecrapaud/speed_tests/test-gpu-bilstm.ipynb +261 -0
- lecrapaud/speed_tests/test-gpu-resnet.ipynb +166 -0
- lecrapaud/speed_tests/test-gpu-transformers.ipynb +254 -0
- lecrapaud/speed_tests/tests.ipynb +145 -0
- lecrapaud/speed_tests/trash.py +37 -0
- lecrapaud/training.py +151 -0
- lecrapaud/utils.py +246 -0
- lecrapaud-0.4.0.dist-info/LICENSE +201 -0
- lecrapaud-0.4.0.dist-info/METADATA +103 -0
- lecrapaud-0.4.0.dist-info/RECORD +60 -0
- lecrapaud-0.4.0.dist-info/WHEEL +4 -0
lecrapaud/db/setup.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
from sqlalchemy import create_engine, text, MetaData
|
|
2
|
+
from sqlalchemy.orm import sessionmaker
|
|
3
|
+
import os
|
|
4
|
+
from contextlib import contextmanager
|
|
5
|
+
from dotenv import load_dotenv
|
|
6
|
+
|
|
7
|
+
load_dotenv()
|
|
8
|
+
|
|
9
|
+
if os.getenv("PYTHON_ENV") == "Test":
|
|
10
|
+
DB_USER = os.getenv("TEST_DB_USER", "root")
|
|
11
|
+
DB_PASSWORD = os.getenv("TEST_DB_PASSWORD", "")
|
|
12
|
+
DB_HOST = os.getenv("TEST_DB_HOST", "127.0.0.1")
|
|
13
|
+
DB_PORT = os.getenv("TEST_DB_PORT", "3306")
|
|
14
|
+
DB_NAME = os.getenv("TEST_DB_NAME", "test_stock_db")
|
|
15
|
+
else:
|
|
16
|
+
DB_USER = os.getenv("DB_USER", "root")
|
|
17
|
+
DB_PASSWORD = os.getenv("DB_PASSWORD", "")
|
|
18
|
+
DB_HOST = os.getenv("DB_HOST", "localhost")
|
|
19
|
+
DB_PORT = os.getenv("DB_PORT", "3306")
|
|
20
|
+
DB_NAME = os.getenv("DB_NAME", "stock_db")
|
|
21
|
+
|
|
22
|
+
# Step 1: Connect to MySQL without a database
|
|
23
|
+
root_engine = create_engine(
|
|
24
|
+
f"mysql+pymysql://{DB_USER}:{DB_PASSWORD}@{DB_HOST}:{DB_PORT}/"
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
# Step 2: Create database if it doesn't exist
|
|
28
|
+
with root_engine.connect() as conn:
|
|
29
|
+
conn.execute(text(f"CREATE DATABASE IF NOT EXISTS {DB_NAME}"))
|
|
30
|
+
conn.commit()
|
|
31
|
+
|
|
32
|
+
# Step 3: Connect to the newly created database
|
|
33
|
+
DATABASE_URL = f"mysql+pymysql://{DB_USER}:{DB_PASSWORD}@{DB_HOST}:{DB_PORT}/{DB_NAME}"
|
|
34
|
+
engine = create_engine(DATABASE_URL, echo=False)
|
|
35
|
+
|
|
36
|
+
# Step 4: Create session factory
|
|
37
|
+
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
38
|
+
|
|
39
|
+
# Step 5: Create tables
|
|
40
|
+
RESET_DB = False
|
|
41
|
+
if RESET_DB:
|
|
42
|
+
metadata = MetaData()
|
|
43
|
+
metadata.reflect(bind=engine)
|
|
44
|
+
metadata.drop_all(bind=engine)
|
|
45
|
+
# Base.metadata.create_all(bind=engine)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
# Dependency to get a session instance
|
|
49
|
+
@contextmanager
|
|
50
|
+
def get_db():
|
|
51
|
+
db = SessionLocal()
|
|
52
|
+
try:
|
|
53
|
+
yield db
|
|
54
|
+
except Exception as e:
|
|
55
|
+
db.rollback()
|
|
56
|
+
raise Exception(e)
|
|
57
|
+
finally:
|
|
58
|
+
db.close()
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import os, shutil
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
cwd = os.getcwd()
|
|
5
|
+
tmp_dir = cwd + "/tmp"
|
|
6
|
+
data_dir = tmp_dir + "/data"
|
|
7
|
+
logger_dir = cwd + "/log"
|
|
8
|
+
|
|
9
|
+
os.makedirs(tmp_dir, exist_ok=True)
|
|
10
|
+
os.makedirs(data_dir, exist_ok=True)
|
|
11
|
+
os.makedirs(logger_dir, exist_ok=True)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def clean_directories():
|
|
15
|
+
clean_directory(tmp_dir)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def clean_directory(dir_path: str):
|
|
19
|
+
if os.path.exists(dir_path):
|
|
20
|
+
for root, dirs, files in os.walk(dir_path, topdown=False):
|
|
21
|
+
for file in files:
|
|
22
|
+
file_path = os.path.join(root, file)
|
|
23
|
+
os.remove(file_path)
|
|
24
|
+
for dir in dirs:
|
|
25
|
+
dir_path = os.path.join(root, dir)
|
|
26
|
+
shutil.rmtree(dir_path) # Recursively remove directories
|
|
27
|
+
else:
|
|
28
|
+
Exception(f"Directory {dir_path} does not exist.")
|