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.

Files changed (60) hide show
  1. lecrapaud/__init__.py +0 -0
  2. lecrapaud/config.py +16 -0
  3. lecrapaud/db/__init__.py +0 -0
  4. lecrapaud/db/alembic/README +1 -0
  5. lecrapaud/db/alembic/env.py +78 -0
  6. lecrapaud/db/alembic/script.py.mako +26 -0
  7. lecrapaud/db/alembic/versions/2025_04_06_1738-7390745388e4_initial_setup.py +295 -0
  8. lecrapaud/db/alembic/versions/2025_04_06_1755-40cd8d3e798e_unique_constraint_for_data.py +30 -0
  9. lecrapaud/db/alembic/versions/2025_05_23_1724-2360941fa0bd_longer_string.py +52 -0
  10. lecrapaud/db/alembic/versions/2025_05_27_1159-b96396dcfaff_add_env_to_trading_tables.py +34 -0
  11. lecrapaud/db/alembic/versions/2025_05_27_1337-40cbfc215f7c_fix_nb_character_on_portfolio.py +39 -0
  12. lecrapaud/db/alembic/versions/2025_05_27_1526-3de994115317_to_datetime.py +36 -0
  13. lecrapaud/db/alembic/versions/2025_05_27_2003-25c227c684f8_add_fees_to_transactions.py +30 -0
  14. lecrapaud/db/alembic/versions/2025_05_27_2047-6b6f2d38e9bc_double_instead_of_float.py +132 -0
  15. lecrapaud/db/alembic/versions/2025_05_31_1111-c175e4a36d68_generalise_stock_to_group.py +36 -0
  16. lecrapaud/db/alembic/versions/2025_05_31_1256-5681095bfc27_create_investment_run_and_portfolio_.py +62 -0
  17. lecrapaud/db/alembic/versions/2025_05_31_1806-339927587383_add_investment_run_id.py +107 -0
  18. lecrapaud/db/alembic/versions/2025_05_31_1834-52b809a34371_make_nullablee.py +38 -0
  19. lecrapaud/db/alembic/versions/2025_05_31_1849-3b8550297e8e_change_date_to_datetime.py +44 -0
  20. lecrapaud/db/alembic/versions/2025_05_31_1852-e6b8c95d8243_add_date_to_portfolio_history.py +30 -0
  21. lecrapaud/db/alembic/versions/2025_06_10_1136-db8cdd83563a_addnewsandoptiontodata.py +32 -0
  22. lecrapaud/db/crud.py +179 -0
  23. lecrapaud/db/models/__init__.py +11 -0
  24. lecrapaud/db/models/base.py +6 -0
  25. lecrapaud/db/models/dataset.py +124 -0
  26. lecrapaud/db/models/feature.py +46 -0
  27. lecrapaud/db/models/feature_selection.py +126 -0
  28. lecrapaud/db/models/feature_selection_rank.py +80 -0
  29. lecrapaud/db/models/model.py +41 -0
  30. lecrapaud/db/models/model_selection.py +56 -0
  31. lecrapaud/db/models/model_training.py +54 -0
  32. lecrapaud/db/models/score.py +62 -0
  33. lecrapaud/db/models/target.py +59 -0
  34. lecrapaud/db/services.py +0 -0
  35. lecrapaud/db/setup.py +58 -0
  36. lecrapaud/directory_management.py +28 -0
  37. lecrapaud/feature_engineering.py +1119 -0
  38. lecrapaud/feature_selection.py +1229 -0
  39. lecrapaud/jobs/__init__.py +13 -0
  40. lecrapaud/jobs/config.py +17 -0
  41. lecrapaud/jobs/scheduler.py +36 -0
  42. lecrapaud/jobs/tasks.py +57 -0
  43. lecrapaud/model_selection.py +1571 -0
  44. lecrapaud/predictions.py +292 -0
  45. lecrapaud/search_space.py +844 -0
  46. lecrapaud/services/__init__.py +0 -0
  47. lecrapaud/services/embedding_categorical.py +71 -0
  48. lecrapaud/services/indicators.py +309 -0
  49. lecrapaud/speed_tests/experiments.py +139 -0
  50. lecrapaud/speed_tests/test-gpu-bilstm.ipynb +261 -0
  51. lecrapaud/speed_tests/test-gpu-resnet.ipynb +166 -0
  52. lecrapaud/speed_tests/test-gpu-transformers.ipynb +254 -0
  53. lecrapaud/speed_tests/tests.ipynb +145 -0
  54. lecrapaud/speed_tests/trash.py +37 -0
  55. lecrapaud/training.py +151 -0
  56. lecrapaud/utils.py +246 -0
  57. lecrapaud-0.4.0.dist-info/LICENSE +201 -0
  58. lecrapaud-0.4.0.dist-info/METADATA +103 -0
  59. lecrapaud-0.4.0.dist-info/RECORD +60 -0
  60. lecrapaud-0.4.0.dist-info/WHEEL +4 -0
