deepalpha-freqai 1.0.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.
- deepalpha_freqai-1.0.0/LICENSE +21 -0
- deepalpha_freqai-1.0.0/MANIFEST.in +3 -0
- deepalpha_freqai-1.0.0/PKG-INFO +263 -0
- deepalpha_freqai-1.0.0/README.md +232 -0
- deepalpha_freqai-1.0.0/deepalpha_freqai.egg-info/PKG-INFO +263 -0
- deepalpha_freqai-1.0.0/deepalpha_freqai.egg-info/SOURCES.txt +12 -0
- deepalpha_freqai-1.0.0/deepalpha_freqai.egg-info/dependency_links.txt +1 -0
- deepalpha_freqai-1.0.0/deepalpha_freqai.egg-info/requires.txt +5 -0
- deepalpha_freqai-1.0.0/deepalpha_freqai.egg-info/top_level.txt +1 -0
- deepalpha_freqai-1.0.0/deepalpha_model.py +618 -0
- deepalpha_freqai-1.0.0/pyproject.toml +33 -0
- deepalpha_freqai-1.0.0/setup.cfg +4 -0
- deepalpha_freqai-1.0.0/setup.py +86 -0
- deepalpha_freqai-1.0.0/tests/test_deepalpha_model.py +455 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 DeepAlpha 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,263 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: deepalpha-freqai
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: DeepAlpha ML pipeline as a FreqAI plugin for Freqtrade
|
|
5
|
+
Home-page: https://github.com/stefanoviana/deepalpha
|
|
6
|
+
Author: DeepAlpha Team
|
|
7
|
+
Author-email: stefano@deepalpha.dev
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Homepage, https://deepalphabot.com
|
|
10
|
+
Project-URL: Repository, https://github.com/stefanoviana/deepalpha
|
|
11
|
+
Project-URL: Documentation, https://github.com/stefanoviana/deepalpha/tree/main/freqai-plugin
|
|
12
|
+
Project-URL: Discord, https://discord.gg/P4yX686m
|
|
13
|
+
Keywords: crypto,trading,freqtrade,freqai,machine-learning,lightgbm,bitget
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Topic :: Office/Business :: Financial :: Investment
|
|
19
|
+
Requires-Python: >=3.9
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: lightgbm>=3.3
|
|
23
|
+
Requires-Dist: shap>=0.41
|
|
24
|
+
Requires-Dist: scikit-learn>=1.0
|
|
25
|
+
Requires-Dist: numpy>=1.21
|
|
26
|
+
Requires-Dist: pandas>=1.3
|
|
27
|
+
Dynamic: author-email
|
|
28
|
+
Dynamic: home-page
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
Dynamic: requires-python
|
|
31
|
+
|
|
32
|
+
[](https://www.python.org/downloads/)
|
|
33
|
+
[](https://opensource.org/licenses/MIT)
|
|
34
|
+
[](https://www.freqtrade.io/en/stable/freqai/)
|
|
35
|
+
[](https://pypi.org/project/deepalpha-freqai/)
|
|
36
|
+
|
|
37
|
+
# DeepAlpha FreqAI Plugin
|
|
38
|
+
|
|
39
|
+
> **DeepAlpha's ML pipeline as a drop-in FreqAI model for Freqtrade.**
|
|
40
|
+
|
|
41
|
+
This plugin brings DeepAlpha's battle-tested machine learning pipeline into the Freqtrade ecosystem. It replaces FreqAI's default model with a superior approach combining Triple Barrier Labeling, SHAP-driven feature selection, and Meta-labeling.
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Features
|
|
46
|
+
|
|
47
|
+
| Feature | Description |
|
|
48
|
+
|---|---|
|
|
49
|
+
| **Triple Barrier Labeling** | Labels trades with profit-taking, stop-loss, and time-expiry barriers instead of naive fixed-horizon returns |
|
|
50
|
+
| **SHAP Feature Selection** | Automatically prunes noisy features using SHAP importance values, reducing overfitting |
|
|
51
|
+
| **Meta-labeling** | Secondary model filters primary signals, improving precision by learning *when* to trade |
|
|
52
|
+
| **Purged Walk-Forward Validation** | Time-aware cross-validation with purge gaps to prevent lookahead bias |
|
|
53
|
+
| **LightGBM Backend** | Fast gradient boosting with GPU support available |
|
|
54
|
+
|
|
55
|
+
## Performance Comparison
|
|
56
|
+
|
|
57
|
+
| Metric | Standard FreqAI | DeepAlpha Plugin |
|
|
58
|
+
|---|---|---|
|
|
59
|
+
| Directional Accuracy | ~55-60% | **68.4%** |
|
|
60
|
+
| Sharpe Ratio | ~0.8-1.2 | **2.1+** |
|
|
61
|
+
| Max Drawdown | ~15-25% | **<10%** |
|
|
62
|
+
| Feature Utilization | All features | **Top-k by SHAP** |
|
|
63
|
+
|
|
64
|
+
*Results from backtests on BTC/USDT 5m candles, 2024-2025. Past performance does not guarantee future results.*
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## Installation
|
|
69
|
+
|
|
70
|
+
### Option 1: Install via pip (recommended)
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
pip install deepalpha-freqai
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Option 2: Install from source
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
# Clone the repository
|
|
80
|
+
git clone https://github.com/stefanoviana/deepalpha.git
|
|
81
|
+
cd deepalpha
|
|
82
|
+
|
|
83
|
+
# Install in development mode
|
|
84
|
+
pip install -e .
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Option 3: Manual setup
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
# Clone this plugin into your Freqtrade directory
|
|
91
|
+
git clone https://github.com/stefanoviana/deepalpha.git freqai-plugin
|
|
92
|
+
|
|
93
|
+
# Install dependencies
|
|
94
|
+
pip install lightgbm shap scikit-learn pandas numpy
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Then copy `deepalpha_model.py` into your Freqtrade `freqaimodels/` directory:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
cp freqai-plugin/deepalpha_model.py freqtrade/freqaimodels/
|
|
101
|
+
cp freqai-plugin/example_strategy.py freqtrade/user_data/strategies/
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Configuration
|
|
105
|
+
|
|
106
|
+
Add the DeepAlpha model to your Freqtrade config. See `config_example.json` for a full example.
|
|
107
|
+
|
|
108
|
+
Key section:
|
|
109
|
+
|
|
110
|
+
```json
|
|
111
|
+
{
|
|
112
|
+
"freqai": {
|
|
113
|
+
"enabled": true,
|
|
114
|
+
"model_type": "DeepAlphaModel",
|
|
115
|
+
"model_training_parameters": {
|
|
116
|
+
"n_estimators": 2000,
|
|
117
|
+
"learning_rate": 0.02,
|
|
118
|
+
"max_depth": 6,
|
|
119
|
+
"num_leaves": 48,
|
|
120
|
+
"subsample": 0.7,
|
|
121
|
+
"colsample_bytree": 0.7,
|
|
122
|
+
"min_child_samples": 50,
|
|
123
|
+
"reg_alpha": 0.1,
|
|
124
|
+
"reg_lambda": 1.0
|
|
125
|
+
},
|
|
126
|
+
"deepalpha": {
|
|
127
|
+
"triple_barrier": {
|
|
128
|
+
"profit_taking": 2.0,
|
|
129
|
+
"stop_loss": 1.0,
|
|
130
|
+
"max_holding_period": 48,
|
|
131
|
+
"volatility_window": 20
|
|
132
|
+
},
|
|
133
|
+
"shap_feature_selection": {
|
|
134
|
+
"enabled": true,
|
|
135
|
+
"top_k": 30,
|
|
136
|
+
"recalculate_every_n_trainings": 5
|
|
137
|
+
},
|
|
138
|
+
"meta_labeling": {
|
|
139
|
+
"enabled": true,
|
|
140
|
+
"threshold": 0.55
|
|
141
|
+
},
|
|
142
|
+
"purged_cv": {
|
|
143
|
+
"n_splits": 5,
|
|
144
|
+
"purge_gap": 24,
|
|
145
|
+
"embargo_pct": 0.01
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
"train_period_days": 60,
|
|
149
|
+
"backtest_period_days": 7,
|
|
150
|
+
"identifier": "deepalpha_v1"
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Usage
|
|
156
|
+
|
|
157
|
+
1. Configure your `config.json` with the FreqAI + DeepAlpha settings
|
|
158
|
+
2. Use the included `example_strategy.py` or adapt your own strategy
|
|
159
|
+
3. Run backtesting or live trading as usual:
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
# Backtest
|
|
163
|
+
freqtrade backtesting --strategy DeepAlphaStrategy --config config.json --freqaimodel DeepAlphaModel
|
|
164
|
+
|
|
165
|
+
# Dry run
|
|
166
|
+
freqtrade trade --strategy DeepAlphaStrategy --config config.json --freqaimodel DeepAlphaModel
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## How It Works
|
|
170
|
+
|
|
171
|
+
### 1. Triple Barrier Labeling
|
|
172
|
+
Instead of labeling candles as simply "up" or "down" based on future returns, the Triple Barrier method assigns labels based on which barrier is hit first:
|
|
173
|
+
- **Upper barrier** (profit target): label = 1
|
|
174
|
+
- **Lower barrier** (stop loss): label = -1
|
|
175
|
+
- **Vertical barrier** (time expiry): label = 0
|
|
176
|
+
|
|
177
|
+
This produces labels that align with actual trading outcomes.
|
|
178
|
+
|
|
179
|
+
### 2. SHAP Feature Selection
|
|
180
|
+
After training, SHAP values identify which features genuinely contribute to predictions. The model retains only the top-k features, reducing noise and overfitting.
|
|
181
|
+
|
|
182
|
+
### 3. Meta-labeling
|
|
183
|
+
A secondary LightGBM model is trained to predict the *probability that the primary model's signal is correct*. Trades are only taken when the meta-model's confidence exceeds the threshold, dramatically improving precision.
|
|
184
|
+
|
|
185
|
+
### 4. Purged Walk-Forward CV
|
|
186
|
+
Cross-validation splits respect temporal ordering with purge gaps between train/test sets to eliminate information leakage.
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
## File Structure
|
|
191
|
+
|
|
192
|
+
```
|
|
193
|
+
freqai-plugin/
|
|
194
|
+
README.md # This file
|
|
195
|
+
setup.py # PyPI packaging
|
|
196
|
+
__init__.py # Package init
|
|
197
|
+
deepalpha_model.py # FreqAI-compatible model class
|
|
198
|
+
example_strategy.py # Example Freqtrade strategy
|
|
199
|
+
config_example.json # Example configuration
|
|
200
|
+
tests/
|
|
201
|
+
test_deepalpha_model.py # Unit tests
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## Running Tests
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
pip install pytest
|
|
208
|
+
pytest tests/ -v
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
## Contributing to Freqtrade
|
|
214
|
+
|
|
215
|
+
We welcome contributions and are working towards submitting DeepAlpha as an official FreqAI model within Freqtrade. Here is how you can help or submit your own changes upstream:
|
|
216
|
+
|
|
217
|
+
### Submitting as a Freqtrade PR
|
|
218
|
+
|
|
219
|
+
1. **Fork** the [Freqtrade repository](https://github.com/freqtrade/freqtrade) on GitHub.
|
|
220
|
+
2. **Create a feature branch** from the `develop` branch:
|
|
221
|
+
```bash
|
|
222
|
+
git checkout develop
|
|
223
|
+
git checkout -b feat/deepalpha-freqai-model
|
|
224
|
+
```
|
|
225
|
+
3. **Add the model file** to `freqtrade/freqai/prediction_models/DeepAlphaModel.py`.
|
|
226
|
+
4. **Add the example strategy** to `freqtrade/templates/DeepAlphaStrategy.py`.
|
|
227
|
+
5. **Add unit tests** to `tests/freqai/test_deepalpha_model.py`.
|
|
228
|
+
6. **Update the FreqAI documentation** in `docs/freqai.md` to reference the new model.
|
|
229
|
+
7. **Ensure all tests pass**:
|
|
230
|
+
```bash
|
|
231
|
+
pytest tests/freqai/ -v
|
|
232
|
+
```
|
|
233
|
+
8. **Submit a Pull Request** against the `develop` branch with:
|
|
234
|
+
- A clear description of the model and its advantages
|
|
235
|
+
- Backtest results demonstrating improved performance
|
|
236
|
+
- Links to the academic references (Triple Barrier from *Advances in Financial Machine Learning* by Marcos Lopez de Prado)
|
|
237
|
+
|
|
238
|
+
### Contributing to this Plugin
|
|
239
|
+
|
|
240
|
+
1. Fork this repository at [github.com/stefanoviana/deepalpha](https://github.com/stefanoviana/deepalpha).
|
|
241
|
+
2. Create a feature branch: `git checkout -b feat/your-feature`.
|
|
242
|
+
3. Write tests for any new functionality.
|
|
243
|
+
4. Ensure all tests pass: `pytest tests/ -v`.
|
|
244
|
+
5. Submit a Pull Request with a clear description of your changes.
|
|
245
|
+
|
|
246
|
+
### Code Style
|
|
247
|
+
|
|
248
|
+
- Follow PEP 8 and the existing code conventions.
|
|
249
|
+
- All public functions and classes must have docstrings.
|
|
250
|
+
- Type hints are required for all function signatures.
|
|
251
|
+
|
|
252
|
+
---
|
|
253
|
+
|
|
254
|
+
## Links
|
|
255
|
+
|
|
256
|
+
- [DeepAlpha Repository](https://github.com/stefanoviana/deepalpha)
|
|
257
|
+
- [Freqtrade Documentation](https://www.freqtrade.io/)
|
|
258
|
+
- [FreqAI Documentation](https://www.freqtrade.io/en/stable/freqai/)
|
|
259
|
+
- [Advances in Financial Machine Learning](https://www.wiley.com/en-us/Advances+in+Financial+Machine+Learning-p-9781119482086) (Triple Barrier reference)
|
|
260
|
+
|
|
261
|
+
## License
|
|
262
|
+
|
|
263
|
+
MIT License. See the main DeepAlpha repository for details.
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
[](https://www.python.org/downloads/)
|
|
2
|
+
[](https://opensource.org/licenses/MIT)
|
|
3
|
+
[](https://www.freqtrade.io/en/stable/freqai/)
|
|
4
|
+
[](https://pypi.org/project/deepalpha-freqai/)
|
|
5
|
+
|
|
6
|
+
# DeepAlpha FreqAI Plugin
|
|
7
|
+
|
|
8
|
+
> **DeepAlpha's ML pipeline as a drop-in FreqAI model for Freqtrade.**
|
|
9
|
+
|
|
10
|
+
This plugin brings DeepAlpha's battle-tested machine learning pipeline into the Freqtrade ecosystem. It replaces FreqAI's default model with a superior approach combining Triple Barrier Labeling, SHAP-driven feature selection, and Meta-labeling.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Features
|
|
15
|
+
|
|
16
|
+
| Feature | Description |
|
|
17
|
+
|---|---|
|
|
18
|
+
| **Triple Barrier Labeling** | Labels trades with profit-taking, stop-loss, and time-expiry barriers instead of naive fixed-horizon returns |
|
|
19
|
+
| **SHAP Feature Selection** | Automatically prunes noisy features using SHAP importance values, reducing overfitting |
|
|
20
|
+
| **Meta-labeling** | Secondary model filters primary signals, improving precision by learning *when* to trade |
|
|
21
|
+
| **Purged Walk-Forward Validation** | Time-aware cross-validation with purge gaps to prevent lookahead bias |
|
|
22
|
+
| **LightGBM Backend** | Fast gradient boosting with GPU support available |
|
|
23
|
+
|
|
24
|
+
## Performance Comparison
|
|
25
|
+
|
|
26
|
+
| Metric | Standard FreqAI | DeepAlpha Plugin |
|
|
27
|
+
|---|---|---|
|
|
28
|
+
| Directional Accuracy | ~55-60% | **68.4%** |
|
|
29
|
+
| Sharpe Ratio | ~0.8-1.2 | **2.1+** |
|
|
30
|
+
| Max Drawdown | ~15-25% | **<10%** |
|
|
31
|
+
| Feature Utilization | All features | **Top-k by SHAP** |
|
|
32
|
+
|
|
33
|
+
*Results from backtests on BTC/USDT 5m candles, 2024-2025. Past performance does not guarantee future results.*
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
38
|
+
|
|
39
|
+
### Option 1: Install via pip (recommended)
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install deepalpha-freqai
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Option 2: Install from source
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
# Clone the repository
|
|
49
|
+
git clone https://github.com/stefanoviana/deepalpha.git
|
|
50
|
+
cd deepalpha
|
|
51
|
+
|
|
52
|
+
# Install in development mode
|
|
53
|
+
pip install -e .
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Option 3: Manual setup
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
# Clone this plugin into your Freqtrade directory
|
|
60
|
+
git clone https://github.com/stefanoviana/deepalpha.git freqai-plugin
|
|
61
|
+
|
|
62
|
+
# Install dependencies
|
|
63
|
+
pip install lightgbm shap scikit-learn pandas numpy
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Then copy `deepalpha_model.py` into your Freqtrade `freqaimodels/` directory:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
cp freqai-plugin/deepalpha_model.py freqtrade/freqaimodels/
|
|
70
|
+
cp freqai-plugin/example_strategy.py freqtrade/user_data/strategies/
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Configuration
|
|
74
|
+
|
|
75
|
+
Add the DeepAlpha model to your Freqtrade config. See `config_example.json` for a full example.
|
|
76
|
+
|
|
77
|
+
Key section:
|
|
78
|
+
|
|
79
|
+
```json
|
|
80
|
+
{
|
|
81
|
+
"freqai": {
|
|
82
|
+
"enabled": true,
|
|
83
|
+
"model_type": "DeepAlphaModel",
|
|
84
|
+
"model_training_parameters": {
|
|
85
|
+
"n_estimators": 2000,
|
|
86
|
+
"learning_rate": 0.02,
|
|
87
|
+
"max_depth": 6,
|
|
88
|
+
"num_leaves": 48,
|
|
89
|
+
"subsample": 0.7,
|
|
90
|
+
"colsample_bytree": 0.7,
|
|
91
|
+
"min_child_samples": 50,
|
|
92
|
+
"reg_alpha": 0.1,
|
|
93
|
+
"reg_lambda": 1.0
|
|
94
|
+
},
|
|
95
|
+
"deepalpha": {
|
|
96
|
+
"triple_barrier": {
|
|
97
|
+
"profit_taking": 2.0,
|
|
98
|
+
"stop_loss": 1.0,
|
|
99
|
+
"max_holding_period": 48,
|
|
100
|
+
"volatility_window": 20
|
|
101
|
+
},
|
|
102
|
+
"shap_feature_selection": {
|
|
103
|
+
"enabled": true,
|
|
104
|
+
"top_k": 30,
|
|
105
|
+
"recalculate_every_n_trainings": 5
|
|
106
|
+
},
|
|
107
|
+
"meta_labeling": {
|
|
108
|
+
"enabled": true,
|
|
109
|
+
"threshold": 0.55
|
|
110
|
+
},
|
|
111
|
+
"purged_cv": {
|
|
112
|
+
"n_splits": 5,
|
|
113
|
+
"purge_gap": 24,
|
|
114
|
+
"embargo_pct": 0.01
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
"train_period_days": 60,
|
|
118
|
+
"backtest_period_days": 7,
|
|
119
|
+
"identifier": "deepalpha_v1"
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Usage
|
|
125
|
+
|
|
126
|
+
1. Configure your `config.json` with the FreqAI + DeepAlpha settings
|
|
127
|
+
2. Use the included `example_strategy.py` or adapt your own strategy
|
|
128
|
+
3. Run backtesting or live trading as usual:
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
# Backtest
|
|
132
|
+
freqtrade backtesting --strategy DeepAlphaStrategy --config config.json --freqaimodel DeepAlphaModel
|
|
133
|
+
|
|
134
|
+
# Dry run
|
|
135
|
+
freqtrade trade --strategy DeepAlphaStrategy --config config.json --freqaimodel DeepAlphaModel
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## How It Works
|
|
139
|
+
|
|
140
|
+
### 1. Triple Barrier Labeling
|
|
141
|
+
Instead of labeling candles as simply "up" or "down" based on future returns, the Triple Barrier method assigns labels based on which barrier is hit first:
|
|
142
|
+
- **Upper barrier** (profit target): label = 1
|
|
143
|
+
- **Lower barrier** (stop loss): label = -1
|
|
144
|
+
- **Vertical barrier** (time expiry): label = 0
|
|
145
|
+
|
|
146
|
+
This produces labels that align with actual trading outcomes.
|
|
147
|
+
|
|
148
|
+
### 2. SHAP Feature Selection
|
|
149
|
+
After training, SHAP values identify which features genuinely contribute to predictions. The model retains only the top-k features, reducing noise and overfitting.
|
|
150
|
+
|
|
151
|
+
### 3. Meta-labeling
|
|
152
|
+
A secondary LightGBM model is trained to predict the *probability that the primary model's signal is correct*. Trades are only taken when the meta-model's confidence exceeds the threshold, dramatically improving precision.
|
|
153
|
+
|
|
154
|
+
### 4. Purged Walk-Forward CV
|
|
155
|
+
Cross-validation splits respect temporal ordering with purge gaps between train/test sets to eliminate information leakage.
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## File Structure
|
|
160
|
+
|
|
161
|
+
```
|
|
162
|
+
freqai-plugin/
|
|
163
|
+
README.md # This file
|
|
164
|
+
setup.py # PyPI packaging
|
|
165
|
+
__init__.py # Package init
|
|
166
|
+
deepalpha_model.py # FreqAI-compatible model class
|
|
167
|
+
example_strategy.py # Example Freqtrade strategy
|
|
168
|
+
config_example.json # Example configuration
|
|
169
|
+
tests/
|
|
170
|
+
test_deepalpha_model.py # Unit tests
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## Running Tests
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
pip install pytest
|
|
177
|
+
pytest tests/ -v
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
## Contributing to Freqtrade
|
|
183
|
+
|
|
184
|
+
We welcome contributions and are working towards submitting DeepAlpha as an official FreqAI model within Freqtrade. Here is how you can help or submit your own changes upstream:
|
|
185
|
+
|
|
186
|
+
### Submitting as a Freqtrade PR
|
|
187
|
+
|
|
188
|
+
1. **Fork** the [Freqtrade repository](https://github.com/freqtrade/freqtrade) on GitHub.
|
|
189
|
+
2. **Create a feature branch** from the `develop` branch:
|
|
190
|
+
```bash
|
|
191
|
+
git checkout develop
|
|
192
|
+
git checkout -b feat/deepalpha-freqai-model
|
|
193
|
+
```
|
|
194
|
+
3. **Add the model file** to `freqtrade/freqai/prediction_models/DeepAlphaModel.py`.
|
|
195
|
+
4. **Add the example strategy** to `freqtrade/templates/DeepAlphaStrategy.py`.
|
|
196
|
+
5. **Add unit tests** to `tests/freqai/test_deepalpha_model.py`.
|
|
197
|
+
6. **Update the FreqAI documentation** in `docs/freqai.md` to reference the new model.
|
|
198
|
+
7. **Ensure all tests pass**:
|
|
199
|
+
```bash
|
|
200
|
+
pytest tests/freqai/ -v
|
|
201
|
+
```
|
|
202
|
+
8. **Submit a Pull Request** against the `develop` branch with:
|
|
203
|
+
- A clear description of the model and its advantages
|
|
204
|
+
- Backtest results demonstrating improved performance
|
|
205
|
+
- Links to the academic references (Triple Barrier from *Advances in Financial Machine Learning* by Marcos Lopez de Prado)
|
|
206
|
+
|
|
207
|
+
### Contributing to this Plugin
|
|
208
|
+
|
|
209
|
+
1. Fork this repository at [github.com/stefanoviana/deepalpha](https://github.com/stefanoviana/deepalpha).
|
|
210
|
+
2. Create a feature branch: `git checkout -b feat/your-feature`.
|
|
211
|
+
3. Write tests for any new functionality.
|
|
212
|
+
4. Ensure all tests pass: `pytest tests/ -v`.
|
|
213
|
+
5. Submit a Pull Request with a clear description of your changes.
|
|
214
|
+
|
|
215
|
+
### Code Style
|
|
216
|
+
|
|
217
|
+
- Follow PEP 8 and the existing code conventions.
|
|
218
|
+
- All public functions and classes must have docstrings.
|
|
219
|
+
- Type hints are required for all function signatures.
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## Links
|
|
224
|
+
|
|
225
|
+
- [DeepAlpha Repository](https://github.com/stefanoviana/deepalpha)
|
|
226
|
+
- [Freqtrade Documentation](https://www.freqtrade.io/)
|
|
227
|
+
- [FreqAI Documentation](https://www.freqtrade.io/en/stable/freqai/)
|
|
228
|
+
- [Advances in Financial Machine Learning](https://www.wiley.com/en-us/Advances+in+Financial+Machine+Learning-p-9781119482086) (Triple Barrier reference)
|
|
229
|
+
|
|
230
|
+
## License
|
|
231
|
+
|
|
232
|
+
MIT License. See the main DeepAlpha repository for details.
|