dquant 1.2.3__tar.gz → 1.2.4__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.2.3/src/DQuant.egg-info → dquant-1.2.4}/PKG-INFO +1 -1
- {dquant-1.2.3 → dquant-1.2.4}/pyproject.toml +1 -1
- {dquant-1.2.3 → dquant-1.2.4/src/DQuant.egg-info}/PKG-INFO +1 -1
- {dquant-1.2.3 → dquant-1.2.4}/src/dquant/models.py +50 -44
- {dquant-1.2.3 → dquant-1.2.4}/LICENSE +0 -0
- {dquant-1.2.3 → dquant-1.2.4}/README.md +0 -0
- {dquant-1.2.3 → dquant-1.2.4}/setup.cfg +0 -0
- {dquant-1.2.3 → dquant-1.2.4}/src/DQuant.egg-info/SOURCES.txt +0 -0
- {dquant-1.2.3 → dquant-1.2.4}/src/DQuant.egg-info/dependency_links.txt +0 -0
- {dquant-1.2.3 → dquant-1.2.4}/src/DQuant.egg-info/requires.txt +0 -0
- {dquant-1.2.3 → dquant-1.2.4}/src/DQuant.egg-info/top_level.txt +0 -0
- {dquant-1.2.3 → dquant-1.2.4}/src/__init__.py +0 -0
- {dquant-1.2.3 → dquant-1.2.4}/src/dquant/__init__.py +0 -0
- {dquant-1.2.3 → dquant-1.2.4}/src/dquant/get_data.py +0 -0
- {dquant-1.2.3 → dquant-1.2.4}/src/dquant/metrics.py +0 -0
- {dquant-1.2.3 → dquant-1.2.4}/src/dquant/visual.py +0 -0
- {dquant-1.2.3 → dquant-1.2.4}/test/test.py +0 -0
- {dquant-1.2.3 → dquant-1.2.4}/test/test_load.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dquant
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.4
|
|
4
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
5
|
Author: Denis Makarov
|
|
6
6
|
Project-URL: Homepage, https://dquant.space
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dquant
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.4
|
|
4
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
5
|
Author: Denis Makarov
|
|
6
6
|
Project-URL: Homepage, https://dquant.space
|
|
@@ -557,8 +557,14 @@ class FichEn:
|
|
|
557
557
|
X_train, X_test, y_train, y_test = train_test_split(x, y, test_size=0.2, shuffle=False, random_state=42)
|
|
558
558
|
X_scaled = self.scaler.fit_transform(X_train)
|
|
559
559
|
X_test_scaled = self.scaler.transform(X_test)
|
|
560
|
-
Y_scaled = self.scaler_y.fit_transform(y_train)
|
|
561
|
-
Y_test_scaled = self.scaler_y.transform(y_test)
|
|
560
|
+
#Y_scaled = self.scaler_y.fit_transform(y_train)
|
|
561
|
+
#Y_test_scaled = self.scaler_y.transform(y_test)
|
|
562
|
+
"""if hasattr(y, 'ndim') and y.ndim == 1:
|
|
563
|
+
self.X_shape = 1
|
|
564
|
+
#y_2d = y.values.reshape(-1, 1) if hasattr(y, 'values') else y.reshape(-1, 1)
|
|
565
|
+
else:
|
|
566
|
+
self.X_shape = y.shape[1]"""
|
|
567
|
+
|
|
562
568
|
self.X_shape = x.shape[1]
|
|
563
569
|
|
|
564
570
|
self.train_errors = []
|
|
@@ -594,18 +600,18 @@ class FichEn:
|
|
|
594
600
|
horizon_list = list(range(horizon))
|
|
595
601
|
else:
|
|
596
602
|
horizon_list = horizon
|
|
597
|
-
if len(
|
|
603
|
+
if len(y_train.shape) == 2 and y_train.shape[1] > 0:
|
|
598
604
|
for h_idx, h in enumerate(horizon_list):
|
|
599
|
-
if h_idx >=
|
|
605
|
+
if h_idx >= y_train.shape[1]:
|
|
600
606
|
self.dquantprint(f"Warning: horizon {h} extends beyond y, skipping")
|
|
601
607
|
continue
|
|
602
608
|
|
|
603
|
-
y_h =
|
|
609
|
+
y_h = y_train.iloc[:, h_idx] if hasattr(y_train, 'iloc') else y_train[:, h_idx]
|
|
604
610
|
|
|
605
611
|
valid_mask = ~pd.isna(y_h) if hasattr(y_h, 'isna') else ~np.isnan(y_h)
|
|
606
612
|
X_h = X_scaled[valid_mask]
|
|
607
613
|
y_h_clean = y_h[valid_mask]
|
|
608
|
-
y_h_clean_orig = self.scaler_y.inverse_transform(y_h_clean.reshape(-1, 1)).ravel()
|
|
614
|
+
#y_h_clean_orig = self.scaler_y.inverse_transform(y_h_clean.reshape(-1, 1)).ravel()
|
|
609
615
|
|
|
610
616
|
if i != 1:
|
|
611
617
|
self.models[h_idx].set_params(n_estimators=i)
|
|
@@ -616,36 +622,36 @@ class FichEn:
|
|
|
616
622
|
model.fit(X_h, y_h_clean)
|
|
617
623
|
self.models.append(model)
|
|
618
624
|
|
|
619
|
-
y_h_v =
|
|
625
|
+
y_h_v = y_test.iloc[:, h_idx] if hasattr(y_test, 'iloc') else y_test[:, h_idx]
|
|
620
626
|
|
|
621
627
|
valid_mask = ~pd.isna(y_h_v) if hasattr(y_h_v, 'isna') else ~np.isnan(y_h_v)
|
|
622
628
|
X_h_v = X_test_scaled[valid_mask]
|
|
623
629
|
y_h_v_clean = y_h_v[valid_mask]
|
|
624
|
-
y_h_v_clean_orig = self.scaler_y.inverse_transform(y_h_v_clean.reshape(-1, 1)).ravel()
|
|
630
|
+
#y_h_v_clean_orig = self.scaler_y.inverse_transform(y_h_v_clean.reshape(-1, 1)).ravel()
|
|
625
631
|
if i != 1:
|
|
626
632
|
pred_train = self.models[h_idx].predict(X_h)
|
|
627
633
|
pred_val = self.models[h_idx].predict(X_h_v)
|
|
628
|
-
pred_train_orig = self.scaler_y.inverse_transform(pred_train.reshape(-1, 1)).ravel()
|
|
629
|
-
pred_val_orig = self.scaler_y.inverse_transform(pred_val.reshape(-1, 1)).ravel()
|
|
634
|
+
#pred_train_orig = self.scaler_y.inverse_transform(pred_train.reshape(-1, 1)).ravel()
|
|
635
|
+
#pred_val_orig = self.scaler_y.inverse_transform(pred_val.reshape(-1, 1)).ravel()
|
|
630
636
|
t_error += mean_squared_error(y_h_clean, pred_train)
|
|
631
637
|
v_error += mean_squared_error(y_h_v_clean, pred_val)
|
|
632
638
|
t_mae += mean_absolute_error(y_h_clean, pred_train)
|
|
633
639
|
v_mae += mean_absolute_error(y_h_v_clean, pred_val)
|
|
634
|
-
t_qlike += qlike_score(
|
|
635
|
-
v_qlike += qlike_score(
|
|
640
|
+
t_qlike += qlike_score(y_h_clean, pred_train)
|
|
641
|
+
v_qlike += qlike_score(y_h_v_clean, pred_val)
|
|
636
642
|
t_r2 += r2_score(y_h_clean, pred_train)
|
|
637
643
|
v_r2 += r2_score(y_h_v_clean, pred_val)
|
|
638
644
|
else:
|
|
639
645
|
pred_train = model.predict(X_h)
|
|
640
646
|
pred_val = model.predict(X_h_v)
|
|
641
|
-
pred_train_orig = self.scaler_y.inverse_transform(pred_train.reshape(-1, 1)).ravel()
|
|
642
|
-
pred_val_orig = self.scaler_y.inverse_transform(pred_val.reshape(-1, 1)).ravel()
|
|
647
|
+
#pred_train_orig = self.scaler_y.inverse_transform(pred_train.reshape(-1, 1)).ravel()
|
|
648
|
+
#pred_val_orig = self.scaler_y.inverse_transform(pred_val.reshape(-1, 1)).ravel()
|
|
643
649
|
t_error += mean_squared_error(y_h_clean, pred_train)
|
|
644
650
|
v_error += mean_squared_error(y_h_v_clean, pred_val)
|
|
645
651
|
t_mae += mean_absolute_error(y_h_clean, pred_train)
|
|
646
652
|
v_mae += mean_absolute_error(y_h_v_clean, pred_val)
|
|
647
|
-
t_qlike += qlike_score(
|
|
648
|
-
v_qlike += qlike_score(
|
|
653
|
+
t_qlike += qlike_score(y_h_clean, pred_train)
|
|
654
|
+
v_qlike += qlike_score(y_h_v_clean, pred_val)
|
|
649
655
|
t_r2 += r2_score(y_h_clean, pred_train)
|
|
650
656
|
v_r2 += r2_score(y_h_v_clean, pred_val)
|
|
651
657
|
|
|
@@ -748,7 +754,7 @@ class FichEn:
|
|
|
748
754
|
pred_array = pred_array.T
|
|
749
755
|
elif pred_array.shape[0] > 1 and pred_array.shape[1] == 30:
|
|
750
756
|
pred_array = pred_array[0:1, :]
|
|
751
|
-
predictions =
|
|
757
|
+
predictions = pred_array.flatten()
|
|
752
758
|
|
|
753
759
|
if show:
|
|
754
760
|
epsilon = 1e-10
|
|
@@ -792,7 +798,7 @@ class FichEn:
|
|
|
792
798
|
pred_array = pred_array.T
|
|
793
799
|
elif pred_array.shape[0] > 1 and pred_array.shape[1] == 30:
|
|
794
800
|
pred_array = pred_array[0:1, :]
|
|
795
|
-
predictions =
|
|
801
|
+
predictions = pred_array.flatten()
|
|
796
802
|
|
|
797
803
|
if show:
|
|
798
804
|
epsilon = 1e-10
|
|
@@ -826,13 +832,13 @@ class FichEn:
|
|
|
826
832
|
mean_str = ','.join(str(x) for x in scaler_data['mean'])
|
|
827
833
|
std_str = ','.join(str(x) for x in scaler_data['std'])
|
|
828
834
|
|
|
829
|
-
scaler_data_y = {
|
|
835
|
+
"""scaler_data_y = {
|
|
830
836
|
"mean": self.scaler_y.mean_.tolist() if self.scaler_y.mean_ is not None else [],
|
|
831
837
|
"std": self.scaler_y.scale_.tolist() if self.scaler_y.scale_ is not None else [],
|
|
832
838
|
"var": self.scaler_y.var_.tolist() if self.scaler_y.var_ is not None else []
|
|
833
839
|
}
|
|
834
840
|
mean_str_y = ','.join(str(x) for x in scaler_data_y['mean'])
|
|
835
|
-
std_str_y = ','.join(str(x) for x in scaler_data_y['std'])
|
|
841
|
+
std_str_y = ','.join(str(x) for x in scaler_data_y['std'])"""
|
|
836
842
|
|
|
837
843
|
|
|
838
844
|
os.makedirs(name, exist_ok=True)
|
|
@@ -864,8 +870,8 @@ class FichEn:
|
|
|
864
870
|
f.write(f"double mean_[] = {{{mean_str}}};\n\n")
|
|
865
871
|
f.write(f"double std_[] = {{{std_str}}};\n\n")
|
|
866
872
|
|
|
867
|
-
f.write(f"double mean_y[] = {{{mean_str_y}}};\n\n")
|
|
868
|
-
f.write(f"double std_y[] = {{{std_str_y}}};\n\n")
|
|
873
|
+
#f.write(f"double mean_y[] = {{{mean_str_y}}};\n\n")
|
|
874
|
+
#f.write(f"double std_y[] = {{{std_str_y}}};\n\n")
|
|
869
875
|
|
|
870
876
|
f.write("//--- indicator buffers\n")
|
|
871
877
|
f.write("double past_vol[];\n")
|
|
@@ -1479,7 +1485,7 @@ class VolClustGB(FichEn):
|
|
|
1479
1485
|
self.output = output
|
|
1480
1486
|
self.models = []
|
|
1481
1487
|
self.scaler = StandardScaler()
|
|
1482
|
-
self.scaler_y = StandardScaler()
|
|
1488
|
+
#self.scaler_y = StandardScaler()
|
|
1483
1489
|
self.X_shape = 0
|
|
1484
1490
|
self.is_fitted = False
|
|
1485
1491
|
self.onnx_load = False
|
|
@@ -1530,9 +1536,9 @@ class VolClustGB(FichEn):
|
|
|
1530
1536
|
scaler_path = os.path.join(name, f"{name}_scaler.pkl")
|
|
1531
1537
|
joblib.dump(self.scaler, scaler_path)
|
|
1532
1538
|
|
|
1533
|
-
if hasattr(self, 'scaler_y'):
|
|
1539
|
+
"""if hasattr(self, 'scaler_y'):
|
|
1534
1540
|
scaler_path = os.path.join(name, f"{name}_scaler_y.pkl")
|
|
1535
|
-
joblib.dump(self.scaler_y, scaler_path)
|
|
1541
|
+
joblib.dump(self.scaler_y, scaler_path)"""
|
|
1536
1542
|
|
|
1537
1543
|
for i in range(len(self.models)):
|
|
1538
1544
|
onx = convert_sklearn(self.models[i], initial_types=initial_type, target_opset=12)
|
|
@@ -1554,10 +1560,10 @@ class VolClustGB(FichEn):
|
|
|
1554
1560
|
joblib.dump(self.scaler, scaler_path)
|
|
1555
1561
|
self.dquantprint(f"Scaler is saved in {scaler_path}")
|
|
1556
1562
|
|
|
1557
|
-
if hasattr(self, 'scaler_y') and self.scaler_y is not None:
|
|
1563
|
+
"""if hasattr(self, 'scaler_y') and self.scaler_y is not None:
|
|
1558
1564
|
scaler_path = os.path.join(onnx_dir, f"{name}_scaler_y.pkl")
|
|
1559
1565
|
joblib.dump(self.scaler_y, scaler_path)
|
|
1560
|
-
self.dquantprint(f"Scalery is saved in {scaler_path}")
|
|
1566
|
+
self.dquantprint(f"Scalery is saved in {scaler_path}")"""
|
|
1561
1567
|
|
|
1562
1568
|
for i in range(len(self.models)):
|
|
1563
1569
|
onx = convert_sklearn(self.models[i], initial_types=initial_type, target_opset=12)
|
|
@@ -1599,10 +1605,10 @@ class VolClustGB(FichEn):
|
|
|
1599
1605
|
scaler_path = os.path.join(name, scaler_files[0])
|
|
1600
1606
|
self.scaler = joblib.load(scaler_path)
|
|
1601
1607
|
|
|
1602
|
-
scaler_files = [f for f in os.listdir(name) if f.endswith('_scaler_y.pkl')]
|
|
1608
|
+
"""scaler_files = [f for f in os.listdir(name) if f.endswith('_scaler_y.pkl')]
|
|
1603
1609
|
if scaler_files:
|
|
1604
|
-
scaler_path = os.path.join(name, scaler_files[0])
|
|
1605
|
-
self.scaler_y = joblib.load(scaler_path)
|
|
1610
|
+
scaler_path = os.path.join(name, scaler_files[0])"""
|
|
1611
|
+
#self.scaler_y = joblib.load(scaler_path)
|
|
1606
1612
|
|
|
1607
1613
|
model_files = [f for f in os.listdir(name) if f.endswith('.onnx')]
|
|
1608
1614
|
|
|
@@ -1641,7 +1647,7 @@ class VolClustXGB(FichEn):
|
|
|
1641
1647
|
self.output = output
|
|
1642
1648
|
self.models = []
|
|
1643
1649
|
self.scaler = StandardScaler()
|
|
1644
|
-
self.scaler_y = StandardScaler()
|
|
1650
|
+
#self.scaler_y = StandardScaler()
|
|
1645
1651
|
self.X_shape = 0
|
|
1646
1652
|
self.is_fitted = False
|
|
1647
1653
|
self.onnx_load = False
|
|
@@ -1711,9 +1717,9 @@ class VolClustXGB(FichEn):
|
|
|
1711
1717
|
scaler_path = os.path.join(name, f"{name}_scaler.pkl")
|
|
1712
1718
|
joblib.dump(self.scaler, scaler_path)
|
|
1713
1719
|
|
|
1714
|
-
if hasattr(self, 'scaler_y'):
|
|
1720
|
+
"""if hasattr(self, 'scaler_y'):
|
|
1715
1721
|
scaler_path = os.path.join(name, f"{name}_scaler_y.pkl")
|
|
1716
|
-
joblib.dump(self.scaler_y, scaler_path)
|
|
1722
|
+
joblib.dump(self.scaler_y, scaler_path)"""
|
|
1717
1723
|
|
|
1718
1724
|
for i in range(len(self.models)):
|
|
1719
1725
|
onx = onnxmltools.convert_xgboost(self.models[i], initial_types=initial_type, target_opset=12)
|
|
@@ -1733,10 +1739,10 @@ class VolClustXGB(FichEn):
|
|
|
1733
1739
|
joblib.dump(self.scaler, scaler_path)
|
|
1734
1740
|
self.dquantprint(f"Scaler is saved in {scaler_path}")
|
|
1735
1741
|
|
|
1736
|
-
if hasattr(self, 'scaler_y') and self.scaler_y is not None:
|
|
1742
|
+
"""if hasattr(self, 'scaler_y') and self.scaler_y is not None:
|
|
1737
1743
|
scaler_path = os.path.join(onnx_dir, f"{name}_scaler_y.pkl")
|
|
1738
1744
|
joblib.dump(self.scaler_y, scaler_path)
|
|
1739
|
-
self.dquantprint(f"Scalery is saved in {scaler_path}")
|
|
1745
|
+
self.dquantprint(f"Scalery is saved in {scaler_path}")"""
|
|
1740
1746
|
|
|
1741
1747
|
for i in range(len(self.models)):
|
|
1742
1748
|
onx = onnxmltools.convert_xgboost(self.models[i], initial_types=initial_type, target_opset=9)
|
|
@@ -1778,10 +1784,10 @@ class VolClustXGB(FichEn):
|
|
|
1778
1784
|
scaler_path = os.path.join(name, scaler_files[0])
|
|
1779
1785
|
self.scaler = joblib.load(scaler_path)
|
|
1780
1786
|
|
|
1781
|
-
scaler_files = [f for f in os.listdir(name) if f.endswith('_scaler_y.pkl')]
|
|
1787
|
+
"""scaler_files = [f for f in os.listdir(name) if f.endswith('_scaler_y.pkl')]
|
|
1782
1788
|
if scaler_files:
|
|
1783
1789
|
scaler_path = os.path.join(name, scaler_files[0])
|
|
1784
|
-
self.scaler_y = joblib.load(scaler_path)
|
|
1790
|
+
#self.scaler_y = joblib.load(scaler_path)"""
|
|
1785
1791
|
|
|
1786
1792
|
model_files = [f for f in os.listdir(name) if f.endswith('.onnx')]
|
|
1787
1793
|
|
|
@@ -1818,7 +1824,7 @@ class VolClustLightGBM(FichEn):
|
|
|
1818
1824
|
self.output = output
|
|
1819
1825
|
self.models = []
|
|
1820
1826
|
self.scaler = StandardScaler()
|
|
1821
|
-
self.scaler_y = StandardScaler()
|
|
1827
|
+
#self.scaler_y = StandardScaler()
|
|
1822
1828
|
self.X_shape = 0
|
|
1823
1829
|
self.is_fitted = False
|
|
1824
1830
|
self.onnx_load = False
|
|
@@ -1890,9 +1896,9 @@ class VolClustLightGBM(FichEn):
|
|
|
1890
1896
|
scaler_path = os.path.join(name, f"{name}_scaler.pkl")
|
|
1891
1897
|
joblib.dump(self.scaler, scaler_path)
|
|
1892
1898
|
|
|
1893
|
-
if hasattr(self, 'scaler_y'):
|
|
1899
|
+
"""if hasattr(self, 'scaler_y'):
|
|
1894
1900
|
scaler_path = os.path.join(name, f"{name}_scaler_y.pkl")
|
|
1895
|
-
joblib.dump(self.scaler_y, scaler_path)
|
|
1901
|
+
joblib.dump(self.scaler_y, scaler_path)"""
|
|
1896
1902
|
|
|
1897
1903
|
for i in range(len(self.models)):
|
|
1898
1904
|
onx = onnxmltools.convert_lightgbm(self.models[i], initial_types=initial_type, zipmap=False,
|
|
@@ -1912,10 +1918,10 @@ class VolClustLightGBM(FichEn):
|
|
|
1912
1918
|
joblib.dump(self.scaler, scaler_path)
|
|
1913
1919
|
self.dquantprint(f"Scaler is saved in {scaler_path}")
|
|
1914
1920
|
|
|
1915
|
-
if hasattr(self, 'scaler_y') and self.scaler_y is not None:
|
|
1921
|
+
"""if hasattr(self, 'scaler_y') and self.scaler_y is not None:
|
|
1916
1922
|
scaler_path = os.path.join(onnx_dir, f"{name}_scaler_y.pkl")
|
|
1917
1923
|
joblib.dump(self.scaler_y, scaler_path)
|
|
1918
|
-
self.dquantprint(f"Scalery is saved in {scaler_path}")
|
|
1924
|
+
self.dquantprint(f"Scalery is saved in {scaler_path}")"""
|
|
1919
1925
|
|
|
1920
1926
|
for i in range(len(self.models)):
|
|
1921
1927
|
onx = onnxmltools.convert_lightgbm(self.models[i], initial_types=initial_type, zipmap=False,
|
|
@@ -1957,10 +1963,10 @@ class VolClustLightGBM(FichEn):
|
|
|
1957
1963
|
scaler_path = os.path.join(name, scaler_files[0])
|
|
1958
1964
|
self.scaler = joblib.load(scaler_path)
|
|
1959
1965
|
|
|
1960
|
-
scaler_files = [f for f in os.listdir(name) if f.endswith('_scaler_y.pkl')]
|
|
1966
|
+
"""scaler_files = [f for f in os.listdir(name) if f.endswith('_scaler_y.pkl')]
|
|
1961
1967
|
if scaler_files:
|
|
1962
1968
|
scaler_path = os.path.join(name, scaler_files[0])
|
|
1963
|
-
self.scaler_y = joblib.load(scaler_path)
|
|
1969
|
+
#self.scaler_y = joblib.load(scaler_path)"""
|
|
1964
1970
|
|
|
1965
1971
|
model_files = [f for f in os.listdir(name) if f.endswith('.onnx')]
|
|
1966
1972
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|