lecrapaud/__init__.py ADDED
File without changes
lecrapaud/config.py ADDED
@@ -0,0 +1,16 @@
1
+ import os
2
+ from dotenv import load_dotenv
3
+
4
+ load_dotenv(override=False)
5
+
6
+ PYTHON_ENV = os.getenv("PYTHON_ENV")
7
+ REDIS_URL = os.getenv("REDIS_URL", "redis://localhost:6379")
8
+ EMAIL = os.getenv("EMAIL")
9
+ DATASET_ID = os.getenv("DATASET_ID")
10
+ RECEIVER_EMAIL = os.getenv("RECEIVER_EMAIL")
11
+ USERNAME = os.getenv("USERNAME")
12
+ FRAISE = os.getenv("FRAISE")
13
+ FA2 = os.getenv("2FA")
14
+ INT = os.getenv("INT")
15
+ LOGGING_LEVEL = os.getenv("LOGGING_LEVEL", "INFO")
16
+ ALPHA_VENTAGE_API_KEY = os.getenv("ALPHA_VENTAGE_API_KEY")
File without changes
@@ -0,0 +1 @@
1
+ Generic single-database configuration.
@@ -0,0 +1,78 @@
1
+ from logging.config import fileConfig
2
+
3
+ from sqlalchemy import engine_from_config
4
+ from sqlalchemy import pool
5
+
6
+ from alembic import context
7
+ from src.db.setup import DATABASE_URL
8
+
9
+ # this is the Alembic Config object, which provides
10
+ # access to the values within the .ini file in use.
11
+ config = context.config
12
+ config.set_main_option("sqlalchemy.url", DATABASE_URL)
13
+
14
+ # Interpret the config file for Python logging.
15
+ # This line sets up loggers basically.
16
+ if config.config_file_name is not None:
17
+ fileConfig(config.config_file_name)
18
+
19
+ # add your model's MetaData object here
20
+ # for 'autogenerate' support
21
+ from src.db.models.base import Base
22
+
23
+ target_metadata = Base.metadata
24
+
25
+ # other values from the config, defined by the needs of env.py,
26
+ # can be acquired:
27
+ # my_important_option = config.get_main_option("my_important_option")
28
+ # ... etc.
29
+
30
+
31
+ def run_migrations_offline() -> None:
32
+ """Run migrations in 'offline' mode.
33
+
34
+ This configures the context with just a URL
35
+ and not an Engine, though an Engine is acceptable
36
+ here as well. By skipping the Engine creation
37
+ we don't even need a DBAPI to be available.
38
+
39
+ Calls to context.execute() here emit the given string to the
40
+ script output.
41
+
42
+ """
43
+ url = config.get_main_option("sqlalchemy.url")
44
+ context.configure(
45
+ url=url,
46
+ target_metadata=target_metadata,
47
+ literal_binds=True,
48
+ dialect_opts={"paramstyle": "named"},
49
+ )
50
+
51
+ with context.begin_transaction():
52
+ context.run_migrations()
53
+
54
+
55
+ def run_migrations_online() -> None:
56
+ """Run migrations in 'online' mode.
57
+
58
+ In this scenario we need to create an Engine
59
+ and associate a connection with the context.
60
+
61
+ """
62
+ connectable = engine_from_config(
63
+ config.get_section(config.config_ini_section, {}),
64
+ prefix="sqlalchemy.",
65
+ poolclass=pool.NullPool,
66
+ )
67
+
68
+ with connectable.connect() as connection:
69
+ context.configure(connection=connection, target_metadata=target_metadata)
70
+
71
+ with context.begin_transaction():
72
+ context.run_migrations()
73
+
74
+
75
+ if context.is_offline_mode():
76
+ run_migrations_offline()
77
+ else:
78
+ run_migrations_online()
@@ -0,0 +1,26 @@
1
+ """${message}
2
+
3
+ Revision ID: ${up_revision}
4
+ Revises: ${down_revision | comma,n}
5
+ Create Date: ${create_date}
6
+
7
+ """
8
+ from typing import Sequence, Union
9
+
10
+ from alembic import op
11
+ import sqlalchemy as sa
12
+ ${imports if imports else ""}
13
+
14
+ # revision identifiers, used by Alembic.
15
+ revision: str = ${repr(up_revision)}
16
+ down_revision: Union[str, None] = ${repr(down_revision)}
17
+ branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
18
+ depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}
19
+
20
+
21
+ def upgrade() -> None:
22
+ ${upgrades if upgrades else "pass"}
23
+
24
+
25
+ def downgrade() -> None:
26
+ ${downgrades if downgrades else "pass"}
@@ -0,0 +1,295 @@
1
+ """initial setup
2
+
3
+ Revision ID: 7390745388e4
4
+ Revises:
5
+ Create Date: 2025-04-06 17:38:29.297967
6
+
7
+ """
8
+ from typing import Sequence, Union
9
+
10
+ from alembic import op
11
+ import sqlalchemy as sa
12
+
13
+
14
+ # revision identifiers, used by Alembic.
15
+ revision: str = '7390745388e4'
16
+ down_revision: Union[str, None] = None
17
+ branch_labels: Union[str, Sequence[str], None] = None
18
+ depends_on: Union[str, Sequence[str], None] = None
19
+
20
+
21
+ def upgrade() -> None:
22
+ # ### commands auto generated by Alembic - please adjust! ###
23
+ op.create_table('datas',
24
+ sa.Column('id', sa.BigInteger(), autoincrement=True, nullable=False),
25
+ sa.Column('created_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
26
+ sa.Column('updated_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
27
+ sa.Column('date', sa.DateTime(), nullable=True),
28
+ sa.Column('open', sa.Float(), nullable=True),
29
+ sa.Column('high', sa.Float(), nullable=True),
30
+ sa.Column('low', sa.Float(), nullable=True),
31
+ sa.Column('close', sa.Float(), nullable=True),
32
+ sa.Column('adjclose', sa.Float(), nullable=True),
33
+ sa.Column('volume', sa.BigInteger(), nullable=True),
34
+ sa.Column('stock', sa.String(length=50), nullable=True),
35
+ sa.Column('isin', sa.String(length=50), nullable=True),
36
+ sa.Column('security', sa.String(length=50), nullable=True),
37
+ sa.Column('sector', sa.String(length=255), nullable=True),
38
+ sa.Column('subindustry', sa.String(length=255), nullable=True),
39
+ sa.Column('location', sa.String(length=255), nullable=True),
40
+ sa.Column('vix_close', sa.Float(), nullable=True),
41
+ sa.PrimaryKeyConstraint('id')
42
+ )
43
+ op.create_index(op.f('ix_datas_date'), 'datas', ['date'], unique=False)
44
+ op.create_index(op.f('ix_datas_id'), 'datas', ['id'], unique=False)
45
+ op.create_index(op.f('ix_datas_stock'), 'datas', ['stock'], unique=False)
46
+ op.create_table('datasets',
47
+ sa.Column('id', sa.BigInteger(), autoincrement=True, nullable=False),
48
+ sa.Column('created_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
49
+ sa.Column('updated_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
50
+ sa.Column('name', sa.String(length=50), nullable=False),
51
+ sa.Column('path', sa.String(length=255), nullable=True),
52
+ sa.Column('type', sa.String(length=50), nullable=False),
53
+ sa.Column('size', sa.Integer(), nullable=False),
54
+ sa.Column('train_size', sa.Integer(), nullable=False),
55
+ sa.Column('val_size', sa.Integer(), nullable=True),
56
+ sa.Column('test_size', sa.Integer(), nullable=False),
57
+ sa.Column('number_of_stocks', sa.Integer(), nullable=False),
58
+ sa.Column('list_of_companies', sa.JSON(), nullable=False),
59
+ sa.Column('corr_threshold', sa.Float(), nullable=False),
60
+ sa.Column('max_features', sa.Integer(), nullable=False),
61
+ sa.Column('percentile', sa.Float(), nullable=False),
62
+ sa.Column('start_date', sa.DateTime(), nullable=False),
63
+ sa.Column('end_date', sa.DateTime(), nullable=False),
64
+ sa.Column('train_start_date', sa.DateTime(), nullable=False),
65
+ sa.Column('train_end_date', sa.DateTime(), nullable=False),
66
+ sa.Column('val_start_date', sa.DateTime(), nullable=True),
67
+ sa.Column('val_end_date', sa.DateTime(), nullable=True),
68
+ sa.Column('test_start_date', sa.DateTime(), nullable=False),
69
+ sa.Column('test_end_date', sa.DateTime(), nullable=False),
70
+ sa.PrimaryKeyConstraint('id'),
71
+ sa.UniqueConstraint('name', name='uq_datasets_composite')
72
+ )
73
+ op.create_index(op.f('ix_datasets_id'), 'datasets', ['id'], unique=False)
74
+ op.create_table('features',
75
+ sa.Column('id', sa.BigInteger(), autoincrement=True, nullable=False),
76
+ sa.Column('created_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
77
+ sa.Column('updated_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
78
+ sa.Column('name', sa.String(length=50), nullable=False),
79
+ sa.Column('type', sa.String(length=50), nullable=True),
80
+ sa.PrimaryKeyConstraint('id'),
81
+ sa.UniqueConstraint('name')
82
+ )
83
+ op.create_index(op.f('ix_features_id'), 'features', ['id'], unique=False)
84
+ op.create_table('models',
85
+ sa.Column('id', sa.BigInteger(), autoincrement=True, nullable=False),
86
+ sa.Column('created_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
87
+ sa.Column('updated_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
88
+ sa.Column('name', sa.String(length=50), nullable=False),
89
+ sa.Column('type', sa.String(length=50), nullable=False),
90
+ sa.PrimaryKeyConstraint('id'),
91
+ sa.UniqueConstraint('name', 'type', name='uq_model_composite')
92
+ )
93
+ op.create_index(op.f('ix_models_id'), 'models', ['id'], unique=False)
94
+ op.create_table('operations',
95
+ sa.Column('id', sa.BigInteger(), autoincrement=True, nullable=False),
96
+ sa.Column('created_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
97
+ sa.Column('updated_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
98
+ sa.Column('stock', sa.String(length=50), nullable=False),
99
+ sa.Column('price_in', sa.Float(), nullable=False),
100
+ sa.Column('date_in', sa.Date(), nullable=False),
101
+ sa.Column('why_buy', sa.String(length=50), nullable=True),
102
+ sa.Column('price_out', sa.Float(), nullable=False),
103
+ sa.Column('date_out', sa.Date(), nullable=False),
104
+ sa.Column('why_sell', sa.String(length=50), nullable=True),
105
+ sa.Column('pl', sa.Float(), nullable=False),
106
+ sa.Column('cash', sa.Float(), nullable=False),
107
+ sa.Column('portfolio_value', sa.Float(), nullable=False),
108
+ sa.Column('total_value', sa.Float(), nullable=False),
109
+ sa.Column('roi', sa.Float(), nullable=False),
110
+ sa.Column('cumulated_roi', sa.Float(), nullable=False),
111
+ sa.Column('cagr', sa.Float(), nullable=False),
112
+ sa.PrimaryKeyConstraint('id')
113
+ )
114
+ op.create_index(op.f('ix_operations_id'), 'operations', ['id'], unique=False)
115
+ op.create_table('portfolios',
116
+ sa.Column('id', sa.BigInteger(), autoincrement=True, nullable=False),
117
+ sa.Column('created_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
118
+ sa.Column('updated_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
119
+ sa.Column('stock', sa.String(length=50), nullable=False),
120
+ sa.Column('position', sa.Integer(), nullable=False),
121
+ sa.Column('price_in', sa.Float(), nullable=False),
122
+ sa.Column('value', sa.Float(), nullable=False),
123
+ sa.Column('date_in', sa.Date(), nullable=False),
124
+ sa.Column('why_buy', sa.String(length=50), nullable=True),
125
+ sa.PrimaryKeyConstraint('id')
126
+ )
127
+ op.create_index(op.f('ix_portfolios_id'), 'portfolios', ['id'], unique=False)
128
+ op.create_table('targets',
129
+ sa.Column('id', sa.BigInteger(), autoincrement=True, nullable=False),
130
+ sa.Column('created_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
131
+ sa.Column('updated_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
132
+ sa.Column('name', sa.String(length=50), nullable=False),
133
+ sa.Column('type', sa.String(length=50), nullable=False),
134
+ sa.Column('description', sa.String(length=255), nullable=True),
135
+ sa.PrimaryKeyConstraint('id'),
136
+ sa.UniqueConstraint('name', 'type', name='uq_target_composite')
137
+ )
138
+ op.create_index(op.f('ix_targets_id'), 'targets', ['id'], unique=False)
139
+ op.create_table('transactions',
140
+ sa.Column('id', sa.BigInteger(), autoincrement=True, nullable=False),
141
+ sa.Column('created_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
142
+ sa.Column('updated_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
143
+ sa.Column('buy_sell', sa.String(length=50), nullable=False),
144
+ sa.Column('stock', sa.String(length=50), nullable=False),
145
+ sa.Column('price', sa.Float(), nullable=False),
146
+ sa.Column('position', sa.Integer(), nullable=False),
147
+ sa.Column('value', sa.Float(), nullable=False),
148
+ sa.Column('date', sa.Date(), nullable=False),
149
+ sa.Column('why', sa.String(length=50), nullable=True),
150
+ sa.PrimaryKeyConstraint('id')
151
+ )
152
+ op.create_index(op.f('ix_transactions_id'), 'transactions', ['id'], unique=False)
153
+ op.create_table('dataset_target_association',
154
+ sa.Column('dataset_id', sa.BigInteger(), nullable=False),
155
+ sa.Column('target_id', sa.BigInteger(), nullable=False),
156
+ sa.ForeignKeyConstraint(['dataset_id'], ['datasets.id'], ondelete='CASCADE'),
157
+ sa.ForeignKeyConstraint(['target_id'], ['targets.id'], ondelete='CASCADE'),
158
+ sa.PrimaryKeyConstraint('dataset_id', 'target_id')
159
+ )
160
+ op.create_table('feature_selections',
161
+ sa.Column('id', sa.BigInteger(), autoincrement=True, nullable=False),
162
+ sa.Column('created_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
163
+ sa.Column('updated_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
164
+ sa.Column('training_time', sa.Integer(), nullable=True),
165
+ sa.Column('best_features_path', sa.String(length=255), nullable=True),
166
+ sa.Column('dataset_id', sa.BigInteger(), nullable=False),
167
+ sa.Column('target_id', sa.BigInteger(), nullable=False),
168
+ sa.ForeignKeyConstraint(['dataset_id'], ['datasets.id'], ondelete='CASCADE'),
169
+ sa.ForeignKeyConstraint(['target_id'], ['targets.id'], ondelete='CASCADE'),
170
+ sa.PrimaryKeyConstraint('id'),
171
+ sa.UniqueConstraint('dataset_id', 'target_id', name='uq_feature_selection_composite')
172
+ )
173
+ op.create_index(op.f('ix_feature_selections_id'), 'feature_selections', ['id'], unique=False)
174
+ op.create_table('model_selections',
175
+ sa.Column('id', sa.BigInteger(), autoincrement=True, nullable=False),
176
+ sa.Column('created_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
177
+ sa.Column('updated_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
178
+ sa.Column('best_model_params', sa.JSON(), nullable=True),
179
+ sa.Column('best_model_path', sa.String(length=255), nullable=True),
180
+ sa.Column('best_model_id', sa.BigInteger(), nullable=True),
181
+ sa.Column('target_id', sa.BigInteger(), nullable=False),
182
+ sa.Column('dataset_id', sa.BigInteger(), nullable=False),
183
+ sa.ForeignKeyConstraint(['best_model_id'], ['models.id'], ondelete='CASCADE'),
184
+ sa.ForeignKeyConstraint(['dataset_id'], ['datasets.id'], ondelete='CASCADE'),
185
+ sa.ForeignKeyConstraint(['target_id'], ['targets.id'], ondelete='CASCADE'),
186
+ sa.PrimaryKeyConstraint('id'),
187
+ sa.UniqueConstraint('target_id', 'dataset_id', name='uq_model_selection_composite')
188
+ )
189
+ op.create_index(op.f('ix_model_selections_id'), 'model_selections', ['id'], unique=False)
190
+ op.create_table('feature_selection_association',
191
+ sa.Column('feature_selection_id', sa.BigInteger(), nullable=False),
192
+ sa.Column('feature_id', sa.BigInteger(), nullable=False),
193
+ sa.ForeignKeyConstraint(['feature_id'], ['features.id'], ondelete='CASCADE'),
194
+ sa.ForeignKeyConstraint(['feature_selection_id'], ['feature_selections.id'], ondelete='CASCADE'),
195
+ sa.PrimaryKeyConstraint('feature_selection_id', 'feature_id')
196
+ )
197
+ op.create_table('feature_selection_ranks',
198
+ sa.Column('id', sa.BigInteger(), autoincrement=True, nullable=False),
199
+ sa.Column('created_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
200
+ sa.Column('updated_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
201
+ sa.Column('score', sa.Float(), nullable=True),
202
+ sa.Column('pvalue', sa.Float(), nullable=True),
203
+ sa.Column('support', sa.Integer(), nullable=True),
204
+ sa.Column('rank', sa.Integer(), nullable=True),
205
+ sa.Column('method', sa.String(length=50), nullable=True),
206
+ sa.Column('training_time', sa.Integer(), nullable=True),
207
+ sa.Column('feature_id', sa.BigInteger(), nullable=True),
208
+ sa.Column('feature_selection_id', sa.BigInteger(), nullable=True),
209
+ sa.ForeignKeyConstraint(['feature_id'], ['features.id'], ondelete='CASCADE'),
210
+ sa.ForeignKeyConstraint(['feature_selection_id'], ['feature_selections.id'], ondelete='CASCADE'),
211
+ sa.PrimaryKeyConstraint('id'),
212
+ sa.UniqueConstraint('feature_id', 'feature_selection_id', 'method', name='uq_feature_selection_rank_composite')
213
+ )
214
+ op.create_index(op.f('ix_feature_selection_ranks_id'), 'feature_selection_ranks', ['id'], unique=False)
215
+ op.create_table('model_trainings',
216
+ sa.Column('id', sa.BigInteger(), autoincrement=True, nullable=False),
217
+ sa.Column('created_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
218
+ sa.Column('updated_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
219
+ sa.Column('best_params', sa.JSON(), nullable=True),
220
+ sa.Column('model_path', sa.String(length=255), nullable=True),
221
+ sa.Column('training_time', sa.Integer(), nullable=True),
222
+ sa.Column('model_id', sa.BigInteger(), nullable=False),
223
+ sa.Column('model_selection_id', sa.BigInteger(), nullable=False),
224
+ sa.ForeignKeyConstraint(['model_id'], ['models.id'], ),
225
+ sa.ForeignKeyConstraint(['model_selection_id'], ['model_selections.id'], ondelete='CASCADE'),
226
+ sa.PrimaryKeyConstraint('id'),
227
+ sa.UniqueConstraint('model_id', 'model_selection_id', name='uq_model_training_composite')
228
+ )
229
+ op.create_index(op.f('ix_model_trainings_id'), 'model_trainings', ['id'], unique=False)
230
+ op.create_table('scores',
231
+ sa.Column('id', sa.BigInteger(), autoincrement=True, nullable=False),
232
+ sa.Column('created_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
233
+ sa.Column('updated_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
234
+ sa.Column('type', sa.String(length=50), nullable=False),
235
+ sa.Column('training_time', sa.Integer(), nullable=True),
236
+ sa.Column('eval_data_std', sa.Float(), nullable=True),
237
+ sa.Column('rmse', sa.Float(), nullable=True),
238
+ sa.Column('rmse_std_ratio', sa.Float(), nullable=True),
239
+ sa.Column('mae', sa.Float(), nullable=True),
240
+ sa.Column('mape', sa.Float(), nullable=True),
241
+ sa.Column('mam', sa.Float(), nullable=True),
242
+ sa.Column('mad', sa.Float(), nullable=True),
243
+ sa.Column('mae_mam_ratio', sa.Float(), nullable=True),
244
+ sa.Column('mae_mad_ratio', sa.Float(), nullable=True),
245
+ sa.Column('r2', sa.Float(), nullable=True),
246
+ sa.Column('logloss', sa.Float(), nullable=True),
247
+ sa.Column('accuracy', sa.Float(), nullable=True),
248
+ sa.Column('precision', sa.Float(), nullable=True),
249
+ sa.Column('recall', sa.Float(), nullable=True),
250
+ sa.Column('f1', sa.Float(), nullable=True),
251
+ sa.Column('roc_auc', sa.Float(), nullable=True),
252
+ sa.Column('threshold', sa.Float(), nullable=True),
253
+ sa.Column('precision_at_threshold', sa.Float(), nullable=True),
254
+ sa.Column('recall_at_threshold', sa.Float(), nullable=True),
255
+ sa.Column('model_training_id', sa.BigInteger(), nullable=False),
256
+ sa.ForeignKeyConstraint(['model_training_id'], ['model_trainings.id'], ondelete='CASCADE'),
257
+ sa.PrimaryKeyConstraint('id')
258
+ )
259
+ op.create_index(op.f('ix_scores_id'), 'scores', ['id'], unique=False)
260
+ # ### end Alembic commands ###
261
+
262
+
263
+ def downgrade() -> None:
264
+ # ### commands auto generated by Alembic - please adjust! ###
265
+ op.drop_index(op.f('ix_scores_id'), table_name='scores')
266
+ op.drop_table('scores')
267
+ op.drop_index(op.f('ix_model_trainings_id'), table_name='model_trainings')
268
+ op.drop_table('model_trainings')
269
+ op.drop_index(op.f('ix_feature_selection_ranks_id'), table_name='feature_selection_ranks')
270
+ op.drop_table('feature_selection_ranks')
271
+ op.drop_table('feature_selection_association')
272
+ op.drop_index(op.f('ix_model_selections_id'), table_name='model_selections')
273
+ op.drop_table('model_selections')
274
+ op.drop_index(op.f('ix_feature_selections_id'), table_name='feature_selections')
275
+ op.drop_table('feature_selections')
276
+ op.drop_table('dataset_target_association')
277
+ op.drop_index(op.f('ix_transactions_id'), table_name='transactions')
278
+ op.drop_table('transactions')
279
+ op.drop_index(op.f('ix_targets_id'), table_name='targets')
280
+ op.drop_table('targets')
281
+ op.drop_index(op.f('ix_portfolios_id'), table_name='portfolios')
282
+ op.drop_table('portfolios')
283
+ op.drop_index(op.f('ix_operations_id'), table_name='operations')
284
+ op.drop_table('operations')
285
+ op.drop_index(op.f('ix_models_id'), table_name='models')
286
+ op.drop_table('models')
287
+ op.drop_index(op.f('ix_features_id'), table_name='features')
288
+ op.drop_table('features')
289
+ op.drop_index(op.f('ix_datasets_id'), table_name='datasets')
290
+ op.drop_table('datasets')
291
+ op.drop_index(op.f('ix_datas_stock'), table_name='datas')
292
+ op.drop_index(op.f('ix_datas_id'), table_name='datas')
293
+ op.drop_index(op.f('ix_datas_date'), table_name='datas')
294
+ op.drop_table('datas')
295
+ # ### end Alembic commands ###
@@ -0,0 +1,30 @@
1
+ """unique constraint for data
2
+
3
+ Revision ID: 40cd8d3e798e
4
+ Revises: 7390745388e4
5
+ Create Date: 2025-04-06 17:55:47.709956
6
+
7
+ """
8
+ from typing import Sequence, Union
9
+
10
+ from alembic import op
11
+ import sqlalchemy as sa
12
+
13
+
14
+ # revision identifiers, used by Alembic.
15
+ revision: str = '40cd8d3e798e'
16
+ down_revision: Union[str, None] = '7390745388e4'
17
+ branch_labels: Union[str, Sequence[str], None] = None
18
+ depends_on: Union[str, Sequence[str], None] = None
19
+
20
+
21
+ def upgrade() -> None:
22
+ # ### commands auto generated by Alembic - please adjust! ###
23
+ op.create_unique_constraint('uq_datas_composite', 'datas', ['date', 'stock'])
24
+ # ### end Alembic commands ###
25
+
26
+
27
+ def downgrade() -> None:
28
+ # ### commands auto generated by Alembic - please adjust! ###
29
+ op.drop_constraint('uq_datas_composite', 'datas', type_='unique')
30
+ # ### end Alembic commands ###
@@ -0,0 +1,52 @@
1
+ """longer_string
2
+
3
+ Revision ID: 2360941fa0bd
4
+ Revises: 40cd8d3e798e
5
+ Create Date: 2025-05-23 17:24:07.750472
6
+
7
+ """
8
+ from typing import Sequence, Union
9
+
10
+ from alembic import op
11
+ import sqlalchemy as sa
12
+ from sqlalchemy.dialects import mysql
13
+
14
+ # revision identifiers, used by Alembic.
15
+ revision: str = '2360941fa0bd'
16
+ down_revision: Union[str, None] = '40cd8d3e798e'
17
+ branch_labels: Union[str, Sequence[str], None] = None
18
+ depends_on: Union[str, Sequence[str], None] = None
19
+
20
+
21
+ def upgrade() -> None:
22
+ # ### commands auto generated by Alembic - please adjust! ###
23
+ op.alter_column('operations', 'why_buy',
24
+ existing_type=mysql.VARCHAR(length=50),
25
+ type_=sa.String(length=255),
26
+ existing_nullable=True)
27
+ op.alter_column('operations', 'why_sell',
28
+ existing_type=mysql.VARCHAR(length=50),
29
+ type_=sa.String(length=255),
30
+ existing_nullable=True)
31
+ op.alter_column('transactions', 'why',
32
+ existing_type=mysql.VARCHAR(length=50),
33
+ type_=sa.String(length=255),
34
+ existing_nullable=True)
35
+ # ### end Alembic commands ###
36
+
37
+
38
+ def downgrade() -> None:
39
+ # ### commands auto generated by Alembic - please adjust! ###
40
+ op.alter_column('transactions', 'why',
41
+ existing_type=sa.String(length=255),
42
+ type_=mysql.VARCHAR(length=50),
43
+ existing_nullable=True)
44
+ op.alter_column('operations', 'why_sell',
45
+ existing_type=sa.String(length=255),
46
+ type_=mysql.VARCHAR(length=50),
47
+ existing_nullable=True)
48
+ op.alter_column('operations', 'why_buy',
49
+ existing_type=sa.String(length=255),
50
+ type_=mysql.VARCHAR(length=50),
51
+ existing_nullable=True)
52
+ # ### end Alembic commands ###
@@ -0,0 +1,34 @@
1
+ """add_env_to_trading_tables
2
+
3
+ Revision ID: b96396dcfaff
4
+ Revises: 2360941fa0bd
5
+ Create Date: 2025-05-27 11:59:55.405410
6
+
7
+ """
8
+ from typing import Sequence, Union
9
+
10
+ from alembic import op
11
+ import sqlalchemy as sa
12
+
13
+
14
+ # revision identifiers, used by Alembic.
15
+ revision: str = 'b96396dcfaff'
16
+ down_revision: Union[str, None] = '2360941fa0bd'
17
+ branch_labels: Union[str, Sequence[str], None] = None
18
+ depends_on: Union[str, Sequence[str], None] = None
19
+
20
+
21
+ def upgrade() -> None:
22
+ # ### commands auto generated by Alembic - please adjust! ###
23
+ op.add_column('operations', sa.Column('env', sa.String(length=50), nullable=False))
24
+ op.add_column('portfolios', sa.Column('env', sa.String(length=50), nullable=False))
25
+ op.add_column('transactions', sa.Column('env', sa.String(length=50), nullable=False))
26
+ # ### end Alembic commands ###
27
+
28
+
29
+ def downgrade() -> None:
30
+ # ### commands auto generated by Alembic - please adjust! ###
31
+ op.drop_column('transactions', 'env')
32
+ op.drop_column('portfolios', 'env')
33
+ op.drop_column('operations', 'env')
34
+ # ### end Alembic commands ###
@@ -0,0 +1,39 @@
1
+ """fix_nb_character_on_portfolio
2
+
3
+
4
+ Revision ID: 40cbfc215f7c
5
+ Revises: b96396dcfaff
6
+ Create Date: 2025-05-27 13:37:18.291145
7
+
8
+ """
9
+ from typing import Sequence, Union
10
+
11
+ from alembic import op
12
+ import sqlalchemy as sa
13
+ from sqlalchemy.dialects import mysql
14
+
15
+ # revision identifiers, used by Alembic.
16
+ revision: str = '40cbfc215f7c'
17
+ down_revision: Union[str, None] = 'b96396dcfaff'
18
+ branch_labels: Union[str, Sequence[str], None] = None
19
+ depends_on: Union[str, Sequence[str], None] = None
20
+
21
+
22
+ def upgrade() -> None:
23
+ # ### commands auto generated by Alembic - please adjust! ###
24
+ op.alter_column('portfolios', 'why_buy',
25
+ existing_type=mysql.VARCHAR(length=50),
26
+ type_=sa.String(length=255),
27
+ existing_nullable=True)
28
+ op.create_unique_constraint('uq_portfolio_composite', 'portfolios', ['stock', 'env'])
29
+ # ### end Alembic commands ###
30
+
31
+
32
+ def downgrade() -> None:
33
+ # ### commands auto generated by Alembic - please adjust! ###
34
+ op.drop_constraint('uq_portfolio_composite', 'portfolios', type_='unique')
35
+ op.alter_column('portfolios', 'why_buy',
36
+ existing_type=sa.String(length=255),
37
+ type_=mysql.VARCHAR(length=50),
38
+ existing_nullable=True)
39
+ # ### end Alembic commands ###
@@ -0,0 +1,36 @@
1
+ """to_datetime
2
+
3
+ Revision ID: 3de994115317
4
+ Revises: 40cbfc215f7c
5
+ Create Date: 2025-05-27 15:26:01.669012
6
+
7
+ """
8
+ from typing import Sequence, Union
9
+
10
+ from alembic import op
11
+ import sqlalchemy as sa
12
+
13
+
14
+ # revision identifiers, used by Alembic.
15
+ revision: str = '3de994115317'
16
+ down_revision: Union[str, None] = '40cbfc215f7c'
17
+ branch_labels: Union[str, Sequence[str], None] = None
18
+ depends_on: Union[str, Sequence[str], None] = None
19
+
20
+
21
+ def upgrade() -> None:
22
+ # ### commands auto generated by Alembic - please adjust! ###
23
+ op.alter_column('transactions', 'date',
24
+ existing_type=sa.DATE(),
25
+ type_=sa.DateTime(),
26
+ existing_nullable=False)
27
+ # ### end Alembic commands ###
28
+
29
+
30
+ def downgrade() -> None:
31
+ # ### commands auto generated by Alembic - please adjust! ###
32
+ op.alter_column('transactions', 'date',
33
+ existing_type=sa.DateTime(),
34
+ type_=sa.DATE(),
35
+ existing_nullable=False)
36
+ # ### end Alembic commands ###
@@ -0,0 +1,30 @@
1
+ """add_fees_to_transactions
2
+
3
+ Revision ID: 25c227c684f8
4
+ Revises: 3de994115317
5
+ Create Date: 2025-05-27 20:03:08.193307
6
+
7
+ """
8
+ from typing import Sequence, Union
9
+
10
+ from alembic import op
11
+ import sqlalchemy as sa
12
+
13
+
14
+ # revision identifiers, used by Alembic.
15
+ revision: str = '25c227c684f8'
16
+ down_revision: Union[str, None] = '3de994115317'
17
+ branch_labels: Union[str, Sequence[str], None] = None
18
+ depends_on: Union[str, Sequence[str], None] = None
19
+
20
+
21
+ def upgrade() -> None:
22
+ # ### commands auto generated by Alembic - please adjust! ###
23
+ op.add_column('transactions', sa.Column('fees', sa.Float(), nullable=False))
24
+ # ### end Alembic commands ###
25
+
26
+
27
+ def downgrade() -> None:
28
+ # ### commands auto generated by Alembic - please adjust! ###
29
+ op.drop_column('transactions', 'fees')
30
+ # ### end Alembic commands ###