DQuant 1.1.3__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.
- dquant-1.1.3/LICENSE +21 -0
- dquant-1.1.3/PKG-INFO +307 -0
- dquant-1.1.3/README.md +277 -0
- dquant-1.1.3/pyproject.toml +43 -0
- dquant-1.1.3/setup.cfg +4 -0
- dquant-1.1.3/src/DQuant.egg-info/PKG-INFO +307 -0
- dquant-1.1.3/src/DQuant.egg-info/SOURCES.txt +18 -0
- dquant-1.1.3/src/DQuant.egg-info/dependency_links.txt +1 -0
- dquant-1.1.3/src/DQuant.egg-info/requires.txt +13 -0
- dquant-1.1.3/src/DQuant.egg-info/top_level.txt +1 -0
- dquant-1.1.3/src/dquant/__init__.py +6 -0
- dquant-1.1.3/src/dquant/models.py +1740 -0
- dquant-1.1.3/src/dquant/visual.py +353 -0
- dquant-1.1.3/test/test.py +158 -0
- dquant-1.1.3/test/test_load.py +68 -0
dquant-1.1.3/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Denis Makarov
|
|
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.
|
dquant-1.1.3/PKG-INFO
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: DQuant
|
|
3
|
+
Version: 1.1.3
|
|
4
|
+
Summary: DQuant is an open-source Python library for automated volatility forecasting of financial time series. It handles all stages of model construction, from raw prices to the final forecast.
|
|
5
|
+
Author: Denis Makarov
|
|
6
|
+
Project-URL: Homepage, https://dquant.space
|
|
7
|
+
Project-URL: Repository, https://github.com/artrdon/dquant
|
|
8
|
+
Project-URL: Documentation, https://github.com/artrdon/dquant/blob/main/docs.md
|
|
9
|
+
Project-URL: Issues, https://github.com/artrdon/dquant/issues
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Requires-Python: >=3.7
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Requires-Dist: cycler>=0.11.0
|
|
17
|
+
Requires-Dist: joblib>=1.2.0
|
|
18
|
+
Requires-Dist: lightgbm>=3.3.0
|
|
19
|
+
Requires-Dist: matplotlib>=3.5.0
|
|
20
|
+
Requires-Dist: numpy>=1.21.0
|
|
21
|
+
Requires-Dist: onnx>=1.14.0
|
|
22
|
+
Requires-Dist: onnxruntime>=1.15.0
|
|
23
|
+
Requires-Dist: pandas>=1.5.0
|
|
24
|
+
Requires-Dist: scikit-learn>=1.2.0
|
|
25
|
+
Requires-Dist: skl2onnx>=1.14.0
|
|
26
|
+
Requires-Dist: xgboost>=1.7.0
|
|
27
|
+
Requires-Dist: onnxconverter-common>=1.9.0
|
|
28
|
+
Requires-Dist: onnxmltools>=1.11.0
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
|
|
31
|
+
<div align="center">
|
|
32
|
+
<h1>DQuant</h1>
|
|
33
|
+
<p><strong>Automated Volatility Forecasting for Traders and Analysts</strong></p>
|
|
34
|
+
<br>
|
|
35
|
+
<img src="https://github.com/artrdon/dquant/blob/main/logo.png?raw=true" alt="dquant demo" width="200">
|
|
36
|
+
<br>
|
|
37
|
+
<p><i>Volatility forecast with DQuant</i></p>
|
|
38
|
+
</div>
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## About the Project
|
|
43
|
+
|
|
44
|
+
**DQuant** is an open-source Python library for automated volatility forecasting of financial time series. It handles all stages of model building: from raw prices to ready-made forecasts.
|
|
45
|
+
|
|
46
|
+
### Key Idea
|
|
47
|
+
> **A trader doesn't need to know machine learning to use AI for volatility forecasting.**
|
|
48
|
+
|
|
49
|
+
### Features
|
|
50
|
+
|
|
51
|
+
| | |
|
|
52
|
+
|---|---|
|
|
53
|
+
| **Automated feature engineering** | Creates dozens of features from raw prices (open, high, low, close, volume) |
|
|
54
|
+
| **Target variable without look-ahead bias** | Correct calculation of realized volatility |
|
|
55
|
+
| **3 models to choose from** | Gradient Boosting, XGBoost, LightGBM with early stopping |
|
|
56
|
+
| **Training visualization** | Error plot on train/validation to monitor overfitting |
|
|
57
|
+
| **Save and load** | Train once — use forever |
|
|
58
|
+
| **Flexible customization** | Your own features, model parameters, data sources |
|
|
59
|
+
| **Integration with any data** | Yahoo Finance, MetaTrader 5 |
|
|
60
|
+
|
|
61
|
+
### Who is this for
|
|
62
|
+
|
|
63
|
+
- **Algorithmic traders** — for model calibration and risk management
|
|
64
|
+
- **Discretionary traders** — for assessing market regime and position sizing
|
|
65
|
+
- **Quantitative analysts** — for rapid prototyping
|
|
66
|
+
- **Developers** — for embedding into trading systems
|
|
67
|
+
- **Students** — as a ready-made benchmark and learning example
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## Installation
|
|
72
|
+
|
|
73
|
+
### Requirements
|
|
74
|
+
- Python 3.7 or higher
|
|
75
|
+
- pip
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
pip install dquant
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
### Verify Installation
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
import dquant
|
|
87
|
+
print(dquant.__version__) # Should output the version
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## Quick Start
|
|
93
|
+
|
|
94
|
+
### Minimal working example with Bitcoin
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
import pandas as pd
|
|
98
|
+
import yfinance as yf
|
|
99
|
+
from dquant.models import VolClustXGB
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
# 1. Load data
|
|
103
|
+
df = yf.download("BTC-USD", start="2020-01-01", interval='1d')
|
|
104
|
+
df = pd.DataFrame({
|
|
105
|
+
'open': df[('Open', 'BTC-USD')].values,
|
|
106
|
+
'high': df[('High', 'BTC-USD')].values,
|
|
107
|
+
'low': df[('Low', 'BTC-USD')].values,
|
|
108
|
+
'close': df[('Close', 'BTC-USD')].values,
|
|
109
|
+
'volume': df[('Volume', 'BTC-USD')].values
|
|
110
|
+
}, index=df.index)
|
|
111
|
+
|
|
112
|
+
# 2. Create model
|
|
113
|
+
model = VolClustXGB({}, early_stopping=True)
|
|
114
|
+
|
|
115
|
+
# 3. Train model
|
|
116
|
+
features = [
|
|
117
|
+
'TR',
|
|
118
|
+
'returns',
|
|
119
|
+
'abs_returns',
|
|
120
|
+
'gap',
|
|
121
|
+
'body',
|
|
122
|
+
'shadow',
|
|
123
|
+
'close_position',
|
|
124
|
+
'roll_atr_14'
|
|
125
|
+
]
|
|
126
|
+
model.fit(df, feature_list=features, input_bars=70, horizon=20, trees_count=200, show_results=True)
|
|
127
|
+
|
|
128
|
+
# 4. Make forecast
|
|
129
|
+
rez = model.forecast(df.iloc[-70:].copy(), show=True)
|
|
130
|
+
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Execution result
|
|
134
|
+
|
|
135
|
+
```
|
|
136
|
+
[0.0016554 0.0018979 0.0015921 0.0014239 0.0013767 0.0011586 0.0013139
|
|
137
|
+
0.0009813 0.0007931 0.0012909 0.0013664 0.0016466 0.0014836 0.0011577
|
|
138
|
+
0.0008737 0.0007213 0.0008084 0.0012699 0.0015358 0.0014748]
|
|
139
|
+
```
|
|
140
|
+
<img src="https://github.com/artrdon/dquant/blob/main/readmeforecast.png?raw=true">
|
|
141
|
+
|
|
142
|
+
Red shows volatility for previous candles, green shows future volatility.
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## Documentation
|
|
147
|
+
|
|
148
|
+
| Resource | Description |
|
|
149
|
+
|:-------|:---------|
|
|
150
|
+
| [**Full documentation**](https://github.com/artrdon/dquant/blob/main/docs.md) | All classes, methods, parameters |
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## Usage Examples
|
|
155
|
+
|
|
156
|
+
### With Yahoo Finance
|
|
157
|
+
|
|
158
|
+
```python
|
|
159
|
+
import pandas as pd
|
|
160
|
+
import yfinance as yf
|
|
161
|
+
from dquant.models import VolClustXGB
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
# 1. Load data
|
|
165
|
+
df = yf.download("BTC-USD", start="2020-01-01", interval='1d')
|
|
166
|
+
df = pd.DataFrame({
|
|
167
|
+
'open': df[('Open', 'BTC-USD')].values,
|
|
168
|
+
'high': df[('High', 'BTC-USD')].values,
|
|
169
|
+
'low': df[('Low', 'BTC-USD')].values,
|
|
170
|
+
'close': df[('Close', 'BTC-USD')].values,
|
|
171
|
+
'volume': df[('Volume', 'BTC-USD')].values
|
|
172
|
+
}, index=df.index)
|
|
173
|
+
|
|
174
|
+
# 2. Create model
|
|
175
|
+
model = VolClustXGB({}, early_stopping=True)
|
|
176
|
+
|
|
177
|
+
# 3. Train model
|
|
178
|
+
features = [
|
|
179
|
+
'TR',
|
|
180
|
+
'returns',
|
|
181
|
+
'abs_returns',
|
|
182
|
+
'gap',
|
|
183
|
+
'body',
|
|
184
|
+
'shadow',
|
|
185
|
+
'close_position',
|
|
186
|
+
'roll_atr_14'
|
|
187
|
+
]
|
|
188
|
+
model.fit(df, feature_list=features, input_bars=70, horizon=20, trees_count=200, show_results=True)
|
|
189
|
+
|
|
190
|
+
# 4. Make forecast
|
|
191
|
+
rez = model.forecast(df.iloc[-70:].copy(), show=True)
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### With MetaTrader 5
|
|
195
|
+
|
|
196
|
+
```python
|
|
197
|
+
import pandas as pd
|
|
198
|
+
import MetaTrader5 as mt5
|
|
199
|
+
import datetime as dt
|
|
200
|
+
from dquant.models import VolClustXGB
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
symbol = "EURUSD" # symbol to watch
|
|
204
|
+
timeframe = mt5.TIMEFRAME_H1 # M1, M5, M15, H1, D1, etc.
|
|
205
|
+
days_back = 1000 # how many days of history to load
|
|
206
|
+
|
|
207
|
+
# Connect to MT5
|
|
208
|
+
if not mt5.initialize():
|
|
209
|
+
print("Failed to connect to MetaTrader5")
|
|
210
|
+
quit()
|
|
211
|
+
|
|
212
|
+
# Check that symbol is available
|
|
213
|
+
if not mt5.symbol_select(symbol, True):
|
|
214
|
+
print(f"Symbol {symbol} not found or not enabled")
|
|
215
|
+
mt5.shutdown()
|
|
216
|
+
quit()
|
|
217
|
+
|
|
218
|
+
# Calculate dates
|
|
219
|
+
to_date = dt.datetime.now() + dt.timedelta(hours=3)
|
|
220
|
+
from_date = to_date - dt.timedelta(days=days_back)
|
|
221
|
+
|
|
222
|
+
# Load bars
|
|
223
|
+
rates = mt5.copy_rates_range(symbol, timeframe, from_date, to_date)
|
|
224
|
+
|
|
225
|
+
mt5.shutdown() # terminal no longer needed
|
|
226
|
+
|
|
227
|
+
if rates is None or len(rates) == 0:
|
|
228
|
+
print("No data!")
|
|
229
|
+
quit()
|
|
230
|
+
|
|
231
|
+
# Convert to DataFrame
|
|
232
|
+
df = pd.DataFrame(rates)
|
|
233
|
+
df['time'] = pd.to_datetime(df['time'], unit='s')
|
|
234
|
+
|
|
235
|
+
df.rename(columns={
|
|
236
|
+
'tick_volume': 'volume'
|
|
237
|
+
}, inplace=True)
|
|
238
|
+
|
|
239
|
+
# Create model
|
|
240
|
+
model = VolClustXGB({}, early_stopping=True)
|
|
241
|
+
|
|
242
|
+
# Train model
|
|
243
|
+
features = [
|
|
244
|
+
'TR',
|
|
245
|
+
'returns',
|
|
246
|
+
'abs_returns',
|
|
247
|
+
'gap',
|
|
248
|
+
'body',
|
|
249
|
+
'shadow',
|
|
250
|
+
'close_position',
|
|
251
|
+
'roll_atr_14'
|
|
252
|
+
]
|
|
253
|
+
model.fit(df, feature_list=features, input_bars=70, horizon=20, trees_count=200, show_results=True)
|
|
254
|
+
|
|
255
|
+
# Make forecast
|
|
256
|
+
rez = model.forecast(df.iloc[-70:].copy(), show=True)
|
|
257
|
+
```
|
|
258
|
+
---
|
|
259
|
+
## Creating an indicator for Meta Trader 5
|
|
260
|
+
|
|
261
|
+
Immediately after training the model, you can export it to a working mql5 indicator. Just one more line of code is needed:
|
|
262
|
+
```python
|
|
263
|
+
model.save('indicator_name', type_to_save='mql5')
|
|
264
|
+
```
|
|
265
|
+
Done! Now you can use your trained models in Meta Trader 5.
|
|
266
|
+
|
|
267
|
+
---
|
|
268
|
+
|
|
269
|
+
## How to Contribute
|
|
270
|
+
|
|
271
|
+
We welcome any contribution to the project! Here are a few ways to help:
|
|
272
|
+
|
|
273
|
+
### Report a bug
|
|
274
|
+
Found a bug? [Create an Issue](https://github.com/artrdon/dquant/issues) with a detailed description:
|
|
275
|
+
- What you did
|
|
276
|
+
- What you expected
|
|
277
|
+
- What actually happened
|
|
278
|
+
- Code to reproduce (if possible)
|
|
279
|
+
|
|
280
|
+
### Suggest an idea
|
|
281
|
+
Have an idea for improvement? [Write to Telegram](https://t.me/Denchik_ai) or create an Issue with the `enhancement` label.
|
|
282
|
+
|
|
283
|
+
---
|
|
284
|
+
|
|
285
|
+
## License
|
|
286
|
+
|
|
287
|
+
The project is distributed under the MIT license. See the [LICENSE](https://github.com/artrdon/dquant/blob/main/LICENSE) file for details.
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
## Project Support
|
|
292
|
+
|
|
293
|
+
If **dquant** has helped you in your work or studies:
|
|
294
|
+
|
|
295
|
+
- Star the project on GitHub ⭐ — it's very motivating!
|
|
296
|
+
- Tell your colleagues about the library
|
|
297
|
+
- [Write to me](https://t.me/Denchik_ai) about your experience using it
|
|
298
|
+
|
|
299
|
+
---
|
|
300
|
+
|
|
301
|
+
## Contacts
|
|
302
|
+
|
|
303
|
+
**Author:** Denis Makarov
|
|
304
|
+
|
|
305
|
+
- Telegram: [@Denchik_ai](https://t.me/Denchik_ai)
|
|
306
|
+
- GitHub: [@artrdon](https://github.com/artrdon)
|
|
307
|
+
- Project website: [dquant.space](https://dquant.space)
|
dquant-1.1.3/README.md
ADDED
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<h1>DQuant</h1>
|
|
3
|
+
<p><strong>Automated Volatility Forecasting for Traders and Analysts</strong></p>
|
|
4
|
+
<br>
|
|
5
|
+
<img src="https://github.com/artrdon/dquant/blob/main/logo.png?raw=true" alt="dquant demo" width="200">
|
|
6
|
+
<br>
|
|
7
|
+
<p><i>Volatility forecast with DQuant</i></p>
|
|
8
|
+
</div>
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## About the Project
|
|
13
|
+
|
|
14
|
+
**DQuant** is an open-source Python library for automated volatility forecasting of financial time series. It handles all stages of model building: from raw prices to ready-made forecasts.
|
|
15
|
+
|
|
16
|
+
### Key Idea
|
|
17
|
+
> **A trader doesn't need to know machine learning to use AI for volatility forecasting.**
|
|
18
|
+
|
|
19
|
+
### Features
|
|
20
|
+
|
|
21
|
+
| | |
|
|
22
|
+
|---|---|
|
|
23
|
+
| **Automated feature engineering** | Creates dozens of features from raw prices (open, high, low, close, volume) |
|
|
24
|
+
| **Target variable without look-ahead bias** | Correct calculation of realized volatility |
|
|
25
|
+
| **3 models to choose from** | Gradient Boosting, XGBoost, LightGBM with early stopping |
|
|
26
|
+
| **Training visualization** | Error plot on train/validation to monitor overfitting |
|
|
27
|
+
| **Save and load** | Train once — use forever |
|
|
28
|
+
| **Flexible customization** | Your own features, model parameters, data sources |
|
|
29
|
+
| **Integration with any data** | Yahoo Finance, MetaTrader 5 |
|
|
30
|
+
|
|
31
|
+
### Who is this for
|
|
32
|
+
|
|
33
|
+
- **Algorithmic traders** — for model calibration and risk management
|
|
34
|
+
- **Discretionary traders** — for assessing market regime and position sizing
|
|
35
|
+
- **Quantitative analysts** — for rapid prototyping
|
|
36
|
+
- **Developers** — for embedding into trading systems
|
|
37
|
+
- **Students** — as a ready-made benchmark and learning example
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## Installation
|
|
42
|
+
|
|
43
|
+
### Requirements
|
|
44
|
+
- Python 3.7 or higher
|
|
45
|
+
- pip
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
pip install dquant
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
### Verify Installation
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
import dquant
|
|
57
|
+
print(dquant.__version__) # Should output the version
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## Quick Start
|
|
63
|
+
|
|
64
|
+
### Minimal working example with Bitcoin
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
import pandas as pd
|
|
68
|
+
import yfinance as yf
|
|
69
|
+
from dquant.models import VolClustXGB
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
# 1. Load data
|
|
73
|
+
df = yf.download("BTC-USD", start="2020-01-01", interval='1d')
|
|
74
|
+
df = pd.DataFrame({
|
|
75
|
+
'open': df[('Open', 'BTC-USD')].values,
|
|
76
|
+
'high': df[('High', 'BTC-USD')].values,
|
|
77
|
+
'low': df[('Low', 'BTC-USD')].values,
|
|
78
|
+
'close': df[('Close', 'BTC-USD')].values,
|
|
79
|
+
'volume': df[('Volume', 'BTC-USD')].values
|
|
80
|
+
}, index=df.index)
|
|
81
|
+
|
|
82
|
+
# 2. Create model
|
|
83
|
+
model = VolClustXGB({}, early_stopping=True)
|
|
84
|
+
|
|
85
|
+
# 3. Train model
|
|
86
|
+
features = [
|
|
87
|
+
'TR',
|
|
88
|
+
'returns',
|
|
89
|
+
'abs_returns',
|
|
90
|
+
'gap',
|
|
91
|
+
'body',
|
|
92
|
+
'shadow',
|
|
93
|
+
'close_position',
|
|
94
|
+
'roll_atr_14'
|
|
95
|
+
]
|
|
96
|
+
model.fit(df, feature_list=features, input_bars=70, horizon=20, trees_count=200, show_results=True)
|
|
97
|
+
|
|
98
|
+
# 4. Make forecast
|
|
99
|
+
rez = model.forecast(df.iloc[-70:].copy(), show=True)
|
|
100
|
+
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Execution result
|
|
104
|
+
|
|
105
|
+
```
|
|
106
|
+
[0.0016554 0.0018979 0.0015921 0.0014239 0.0013767 0.0011586 0.0013139
|
|
107
|
+
0.0009813 0.0007931 0.0012909 0.0013664 0.0016466 0.0014836 0.0011577
|
|
108
|
+
0.0008737 0.0007213 0.0008084 0.0012699 0.0015358 0.0014748]
|
|
109
|
+
```
|
|
110
|
+
<img src="https://github.com/artrdon/dquant/blob/main/readmeforecast.png?raw=true">
|
|
111
|
+
|
|
112
|
+
Red shows volatility for previous candles, green shows future volatility.
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## Documentation
|
|
117
|
+
|
|
118
|
+
| Resource | Description |
|
|
119
|
+
|:-------|:---------|
|
|
120
|
+
| [**Full documentation**](https://github.com/artrdon/dquant/blob/main/docs.md) | All classes, methods, parameters |
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## Usage Examples
|
|
125
|
+
|
|
126
|
+
### With Yahoo Finance
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
import pandas as pd
|
|
130
|
+
import yfinance as yf
|
|
131
|
+
from dquant.models import VolClustXGB
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
# 1. Load data
|
|
135
|
+
df = yf.download("BTC-USD", start="2020-01-01", interval='1d')
|
|
136
|
+
df = pd.DataFrame({
|
|
137
|
+
'open': df[('Open', 'BTC-USD')].values,
|
|
138
|
+
'high': df[('High', 'BTC-USD')].values,
|
|
139
|
+
'low': df[('Low', 'BTC-USD')].values,
|
|
140
|
+
'close': df[('Close', 'BTC-USD')].values,
|
|
141
|
+
'volume': df[('Volume', 'BTC-USD')].values
|
|
142
|
+
}, index=df.index)
|
|
143
|
+
|
|
144
|
+
# 2. Create model
|
|
145
|
+
model = VolClustXGB({}, early_stopping=True)
|
|
146
|
+
|
|
147
|
+
# 3. Train model
|
|
148
|
+
features = [
|
|
149
|
+
'TR',
|
|
150
|
+
'returns',
|
|
151
|
+
'abs_returns',
|
|
152
|
+
'gap',
|
|
153
|
+
'body',
|
|
154
|
+
'shadow',
|
|
155
|
+
'close_position',
|
|
156
|
+
'roll_atr_14'
|
|
157
|
+
]
|
|
158
|
+
model.fit(df, feature_list=features, input_bars=70, horizon=20, trees_count=200, show_results=True)
|
|
159
|
+
|
|
160
|
+
# 4. Make forecast
|
|
161
|
+
rez = model.forecast(df.iloc[-70:].copy(), show=True)
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### With MetaTrader 5
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
import pandas as pd
|
|
168
|
+
import MetaTrader5 as mt5
|
|
169
|
+
import datetime as dt
|
|
170
|
+
from dquant.models import VolClustXGB
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
symbol = "EURUSD" # symbol to watch
|
|
174
|
+
timeframe = mt5.TIMEFRAME_H1 # M1, M5, M15, H1, D1, etc.
|
|
175
|
+
days_back = 1000 # how many days of history to load
|
|
176
|
+
|
|
177
|
+
# Connect to MT5
|
|
178
|
+
if not mt5.initialize():
|
|
179
|
+
print("Failed to connect to MetaTrader5")
|
|
180
|
+
quit()
|
|
181
|
+
|
|
182
|
+
# Check that symbol is available
|
|
183
|
+
if not mt5.symbol_select(symbol, True):
|
|
184
|
+
print(f"Symbol {symbol} not found or not enabled")
|
|
185
|
+
mt5.shutdown()
|
|
186
|
+
quit()
|
|
187
|
+
|
|
188
|
+
# Calculate dates
|
|
189
|
+
to_date = dt.datetime.now() + dt.timedelta(hours=3)
|
|
190
|
+
from_date = to_date - dt.timedelta(days=days_back)
|
|
191
|
+
|
|
192
|
+
# Load bars
|
|
193
|
+
rates = mt5.copy_rates_range(symbol, timeframe, from_date, to_date)
|
|
194
|
+
|
|
195
|
+
mt5.shutdown() # terminal no longer needed
|
|
196
|
+
|
|
197
|
+
if rates is None or len(rates) == 0:
|
|
198
|
+
print("No data!")
|
|
199
|
+
quit()
|
|
200
|
+
|
|
201
|
+
# Convert to DataFrame
|
|
202
|
+
df = pd.DataFrame(rates)
|
|
203
|
+
df['time'] = pd.to_datetime(df['time'], unit='s')
|
|
204
|
+
|
|
205
|
+
df.rename(columns={
|
|
206
|
+
'tick_volume': 'volume'
|
|
207
|
+
}, inplace=True)
|
|
208
|
+
|
|
209
|
+
# Create model
|
|
210
|
+
model = VolClustXGB({}, early_stopping=True)
|
|
211
|
+
|
|
212
|
+
# Train model
|
|
213
|
+
features = [
|
|
214
|
+
'TR',
|
|
215
|
+
'returns',
|
|
216
|
+
'abs_returns',
|
|
217
|
+
'gap',
|
|
218
|
+
'body',
|
|
219
|
+
'shadow',
|
|
220
|
+
'close_position',
|
|
221
|
+
'roll_atr_14'
|
|
222
|
+
]
|
|
223
|
+
model.fit(df, feature_list=features, input_bars=70, horizon=20, trees_count=200, show_results=True)
|
|
224
|
+
|
|
225
|
+
# Make forecast
|
|
226
|
+
rez = model.forecast(df.iloc[-70:].copy(), show=True)
|
|
227
|
+
```
|
|
228
|
+
---
|
|
229
|
+
## Creating an indicator for Meta Trader 5
|
|
230
|
+
|
|
231
|
+
Immediately after training the model, you can export it to a working mql5 indicator. Just one more line of code is needed:
|
|
232
|
+
```python
|
|
233
|
+
model.save('indicator_name', type_to_save='mql5')
|
|
234
|
+
```
|
|
235
|
+
Done! Now you can use your trained models in Meta Trader 5.
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
## How to Contribute
|
|
240
|
+
|
|
241
|
+
We welcome any contribution to the project! Here are a few ways to help:
|
|
242
|
+
|
|
243
|
+
### Report a bug
|
|
244
|
+
Found a bug? [Create an Issue](https://github.com/artrdon/dquant/issues) with a detailed description:
|
|
245
|
+
- What you did
|
|
246
|
+
- What you expected
|
|
247
|
+
- What actually happened
|
|
248
|
+
- Code to reproduce (if possible)
|
|
249
|
+
|
|
250
|
+
### Suggest an idea
|
|
251
|
+
Have an idea for improvement? [Write to Telegram](https://t.me/Denchik_ai) or create an Issue with the `enhancement` label.
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
255
|
+
## License
|
|
256
|
+
|
|
257
|
+
The project is distributed under the MIT license. See the [LICENSE](https://github.com/artrdon/dquant/blob/main/LICENSE) file for details.
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
## Project Support
|
|
262
|
+
|
|
263
|
+
If **dquant** has helped you in your work or studies:
|
|
264
|
+
|
|
265
|
+
- Star the project on GitHub ⭐ — it's very motivating!
|
|
266
|
+
- Tell your colleagues about the library
|
|
267
|
+
- [Write to me](https://t.me/Denchik_ai) about your experience using it
|
|
268
|
+
|
|
269
|
+
---
|
|
270
|
+
|
|
271
|
+
## Contacts
|
|
272
|
+
|
|
273
|
+
**Author:** Denis Makarov
|
|
274
|
+
|
|
275
|
+
- Telegram: [@Denchik_ai](https://t.me/Denchik_ai)
|
|
276
|
+
- GitHub: [@artrdon](https://github.com/artrdon)
|
|
277
|
+
- Project website: [dquant.space](https://dquant.space)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "DQuant"
|
|
7
|
+
version = "1.1.3"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name="Denis Makarov" },
|
|
10
|
+
]
|
|
11
|
+
description = "DQuant is an open-source Python library for automated volatility forecasting of financial time series. It handles all stages of model construction, from raw prices to the final forecast."
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.7"
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
dependencies = [
|
|
21
|
+
"cycler>=0.11.0",
|
|
22
|
+
"joblib>=1.2.0",
|
|
23
|
+
"lightgbm>=3.3.0",
|
|
24
|
+
"matplotlib>=3.5.0",
|
|
25
|
+
"numpy>=1.21.0",
|
|
26
|
+
"onnx>=1.14.0",
|
|
27
|
+
"onnxruntime>=1.15.0",
|
|
28
|
+
"pandas>=1.5.0",
|
|
29
|
+
"scikit-learn>=1.2.0",
|
|
30
|
+
"skl2onnx>=1.14.0",
|
|
31
|
+
"xgboost>=1.7.0",
|
|
32
|
+
"onnxconverter-common>=1.9.0",
|
|
33
|
+
"onnxmltools>=1.11.0"
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
#[project.optional-dependencies]
|
|
37
|
+
#dev = ["pytest", "black"]
|
|
38
|
+
|
|
39
|
+
[project.urls]
|
|
40
|
+
Homepage = "https://dquant.space"
|
|
41
|
+
Repository = "https://github.com/artrdon/dquant"
|
|
42
|
+
Documentation = "https://github.com/artrdon/dquant/blob/main/docs.md"
|
|
43
|
+
Issues = "https://github.com/artrdon/dquant/issues"
|
dquant-1.1.3/setup.cfg
ADDED