fg-strategy-modelling-core 0.1.0__tar.gz
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.
- fg_strategy_modelling_core-0.1.0/LICENSE +21 -0
- fg_strategy_modelling_core-0.1.0/MANIFEST.in +7 -0
- fg_strategy_modelling_core-0.1.0/PKG-INFO +274 -0
- fg_strategy_modelling_core-0.1.0/README.md +219 -0
- fg_strategy_modelling_core-0.1.0/fg_strategy_modelling_core.egg-info/PKG-INFO +274 -0
- fg_strategy_modelling_core-0.1.0/fg_strategy_modelling_core.egg-info/SOURCES.txt +127 -0
- fg_strategy_modelling_core-0.1.0/fg_strategy_modelling_core.egg-info/dependency_links.txt +1 -0
- fg_strategy_modelling_core-0.1.0/fg_strategy_modelling_core.egg-info/requires.txt +31 -0
- fg_strategy_modelling_core-0.1.0/fg_strategy_modelling_core.egg-info/top_level.txt +1 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/__init__.py +77 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/aux_model_manager.py +474 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/config.py +95 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/data_manager.py +260 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/dev_tools/features_importance.py +115 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/dev_tools/features_potential.py +291 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/dev_tools/get_target_statistics.py +88 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/dev_tools/nn_overfit_tester.py +328 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/dev_tools/train_xgboost_models.py +216 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/env_validator.py +147 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/indicators.py +187 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/main.py +96 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/models_architecture/__init__.py +24 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/models_architecture/base_model.py +106 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/models_architecture/base_xgb_model.py +463 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/models_architecture/kmeans_module.py +288 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/models_architecture/knn_model.py +166 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/models_architecture/no_train_model.py +141 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/models_architecture/train_models/__init__.py +22 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/models_architecture/train_models/base_train_model.py +669 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/models_architecture/train_models/cnn_bi_lstm.py +79 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/models_architecture/train_models/conservative_model.py +51 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/models_architecture/train_models/lstm_model.py +73 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/pipeline/__init__.py +37 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/pipeline/ensemble_pusher.py +297 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/pipeline/evaluator.py +66 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/pipeline/feature_selection.py +194 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/pipeline/generate_train_data.py +1021 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/pipeline/knn_trainer.py +149 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/pipeline/no_train_trainer.py +218 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/pipeline/performance_test.py +157 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/pipeline/preprocessing/__init__.py +17 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/pipeline/preprocessing/base_preprocessor.py +207 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/pipeline/preprocessing/example_preprocessor.py +30 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/pipeline/publish_no_train_model.py +48 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/pipeline/pusher.py +143 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/pipeline/statistics_gen.py +41 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/pipeline/train_publish_knn_models.py +48 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/pipeline/train_publish_nn_models.py +40 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/pipeline/train_publish_xgb_models.py +55 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/pipeline/trainer.py +364 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/pipeline/xgb_trainer.py +248 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/schemas.py +70 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/settings.py +171 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/storage/__init__.py +8 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/storage/base_client.py +164 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/storage/clients/__init__.py +11 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/storage/clients/aws_client.py +11 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/storage/clients/cloudflare_r2_client.py +24 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/storage/clients/google_s3_client.py +15 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/storage/clients/minio_client.py +15 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/storage/utils.py +31 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/utils/__init__.py +14 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/utils/benchmark.py +84 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/utils/fg_tester_client.py +33 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/utils/package_upload_xgb_model.py +1 -0
- fg_strategy_modelling_core-0.1.0/forexgrand_core/utils.py +6 -0
- fg_strategy_modelling_core-0.1.0/pyproject.toml +135 -0
- fg_strategy_modelling_core-0.1.0/requirements.txt +8 -0
- fg_strategy_modelling_core-0.1.0/setup.cfg +4 -0
- fg_strategy_modelling_core-0.1.0/setup.py +8 -0
- fg_strategy_modelling_core-0.1.0/tests/test_aux_model_manager.py +41 -0
- fg_strategy_modelling_core-0.1.0/tests/test_no_train_model.py +82 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ForexGrand Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fg-strategy-modelling-core
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: ForexGrand strategy modelling core library for ML model training on forex data
|
|
5
|
+
Author-email: ForexGrand Team <dev@forexgrand.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/forexgrand/fg-strategy-modelling-core
|
|
8
|
+
Project-URL: Repository, https://github.com/forexgrand/fg-strategy-modelling-core.git
|
|
9
|
+
Project-URL: Documentation, https://fg-strategy-modelling-core.readthedocs.io
|
|
10
|
+
Project-URL: Bug Tracker, https://github.com/forexgrand/fg-strategy-modelling-core/issues
|
|
11
|
+
Keywords: forex,machine-learning,deep-learning,tensorflow,trading,strategy,timeseries
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
15
|
+
Classifier: Natural Language :: English
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
23
|
+
Classifier: Topic :: Office/Business :: Financial
|
|
24
|
+
Requires-Python: >=3.9
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
License-File: LICENSE
|
|
27
|
+
Requires-Dist: setuptools<81.0,>=70.0
|
|
28
|
+
Requires-Dist: boto3<2.0.0,>=1.34.0
|
|
29
|
+
Requires-Dist: tensorflow<2.22.0,>=2.21.0
|
|
30
|
+
Requires-Dist: pydantic<3.0.0,>=2.0.0
|
|
31
|
+
Requires-Dist: keras<3.14.1,>=3.13.2
|
|
32
|
+
Requires-Dist: keras-tuner<2.0.0,>=1.4.7
|
|
33
|
+
Requires-Dist: xgboost-cpu<3.3.0,>=3.2.0
|
|
34
|
+
Requires-Dist: optuna<5.0.0,>=4.0.0
|
|
35
|
+
Requires-Dist: torch<2.20.0,>=2.10.0
|
|
36
|
+
Requires-Dist: shap<0.53.0,>=0.52.0
|
|
37
|
+
Requires-Dist: openfe<0.0.13,>=0.0.12
|
|
38
|
+
Requires-Dist: imbalanced-learn<0.15.0,>=0.14.2
|
|
39
|
+
Provides-Extra: dev
|
|
40
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
41
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
42
|
+
Requires-Dist: black>=23.0.0; extra == "dev"
|
|
43
|
+
Requires-Dist: isort>=5.12.0; extra == "dev"
|
|
44
|
+
Requires-Dist: flake8>=6.0.0; extra == "dev"
|
|
45
|
+
Requires-Dist: mypy>=1.0.0; extra == "dev"
|
|
46
|
+
Requires-Dist: sphinx>=6.0.0; extra == "dev"
|
|
47
|
+
Requires-Dist: sphinx-rtd-theme>=1.2.0; extra == "dev"
|
|
48
|
+
Provides-Extra: aws
|
|
49
|
+
Requires-Dist: boto3<2.0.0,>=1.34.0; extra == "aws"
|
|
50
|
+
Provides-Extra: gcs
|
|
51
|
+
Requires-Dist: google-cloud-storage>=2.10.0; extra == "gcs"
|
|
52
|
+
Provides-Extra: cloudflare
|
|
53
|
+
Requires-Dist: boto3<2.0.0,>=1.34.0; extra == "cloudflare"
|
|
54
|
+
Dynamic: license-file
|
|
55
|
+
|
|
56
|
+
# ForexGrand Strategy Modelling Core
|
|
57
|
+
|
|
58
|
+
ForexGrand Strategy Modelling Core is a Python package for building forex strategy modelling workflows. It includes utilities for loading market data from Cloudflare R2, generating technical indicators, preparing TFRecord datasets, training models, evaluating model quality, and packaging trained models for deployment.
|
|
59
|
+
|
|
60
|
+
The distribution name is `fg-strategy-modelling-core`; the Python import package is `forexgrand_core`.
|
|
61
|
+
|
|
62
|
+
## Features
|
|
63
|
+
|
|
64
|
+
- Cloudflare R2-backed storage access through the S3-compatible API.
|
|
65
|
+
- A runtime configuration helper so users do not have to manually export environment variables.
|
|
66
|
+
- Data loading and local caching for symbol market data.
|
|
67
|
+
- TensorFlow-based technical indicators for feature engineering.
|
|
68
|
+
- Dataset generation utilities for train, evaluation, and test workflows.
|
|
69
|
+
- Training pipelines for neural-network, KNN, XGBoost, and no-train target models.
|
|
70
|
+
- Model evaluation, performance checks, and model publishing helpers.
|
|
71
|
+
- Extensible preprocessing classes for custom feature pipelines.
|
|
72
|
+
|
|
73
|
+
## Installation
|
|
74
|
+
|
|
75
|
+
Install from PyPI:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
pip install fg-strategy-modelling-core
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Install from source for development:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
git clone https://github.com/forexgrand/fg-strategy-modelling-core.git
|
|
85
|
+
cd fg-strategy-modelling-core
|
|
86
|
+
pip install -e ".[dev]"
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Configure Cloudflare R2
|
|
90
|
+
|
|
91
|
+
The package currently supports Cloudflare R2 storage. Configure it at the start of your script with `configure_r2`:
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
from forexgrand_core import configure_r2
|
|
95
|
+
|
|
96
|
+
settings = configure_r2(
|
|
97
|
+
account_id="your-cloudflare-account-id",
|
|
98
|
+
access_key_id="your-r2-access-key-id",
|
|
99
|
+
secret_access_key="your-r2-secret-access-key",
|
|
100
|
+
bucket_name="forexgrand-data",
|
|
101
|
+
train_bucket_name="forexgrand-train",
|
|
102
|
+
eval_bucket_name="forexgrand-eval",
|
|
103
|
+
test_bucket_name="forexgrand-test",
|
|
104
|
+
model_upload_bucket="forexgrand-models",
|
|
105
|
+
)
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
You can pass `endpoint="https://<account-id>.r2.cloudflarestorage.com"` instead of `account_id` if you already have the full endpoint.
|
|
109
|
+
|
|
110
|
+
`configure_r2` sets these environment variables for the current Python process and returns a fresh `Settings` object:
|
|
111
|
+
|
|
112
|
+
| Variable | Purpose |
|
|
113
|
+
| --- | --- |
|
|
114
|
+
| `S3_STORAGE_OPTION` | Always set to `cloudflare` |
|
|
115
|
+
| `S3_ENDPOINT` | Cloudflare R2 S3 API endpoint |
|
|
116
|
+
| `S3_ACCESS_KEY` | R2 access key ID |
|
|
117
|
+
| `S3_SECRET_KEY` | R2 secret access key |
|
|
118
|
+
| `S3_REGION_NAME` | R2 region, defaults to `auto` |
|
|
119
|
+
| `S3_BUCKET_NAME` | Main data bucket |
|
|
120
|
+
| `TRAIN_BUCKET_NAME` | Training dataset bucket |
|
|
121
|
+
| `EVAL_BUCKET_NAME` | Evaluation dataset bucket |
|
|
122
|
+
| `TEST_BUCKET_NAME` | Test dataset bucket |
|
|
123
|
+
| `MODEL_UPLOAD_BUCKET` | Trained model upload bucket |
|
|
124
|
+
|
|
125
|
+
If bucket-specific names are omitted, `bucket_name` is reused for all buckets.
|
|
126
|
+
|
|
127
|
+
## Load Market Data
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
from forexgrand_core import configure_r2
|
|
131
|
+
from forexgrand_core.data_manager import DataManager
|
|
132
|
+
|
|
133
|
+
configure_r2(
|
|
134
|
+
account_id="your-cloudflare-account-id",
|
|
135
|
+
access_key_id="your-r2-access-key-id",
|
|
136
|
+
secret_access_key="your-r2-secret-access-key",
|
|
137
|
+
bucket_name="forexgrand-data",
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
manager = DataManager(base_bucket_name="forexgrand-data")
|
|
141
|
+
df, properties = manager.load_data(
|
|
142
|
+
symbol_pair="EURUSD",
|
|
143
|
+
instrument_group="forex",
|
|
144
|
+
)
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Use Technical Indicators
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
from forexgrand_core.indicators import tf_atr, tf_ma, tf_rsi
|
|
151
|
+
|
|
152
|
+
df["MA_20"] = tf_ma(df, period=20, column="close")
|
|
153
|
+
df["ATR_14"] = tf_atr(df, period=14)
|
|
154
|
+
df["RSI_14"] = tf_rsi(df, period=14, column="close")
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Available indicators include moving average, slope, ATR, RSI, standard deviation, Bollinger Bands, Garman-Klass volatility, wick-to-range ratio, and normalization helpers.
|
|
158
|
+
|
|
159
|
+
## Train Models
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
from forexgrand_core import configure_r2
|
|
163
|
+
from forexgrand_core.main import run_training
|
|
164
|
+
from forexgrand_core.pipeline.preprocessing.example_preprocessor import ExamplePreprocessor
|
|
165
|
+
|
|
166
|
+
configure_r2(
|
|
167
|
+
account_id="your-cloudflare-account-id",
|
|
168
|
+
access_key_id="your-r2-access-key-id",
|
|
169
|
+
secret_access_key="your-r2-secret-access-key",
|
|
170
|
+
bucket_name="forexgrand-data",
|
|
171
|
+
model_upload_bucket="forexgrand-models",
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
results = run_training(
|
|
175
|
+
symbols=["EURUSD", "GBPUSD", "USDJPY"],
|
|
176
|
+
model_types=["conservative", "simple", "complex"],
|
|
177
|
+
preprocessor_class=ExamplePreprocessor,
|
|
178
|
+
sequence_length=60,
|
|
179
|
+
)
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## Custom Preprocessing
|
|
183
|
+
|
|
184
|
+
Create your own preprocessing class by extending `PreprocessBase`:
|
|
185
|
+
|
|
186
|
+
```python
|
|
187
|
+
from forexgrand_core.pipeline.preprocessing.base_preprocessor import PreprocessBase
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
class MyPreprocessor(PreprocessBase):
|
|
191
|
+
def preprocess(self, inputs, training: bool = False):
|
|
192
|
+
return inputs
|
|
193
|
+
|
|
194
|
+
def features_metadata(self):
|
|
195
|
+
return {}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
Use the class in the training pipeline:
|
|
199
|
+
|
|
200
|
+
```python
|
|
201
|
+
results = run_training(
|
|
202
|
+
symbols=["EURUSD"],
|
|
203
|
+
model_types=["simple"],
|
|
204
|
+
preprocessor_class=MyPreprocessor,
|
|
205
|
+
sequence_length=60,
|
|
206
|
+
)
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Validate Configuration
|
|
210
|
+
|
|
211
|
+
Configuration is not validated on package import, so `import forexgrand_core` works before credentials are available. Validate explicitly when you want a clear setup error:
|
|
212
|
+
|
|
213
|
+
```python
|
|
214
|
+
from forexgrand_core.env_validator import validate_environment_on_import
|
|
215
|
+
|
|
216
|
+
validate_environment_on_import()
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Build And Publish To PyPI
|
|
220
|
+
|
|
221
|
+
Install build tools:
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
python -m pip install --upgrade build twine
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
Build the source distribution and wheel:
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
python -m build
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
Check the package:
|
|
234
|
+
|
|
235
|
+
```bash
|
|
236
|
+
python -m twine check dist/*
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
Upload to TestPyPI first:
|
|
240
|
+
|
|
241
|
+
```bash
|
|
242
|
+
python -m twine upload --repository testpypi dist/*
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
Upload to PyPI:
|
|
246
|
+
|
|
247
|
+
```bash
|
|
248
|
+
python -m twine upload dist/*
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
## Development
|
|
252
|
+
|
|
253
|
+
Run tests:
|
|
254
|
+
|
|
255
|
+
```bash
|
|
256
|
+
pytest
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
Build locally:
|
|
260
|
+
|
|
261
|
+
```bash
|
|
262
|
+
python -m build
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
Check imports:
|
|
266
|
+
|
|
267
|
+
```python
|
|
268
|
+
import forexgrand_core
|
|
269
|
+
from forexgrand_core import configure_r2, Settings
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
## License
|
|
273
|
+
|
|
274
|
+
MIT
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
# ForexGrand Strategy Modelling Core
|
|
2
|
+
|
|
3
|
+
ForexGrand Strategy Modelling Core is a Python package for building forex strategy modelling workflows. It includes utilities for loading market data from Cloudflare R2, generating technical indicators, preparing TFRecord datasets, training models, evaluating model quality, and packaging trained models for deployment.
|
|
4
|
+
|
|
5
|
+
The distribution name is `fg-strategy-modelling-core`; the Python import package is `forexgrand_core`.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- Cloudflare R2-backed storage access through the S3-compatible API.
|
|
10
|
+
- A runtime configuration helper so users do not have to manually export environment variables.
|
|
11
|
+
- Data loading and local caching for symbol market data.
|
|
12
|
+
- TensorFlow-based technical indicators for feature engineering.
|
|
13
|
+
- Dataset generation utilities for train, evaluation, and test workflows.
|
|
14
|
+
- Training pipelines for neural-network, KNN, XGBoost, and no-train target models.
|
|
15
|
+
- Model evaluation, performance checks, and model publishing helpers.
|
|
16
|
+
- Extensible preprocessing classes for custom feature pipelines.
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
Install from PyPI:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install fg-strategy-modelling-core
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Install from source for development:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
git clone https://github.com/forexgrand/fg-strategy-modelling-core.git
|
|
30
|
+
cd fg-strategy-modelling-core
|
|
31
|
+
pip install -e ".[dev]"
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Configure Cloudflare R2
|
|
35
|
+
|
|
36
|
+
The package currently supports Cloudflare R2 storage. Configure it at the start of your script with `configure_r2`:
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
from forexgrand_core import configure_r2
|
|
40
|
+
|
|
41
|
+
settings = configure_r2(
|
|
42
|
+
account_id="your-cloudflare-account-id",
|
|
43
|
+
access_key_id="your-r2-access-key-id",
|
|
44
|
+
secret_access_key="your-r2-secret-access-key",
|
|
45
|
+
bucket_name="forexgrand-data",
|
|
46
|
+
train_bucket_name="forexgrand-train",
|
|
47
|
+
eval_bucket_name="forexgrand-eval",
|
|
48
|
+
test_bucket_name="forexgrand-test",
|
|
49
|
+
model_upload_bucket="forexgrand-models",
|
|
50
|
+
)
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
You can pass `endpoint="https://<account-id>.r2.cloudflarestorage.com"` instead of `account_id` if you already have the full endpoint.
|
|
54
|
+
|
|
55
|
+
`configure_r2` sets these environment variables for the current Python process and returns a fresh `Settings` object:
|
|
56
|
+
|
|
57
|
+
| Variable | Purpose |
|
|
58
|
+
| --- | --- |
|
|
59
|
+
| `S3_STORAGE_OPTION` | Always set to `cloudflare` |
|
|
60
|
+
| `S3_ENDPOINT` | Cloudflare R2 S3 API endpoint |
|
|
61
|
+
| `S3_ACCESS_KEY` | R2 access key ID |
|
|
62
|
+
| `S3_SECRET_KEY` | R2 secret access key |
|
|
63
|
+
| `S3_REGION_NAME` | R2 region, defaults to `auto` |
|
|
64
|
+
| `S3_BUCKET_NAME` | Main data bucket |
|
|
65
|
+
| `TRAIN_BUCKET_NAME` | Training dataset bucket |
|
|
66
|
+
| `EVAL_BUCKET_NAME` | Evaluation dataset bucket |
|
|
67
|
+
| `TEST_BUCKET_NAME` | Test dataset bucket |
|
|
68
|
+
| `MODEL_UPLOAD_BUCKET` | Trained model upload bucket |
|
|
69
|
+
|
|
70
|
+
If bucket-specific names are omitted, `bucket_name` is reused for all buckets.
|
|
71
|
+
|
|
72
|
+
## Load Market Data
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
from forexgrand_core import configure_r2
|
|
76
|
+
from forexgrand_core.data_manager import DataManager
|
|
77
|
+
|
|
78
|
+
configure_r2(
|
|
79
|
+
account_id="your-cloudflare-account-id",
|
|
80
|
+
access_key_id="your-r2-access-key-id",
|
|
81
|
+
secret_access_key="your-r2-secret-access-key",
|
|
82
|
+
bucket_name="forexgrand-data",
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
manager = DataManager(base_bucket_name="forexgrand-data")
|
|
86
|
+
df, properties = manager.load_data(
|
|
87
|
+
symbol_pair="EURUSD",
|
|
88
|
+
instrument_group="forex",
|
|
89
|
+
)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Use Technical Indicators
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
from forexgrand_core.indicators import tf_atr, tf_ma, tf_rsi
|
|
96
|
+
|
|
97
|
+
df["MA_20"] = tf_ma(df, period=20, column="close")
|
|
98
|
+
df["ATR_14"] = tf_atr(df, period=14)
|
|
99
|
+
df["RSI_14"] = tf_rsi(df, period=14, column="close")
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Available indicators include moving average, slope, ATR, RSI, standard deviation, Bollinger Bands, Garman-Klass volatility, wick-to-range ratio, and normalization helpers.
|
|
103
|
+
|
|
104
|
+
## Train Models
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
from forexgrand_core import configure_r2
|
|
108
|
+
from forexgrand_core.main import run_training
|
|
109
|
+
from forexgrand_core.pipeline.preprocessing.example_preprocessor import ExamplePreprocessor
|
|
110
|
+
|
|
111
|
+
configure_r2(
|
|
112
|
+
account_id="your-cloudflare-account-id",
|
|
113
|
+
access_key_id="your-r2-access-key-id",
|
|
114
|
+
secret_access_key="your-r2-secret-access-key",
|
|
115
|
+
bucket_name="forexgrand-data",
|
|
116
|
+
model_upload_bucket="forexgrand-models",
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
results = run_training(
|
|
120
|
+
symbols=["EURUSD", "GBPUSD", "USDJPY"],
|
|
121
|
+
model_types=["conservative", "simple", "complex"],
|
|
122
|
+
preprocessor_class=ExamplePreprocessor,
|
|
123
|
+
sequence_length=60,
|
|
124
|
+
)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Custom Preprocessing
|
|
128
|
+
|
|
129
|
+
Create your own preprocessing class by extending `PreprocessBase`:
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
from forexgrand_core.pipeline.preprocessing.base_preprocessor import PreprocessBase
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
class MyPreprocessor(PreprocessBase):
|
|
136
|
+
def preprocess(self, inputs, training: bool = False):
|
|
137
|
+
return inputs
|
|
138
|
+
|
|
139
|
+
def features_metadata(self):
|
|
140
|
+
return {}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Use the class in the training pipeline:
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
results = run_training(
|
|
147
|
+
symbols=["EURUSD"],
|
|
148
|
+
model_types=["simple"],
|
|
149
|
+
preprocessor_class=MyPreprocessor,
|
|
150
|
+
sequence_length=60,
|
|
151
|
+
)
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Validate Configuration
|
|
155
|
+
|
|
156
|
+
Configuration is not validated on package import, so `import forexgrand_core` works before credentials are available. Validate explicitly when you want a clear setup error:
|
|
157
|
+
|
|
158
|
+
```python
|
|
159
|
+
from forexgrand_core.env_validator import validate_environment_on_import
|
|
160
|
+
|
|
161
|
+
validate_environment_on_import()
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Build And Publish To PyPI
|
|
165
|
+
|
|
166
|
+
Install build tools:
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
python -m pip install --upgrade build twine
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Build the source distribution and wheel:
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
python -m build
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Check the package:
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
python -m twine check dist/*
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
Upload to TestPyPI first:
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
python -m twine upload --repository testpypi dist/*
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Upload to PyPI:
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
python -m twine upload dist/*
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## Development
|
|
197
|
+
|
|
198
|
+
Run tests:
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
pytest
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
Build locally:
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
python -m build
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
Check imports:
|
|
211
|
+
|
|
212
|
+
```python
|
|
213
|
+
import forexgrand_core
|
|
214
|
+
from forexgrand_core import configure_r2, Settings
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## License
|
|
218
|
+
|
|
219
|
+
MIT
|