ml4t-diagnostic 0.1.0a1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ml4t/diagnostic/AGENT.md +25 -0
- ml4t/diagnostic/__init__.py +166 -0
- ml4t/diagnostic/backends/__init__.py +10 -0
- ml4t/diagnostic/backends/adapter.py +192 -0
- ml4t/diagnostic/backends/polars_backend.py +899 -0
- ml4t/diagnostic/caching/__init__.py +40 -0
- ml4t/diagnostic/caching/cache.py +331 -0
- ml4t/diagnostic/caching/decorators.py +131 -0
- ml4t/diagnostic/caching/smart_cache.py +339 -0
- ml4t/diagnostic/config/AGENT.md +24 -0
- ml4t/diagnostic/config/README.md +267 -0
- ml4t/diagnostic/config/__init__.py +219 -0
- ml4t/diagnostic/config/barrier_config.py +277 -0
- ml4t/diagnostic/config/base.py +301 -0
- ml4t/diagnostic/config/event_config.py +148 -0
- ml4t/diagnostic/config/feature_config.py +404 -0
- ml4t/diagnostic/config/multi_signal_config.py +55 -0
- ml4t/diagnostic/config/portfolio_config.py +215 -0
- ml4t/diagnostic/config/report_config.py +391 -0
- ml4t/diagnostic/config/sharpe_config.py +202 -0
- ml4t/diagnostic/config/signal_config.py +206 -0
- ml4t/diagnostic/config/trade_analysis_config.py +310 -0
- ml4t/diagnostic/config/validation.py +279 -0
- ml4t/diagnostic/core/__init__.py +29 -0
- ml4t/diagnostic/core/numba_utils.py +315 -0
- ml4t/diagnostic/core/purging.py +372 -0
- ml4t/diagnostic/core/sampling.py +471 -0
- ml4t/diagnostic/errors/__init__.py +205 -0
- ml4t/diagnostic/evaluation/AGENT.md +26 -0
- ml4t/diagnostic/evaluation/__init__.py +437 -0
- ml4t/diagnostic/evaluation/autocorrelation.py +531 -0
- ml4t/diagnostic/evaluation/barrier_analysis.py +1050 -0
- ml4t/diagnostic/evaluation/binary_metrics.py +910 -0
- ml4t/diagnostic/evaluation/dashboard.py +715 -0
- ml4t/diagnostic/evaluation/diagnostic_plots.py +1037 -0
- ml4t/diagnostic/evaluation/distribution/__init__.py +499 -0
- ml4t/diagnostic/evaluation/distribution/moments.py +299 -0
- ml4t/diagnostic/evaluation/distribution/tails.py +777 -0
- ml4t/diagnostic/evaluation/distribution/tests.py +470 -0
- ml4t/diagnostic/evaluation/drift/__init__.py +139 -0
- ml4t/diagnostic/evaluation/drift/analysis.py +432 -0
- ml4t/diagnostic/evaluation/drift/domain_classifier.py +517 -0
- ml4t/diagnostic/evaluation/drift/population_stability_index.py +310 -0
- ml4t/diagnostic/evaluation/drift/wasserstein.py +388 -0
- ml4t/diagnostic/evaluation/event_analysis.py +647 -0
- ml4t/diagnostic/evaluation/excursion.py +390 -0
- ml4t/diagnostic/evaluation/feature_diagnostics.py +873 -0
- ml4t/diagnostic/evaluation/feature_outcome.py +666 -0
- ml4t/diagnostic/evaluation/framework.py +935 -0
- ml4t/diagnostic/evaluation/metric_registry.py +255 -0
- ml4t/diagnostic/evaluation/metrics/AGENT.md +23 -0
- ml4t/diagnostic/evaluation/metrics/__init__.py +133 -0
- ml4t/diagnostic/evaluation/metrics/basic.py +160 -0
- ml4t/diagnostic/evaluation/metrics/conditional_ic.py +469 -0
- ml4t/diagnostic/evaluation/metrics/feature_outcome.py +475 -0
- ml4t/diagnostic/evaluation/metrics/ic_statistics.py +446 -0
- ml4t/diagnostic/evaluation/metrics/importance_analysis.py +338 -0
- ml4t/diagnostic/evaluation/metrics/importance_classical.py +375 -0
- ml4t/diagnostic/evaluation/metrics/importance_mda.py +371 -0
- ml4t/diagnostic/evaluation/metrics/importance_shap.py +715 -0
- ml4t/diagnostic/evaluation/metrics/information_coefficient.py +527 -0
- ml4t/diagnostic/evaluation/metrics/interactions.py +772 -0
- ml4t/diagnostic/evaluation/metrics/monotonicity.py +226 -0
- ml4t/diagnostic/evaluation/metrics/risk_adjusted.py +324 -0
- ml4t/diagnostic/evaluation/multi_signal.py +550 -0
- ml4t/diagnostic/evaluation/portfolio_analysis/__init__.py +83 -0
- ml4t/diagnostic/evaluation/portfolio_analysis/analysis.py +734 -0
- ml4t/diagnostic/evaluation/portfolio_analysis/metrics.py +589 -0
- ml4t/diagnostic/evaluation/portfolio_analysis/results.py +334 -0
- ml4t/diagnostic/evaluation/report_generation.py +824 -0
- ml4t/diagnostic/evaluation/signal_selector.py +452 -0
- ml4t/diagnostic/evaluation/stat_registry.py +139 -0
- ml4t/diagnostic/evaluation/stationarity/__init__.py +97 -0
- ml4t/diagnostic/evaluation/stationarity/analysis.py +518 -0
- ml4t/diagnostic/evaluation/stationarity/augmented_dickey_fuller.py +296 -0
- ml4t/diagnostic/evaluation/stationarity/kpss_test.py +308 -0
- ml4t/diagnostic/evaluation/stationarity/phillips_perron.py +365 -0
- ml4t/diagnostic/evaluation/stats/AGENT.md +43 -0
- ml4t/diagnostic/evaluation/stats/__init__.py +191 -0
- ml4t/diagnostic/evaluation/stats/backtest_overfitting.py +219 -0
- ml4t/diagnostic/evaluation/stats/bootstrap.py +228 -0
- ml4t/diagnostic/evaluation/stats/deflated_sharpe_ratio.py +591 -0
- ml4t/diagnostic/evaluation/stats/false_discovery_rate.py +295 -0
- ml4t/diagnostic/evaluation/stats/hac_standard_errors.py +108 -0
- ml4t/diagnostic/evaluation/stats/minimum_track_record.py +408 -0
- ml4t/diagnostic/evaluation/stats/moments.py +164 -0
- ml4t/diagnostic/evaluation/stats/rademacher_adjustment.py +436 -0
- ml4t/diagnostic/evaluation/stats/reality_check.py +155 -0
- ml4t/diagnostic/evaluation/stats/sharpe_inference.py +219 -0
- ml4t/diagnostic/evaluation/themes.py +330 -0
- ml4t/diagnostic/evaluation/threshold_analysis.py +957 -0
- ml4t/diagnostic/evaluation/trade_analysis.py +1136 -0
- ml4t/diagnostic/evaluation/trade_dashboard/__init__.py +32 -0
- ml4t/diagnostic/evaluation/trade_dashboard/app.py +315 -0
- ml4t/diagnostic/evaluation/trade_dashboard/export/__init__.py +18 -0
- ml4t/diagnostic/evaluation/trade_dashboard/export/csv.py +82 -0
- ml4t/diagnostic/evaluation/trade_dashboard/export/html.py +276 -0
- ml4t/diagnostic/evaluation/trade_dashboard/io.py +166 -0
- ml4t/diagnostic/evaluation/trade_dashboard/normalize.py +304 -0
- ml4t/diagnostic/evaluation/trade_dashboard/stats.py +386 -0
- ml4t/diagnostic/evaluation/trade_dashboard/style.py +79 -0
- ml4t/diagnostic/evaluation/trade_dashboard/tabs/__init__.py +21 -0
- ml4t/diagnostic/evaluation/trade_dashboard/tabs/patterns.py +354 -0
- ml4t/diagnostic/evaluation/trade_dashboard/tabs/shap_analysis.py +280 -0
- ml4t/diagnostic/evaluation/trade_dashboard/tabs/stat_validation.py +186 -0
- ml4t/diagnostic/evaluation/trade_dashboard/tabs/worst_trades.py +236 -0
- ml4t/diagnostic/evaluation/trade_dashboard/types.py +129 -0
- ml4t/diagnostic/evaluation/trade_shap/__init__.py +102 -0
- ml4t/diagnostic/evaluation/trade_shap/alignment.py +188 -0
- ml4t/diagnostic/evaluation/trade_shap/characterize.py +413 -0
- ml4t/diagnostic/evaluation/trade_shap/cluster.py +302 -0
- ml4t/diagnostic/evaluation/trade_shap/explain.py +208 -0
- ml4t/diagnostic/evaluation/trade_shap/hypotheses/__init__.py +23 -0
- ml4t/diagnostic/evaluation/trade_shap/hypotheses/generator.py +290 -0
- ml4t/diagnostic/evaluation/trade_shap/hypotheses/matcher.py +251 -0
- ml4t/diagnostic/evaluation/trade_shap/hypotheses/templates.yaml +467 -0
- ml4t/diagnostic/evaluation/trade_shap/models.py +386 -0
- ml4t/diagnostic/evaluation/trade_shap/normalize.py +116 -0
- ml4t/diagnostic/evaluation/trade_shap/pipeline.py +263 -0
- ml4t/diagnostic/evaluation/trade_shap_dashboard.py +283 -0
- ml4t/diagnostic/evaluation/trade_shap_diagnostics.py +588 -0
- ml4t/diagnostic/evaluation/validated_cv.py +535 -0
- ml4t/diagnostic/evaluation/visualization.py +1050 -0
- ml4t/diagnostic/evaluation/volatility/__init__.py +45 -0
- ml4t/diagnostic/evaluation/volatility/analysis.py +351 -0
- ml4t/diagnostic/evaluation/volatility/arch.py +258 -0
- ml4t/diagnostic/evaluation/volatility/garch.py +460 -0
- ml4t/diagnostic/integration/__init__.py +48 -0
- ml4t/diagnostic/integration/backtest_contract.py +671 -0
- ml4t/diagnostic/integration/data_contract.py +316 -0
- ml4t/diagnostic/integration/engineer_contract.py +226 -0
- ml4t/diagnostic/logging/__init__.py +77 -0
- ml4t/diagnostic/logging/logger.py +245 -0
- ml4t/diagnostic/logging/performance.py +234 -0
- ml4t/diagnostic/logging/progress.py +234 -0
- ml4t/diagnostic/logging/wandb.py +412 -0
- ml4t/diagnostic/metrics/__init__.py +9 -0
- ml4t/diagnostic/metrics/percentiles.py +128 -0
- ml4t/diagnostic/py.typed +1 -0
- ml4t/diagnostic/reporting/__init__.py +43 -0
- ml4t/diagnostic/reporting/base.py +130 -0
- ml4t/diagnostic/reporting/html_renderer.py +275 -0
- ml4t/diagnostic/reporting/json_renderer.py +51 -0
- ml4t/diagnostic/reporting/markdown_renderer.py +117 -0
- ml4t/diagnostic/results/AGENT.md +24 -0
- ml4t/diagnostic/results/__init__.py +105 -0
- ml4t/diagnostic/results/barrier_results/__init__.py +36 -0
- ml4t/diagnostic/results/barrier_results/hit_rate.py +304 -0
- ml4t/diagnostic/results/barrier_results/precision_recall.py +266 -0
- ml4t/diagnostic/results/barrier_results/profit_factor.py +297 -0
- ml4t/diagnostic/results/barrier_results/tearsheet.py +397 -0
- ml4t/diagnostic/results/barrier_results/time_to_target.py +305 -0
- ml4t/diagnostic/results/barrier_results/validation.py +38 -0
- ml4t/diagnostic/results/base.py +177 -0
- ml4t/diagnostic/results/event_results.py +349 -0
- ml4t/diagnostic/results/feature_results.py +787 -0
- ml4t/diagnostic/results/multi_signal_results.py +431 -0
- ml4t/diagnostic/results/portfolio_results.py +281 -0
- ml4t/diagnostic/results/sharpe_results.py +448 -0
- ml4t/diagnostic/results/signal_results/__init__.py +74 -0
- ml4t/diagnostic/results/signal_results/ic.py +581 -0
- ml4t/diagnostic/results/signal_results/irtc.py +110 -0
- ml4t/diagnostic/results/signal_results/quantile.py +392 -0
- ml4t/diagnostic/results/signal_results/tearsheet.py +456 -0
- ml4t/diagnostic/results/signal_results/turnover.py +213 -0
- ml4t/diagnostic/results/signal_results/validation.py +147 -0
- ml4t/diagnostic/signal/AGENT.md +17 -0
- ml4t/diagnostic/signal/__init__.py +69 -0
- ml4t/diagnostic/signal/_report.py +152 -0
- ml4t/diagnostic/signal/_utils.py +261 -0
- ml4t/diagnostic/signal/core.py +275 -0
- ml4t/diagnostic/signal/quantile.py +148 -0
- ml4t/diagnostic/signal/result.py +214 -0
- ml4t/diagnostic/signal/signal_ic.py +129 -0
- ml4t/diagnostic/signal/turnover.py +182 -0
- ml4t/diagnostic/splitters/AGENT.md +19 -0
- ml4t/diagnostic/splitters/__init__.py +36 -0
- ml4t/diagnostic/splitters/base.py +501 -0
- ml4t/diagnostic/splitters/calendar.py +421 -0
- ml4t/diagnostic/splitters/calendar_config.py +91 -0
- ml4t/diagnostic/splitters/combinatorial.py +1064 -0
- ml4t/diagnostic/splitters/config.py +322 -0
- ml4t/diagnostic/splitters/cpcv/__init__.py +57 -0
- ml4t/diagnostic/splitters/cpcv/combinations.py +119 -0
- ml4t/diagnostic/splitters/cpcv/partitioning.py +263 -0
- ml4t/diagnostic/splitters/cpcv/purge_engine.py +379 -0
- ml4t/diagnostic/splitters/cpcv/windows.py +190 -0
- ml4t/diagnostic/splitters/group_isolation.py +329 -0
- ml4t/diagnostic/splitters/persistence.py +316 -0
- ml4t/diagnostic/splitters/utils.py +207 -0
- ml4t/diagnostic/splitters/walk_forward.py +757 -0
- ml4t/diagnostic/utils/__init__.py +42 -0
- ml4t/diagnostic/utils/config.py +542 -0
- ml4t/diagnostic/utils/dependencies.py +318 -0
- ml4t/diagnostic/utils/sessions.py +127 -0
- ml4t/diagnostic/validation/__init__.py +54 -0
- ml4t/diagnostic/validation/dataframe.py +274 -0
- ml4t/diagnostic/validation/returns.py +280 -0
- ml4t/diagnostic/validation/timeseries.py +299 -0
- ml4t/diagnostic/visualization/AGENT.md +19 -0
- ml4t/diagnostic/visualization/__init__.py +223 -0
- ml4t/diagnostic/visualization/backtest/__init__.py +98 -0
- ml4t/diagnostic/visualization/backtest/cost_attribution.py +762 -0
- ml4t/diagnostic/visualization/backtest/executive_summary.py +895 -0
- ml4t/diagnostic/visualization/backtest/interactive_controls.py +673 -0
- ml4t/diagnostic/visualization/backtest/statistical_validity.py +874 -0
- ml4t/diagnostic/visualization/backtest/tearsheet.py +565 -0
- ml4t/diagnostic/visualization/backtest/template_system.py +373 -0
- ml4t/diagnostic/visualization/backtest/trade_plots.py +1172 -0
- ml4t/diagnostic/visualization/barrier_plots.py +782 -0
- ml4t/diagnostic/visualization/core.py +1060 -0
- ml4t/diagnostic/visualization/dashboards/__init__.py +36 -0
- ml4t/diagnostic/visualization/dashboards/base.py +582 -0
- ml4t/diagnostic/visualization/dashboards/importance.py +801 -0
- ml4t/diagnostic/visualization/dashboards/interaction.py +263 -0
- ml4t/diagnostic/visualization/dashboards.py +43 -0
- ml4t/diagnostic/visualization/data_extraction/__init__.py +48 -0
- ml4t/diagnostic/visualization/data_extraction/importance.py +649 -0
- ml4t/diagnostic/visualization/data_extraction/interaction.py +504 -0
- ml4t/diagnostic/visualization/data_extraction/types.py +113 -0
- ml4t/diagnostic/visualization/data_extraction/validation.py +66 -0
- ml4t/diagnostic/visualization/feature_plots.py +888 -0
- ml4t/diagnostic/visualization/interaction_plots.py +618 -0
- ml4t/diagnostic/visualization/portfolio/__init__.py +41 -0
- ml4t/diagnostic/visualization/portfolio/dashboard.py +514 -0
- ml4t/diagnostic/visualization/portfolio/drawdown_plots.py +341 -0
- ml4t/diagnostic/visualization/portfolio/returns_plots.py +487 -0
- ml4t/diagnostic/visualization/portfolio/risk_plots.py +301 -0
- ml4t/diagnostic/visualization/report_generation.py +1343 -0
- ml4t/diagnostic/visualization/signal/__init__.py +103 -0
- ml4t/diagnostic/visualization/signal/dashboard.py +911 -0
- ml4t/diagnostic/visualization/signal/event_plots.py +514 -0
- ml4t/diagnostic/visualization/signal/ic_plots.py +635 -0
- ml4t/diagnostic/visualization/signal/multi_signal_dashboard.py +974 -0
- ml4t/diagnostic/visualization/signal/multi_signal_plots.py +603 -0
- ml4t/diagnostic/visualization/signal/quantile_plots.py +625 -0
- ml4t/diagnostic/visualization/signal/turnover_plots.py +400 -0
- ml4t/diagnostic/visualization/trade_shap/__init__.py +90 -0
- ml4t_diagnostic-0.1.0a1.dist-info/METADATA +1044 -0
- ml4t_diagnostic-0.1.0a1.dist-info/RECORD +242 -0
- ml4t_diagnostic-0.1.0a1.dist-info/WHEEL +4 -0
- ml4t_diagnostic-0.1.0a1.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"""ML4T Diagnostic Configuration System.
|
|
2
|
+
|
|
3
|
+
This module provides comprehensive Pydantic v2 configuration schemas for the
|
|
4
|
+
ML4T Diagnostic framework, covering:
|
|
5
|
+
|
|
6
|
+
- **Feature Evaluation**: Diagnostics, cross-feature analysis, feature-outcome relationships
|
|
7
|
+
- **Portfolio Evaluation**: Risk/return metrics, Bayesian comparison
|
|
8
|
+
- **Statistical Framework**: PSR, MinTRL, DSR, FDR for multiple testing correction
|
|
9
|
+
- **Reporting**: HTML, JSON, visualization settings
|
|
10
|
+
|
|
11
|
+
Examples:
|
|
12
|
+
Quick start with defaults:
|
|
13
|
+
|
|
14
|
+
>>> from ml4t.diagnostic.config import DiagnosticConfig
|
|
15
|
+
>>> config = DiagnosticConfig()
|
|
16
|
+
|
|
17
|
+
Custom configuration:
|
|
18
|
+
|
|
19
|
+
>>> config = DiagnosticConfig(
|
|
20
|
+
... stationarity=StationaritySettings(significance_level=0.01),
|
|
21
|
+
... ic=ICSettings(lag_structure=[0, 1, 5, 10]),
|
|
22
|
+
... )
|
|
23
|
+
|
|
24
|
+
Load from YAML:
|
|
25
|
+
|
|
26
|
+
>>> config = DiagnosticConfig.from_yaml("config.yaml")
|
|
27
|
+
|
|
28
|
+
Use presets:
|
|
29
|
+
|
|
30
|
+
>>> config = DiagnosticConfig.for_quick_analysis()
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
# Base configuration
|
|
34
|
+
# Barrier analysis configuration
|
|
35
|
+
from ml4t.diagnostic.config.barrier_config import (
|
|
36
|
+
AnalysisSettings as BarrierAnalysisSettings,
|
|
37
|
+
)
|
|
38
|
+
from ml4t.diagnostic.config.barrier_config import (
|
|
39
|
+
BarrierConfig,
|
|
40
|
+
BarrierLabel,
|
|
41
|
+
DecileMethod,
|
|
42
|
+
)
|
|
43
|
+
from ml4t.diagnostic.config.barrier_config import (
|
|
44
|
+
ColumnSettings as BarrierColumnSettings,
|
|
45
|
+
)
|
|
46
|
+
from ml4t.diagnostic.config.barrier_config import (
|
|
47
|
+
VisualizationSettings as BarrierVisualizationSettings,
|
|
48
|
+
)
|
|
49
|
+
from ml4t.diagnostic.config.base import (
|
|
50
|
+
BaseConfig,
|
|
51
|
+
RuntimeConfig,
|
|
52
|
+
StatisticalTestConfig,
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
# Event study configuration
|
|
56
|
+
from ml4t.diagnostic.config.event_config import (
|
|
57
|
+
EventConfig,
|
|
58
|
+
)
|
|
59
|
+
from ml4t.diagnostic.config.event_config import (
|
|
60
|
+
WindowSettings as EventWindowSettings,
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
# Feature evaluation configuration (consolidated)
|
|
64
|
+
from ml4t.diagnostic.config.feature_config import (
|
|
65
|
+
ACFSettings,
|
|
66
|
+
BinaryClassificationSettings,
|
|
67
|
+
ClusteringSettings,
|
|
68
|
+
CorrelationSettings,
|
|
69
|
+
DiagnosticConfig,
|
|
70
|
+
DistributionSettings,
|
|
71
|
+
ICSettings,
|
|
72
|
+
MLDiagnosticsSettings,
|
|
73
|
+
PCASettings,
|
|
74
|
+
RedundancySettings,
|
|
75
|
+
StationaritySettings,
|
|
76
|
+
ThresholdAnalysisSettings,
|
|
77
|
+
VolatilitySettings,
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
# Multi-signal analysis configuration
|
|
81
|
+
from ml4t.diagnostic.config.multi_signal_config import (
|
|
82
|
+
MultiSignalAnalysisConfig,
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
# Portfolio evaluation configuration (consolidated)
|
|
86
|
+
from ml4t.diagnostic.config.portfolio_config import (
|
|
87
|
+
AggregationSettings as PortfolioAggregationSettings,
|
|
88
|
+
)
|
|
89
|
+
from ml4t.diagnostic.config.portfolio_config import (
|
|
90
|
+
BayesianSettings as PortfolioBayesianSettings,
|
|
91
|
+
)
|
|
92
|
+
from ml4t.diagnostic.config.portfolio_config import (
|
|
93
|
+
DrawdownSettings as PortfolioDrawdownSettings,
|
|
94
|
+
)
|
|
95
|
+
from ml4t.diagnostic.config.portfolio_config import (
|
|
96
|
+
MetricsSettings as PortfolioMetricsSettings,
|
|
97
|
+
)
|
|
98
|
+
from ml4t.diagnostic.config.portfolio_config import (
|
|
99
|
+
PortfolioConfig,
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
# Report configuration
|
|
103
|
+
from ml4t.diagnostic.config.report_config import (
|
|
104
|
+
HTMLConfig,
|
|
105
|
+
JSONConfig,
|
|
106
|
+
OutputFormatConfig,
|
|
107
|
+
ReportConfig,
|
|
108
|
+
VisualizationConfig,
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
# Statistical testing configuration (consolidated)
|
|
112
|
+
from ml4t.diagnostic.config.sharpe_config import (
|
|
113
|
+
DSRSettings,
|
|
114
|
+
FDRSettings,
|
|
115
|
+
MinTRLSettings,
|
|
116
|
+
PSRSettings,
|
|
117
|
+
StatisticalConfig,
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
# Signal analysis configuration (consolidated)
|
|
121
|
+
from ml4t.diagnostic.config.signal_config import (
|
|
122
|
+
AnalysisSettings as SignalAnalysisSettings,
|
|
123
|
+
)
|
|
124
|
+
from ml4t.diagnostic.config.signal_config import (
|
|
125
|
+
ICMethod,
|
|
126
|
+
MultiSignalSettings,
|
|
127
|
+
QuantileMethod,
|
|
128
|
+
RASSettings,
|
|
129
|
+
SignalConfig,
|
|
130
|
+
)
|
|
131
|
+
from ml4t.diagnostic.config.signal_config import (
|
|
132
|
+
VisualizationSettings as SignalVisualizationSettings,
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
# Trade analysis configuration (consolidated)
|
|
136
|
+
from ml4t.diagnostic.config.trade_analysis_config import (
|
|
137
|
+
AlignmentSettings as TradeAlignmentSettings,
|
|
138
|
+
)
|
|
139
|
+
from ml4t.diagnostic.config.trade_analysis_config import (
|
|
140
|
+
ClusteringSettings as TradeClusteringSettings,
|
|
141
|
+
)
|
|
142
|
+
from ml4t.diagnostic.config.trade_analysis_config import (
|
|
143
|
+
ExtractionSettings as TradeExtractionSettings,
|
|
144
|
+
)
|
|
145
|
+
from ml4t.diagnostic.config.trade_analysis_config import (
|
|
146
|
+
FilterSettings as TradeFilterSettings,
|
|
147
|
+
)
|
|
148
|
+
from ml4t.diagnostic.config.trade_analysis_config import (
|
|
149
|
+
HypothesisSettings as TradeHypothesisSettings,
|
|
150
|
+
)
|
|
151
|
+
from ml4t.diagnostic.config.trade_analysis_config import (
|
|
152
|
+
TradeConfig,
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
__all__ = [
|
|
156
|
+
# Base configs
|
|
157
|
+
"BaseConfig",
|
|
158
|
+
"StatisticalTestConfig",
|
|
159
|
+
"RuntimeConfig",
|
|
160
|
+
# Feature evaluation (consolidated)
|
|
161
|
+
"DiagnosticConfig",
|
|
162
|
+
"StationaritySettings",
|
|
163
|
+
"ACFSettings",
|
|
164
|
+
"VolatilitySettings",
|
|
165
|
+
"DistributionSettings",
|
|
166
|
+
"CorrelationSettings",
|
|
167
|
+
"PCASettings",
|
|
168
|
+
"ClusteringSettings",
|
|
169
|
+
"RedundancySettings",
|
|
170
|
+
"ICSettings",
|
|
171
|
+
"BinaryClassificationSettings",
|
|
172
|
+
"ThresholdAnalysisSettings",
|
|
173
|
+
"MLDiagnosticsSettings",
|
|
174
|
+
# Portfolio evaluation (consolidated)
|
|
175
|
+
"PortfolioConfig",
|
|
176
|
+
"PortfolioMetricsSettings",
|
|
177
|
+
"PortfolioBayesianSettings",
|
|
178
|
+
"PortfolioAggregationSettings",
|
|
179
|
+
"PortfolioDrawdownSettings",
|
|
180
|
+
# Statistical testing (consolidated)
|
|
181
|
+
"StatisticalConfig",
|
|
182
|
+
"PSRSettings",
|
|
183
|
+
"MinTRLSettings",
|
|
184
|
+
"DSRSettings",
|
|
185
|
+
"FDRSettings",
|
|
186
|
+
# Reporting
|
|
187
|
+
"ReportConfig",
|
|
188
|
+
"OutputFormatConfig",
|
|
189
|
+
"HTMLConfig",
|
|
190
|
+
"VisualizationConfig",
|
|
191
|
+
"JSONConfig",
|
|
192
|
+
# Trade analysis (consolidated)
|
|
193
|
+
"TradeConfig",
|
|
194
|
+
"TradeExtractionSettings",
|
|
195
|
+
"TradeFilterSettings",
|
|
196
|
+
"TradeAlignmentSettings",
|
|
197
|
+
"TradeClusteringSettings",
|
|
198
|
+
"TradeHypothesisSettings",
|
|
199
|
+
# Signal analysis (consolidated)
|
|
200
|
+
"SignalConfig",
|
|
201
|
+
"SignalAnalysisSettings",
|
|
202
|
+
"RASSettings",
|
|
203
|
+
"SignalVisualizationSettings",
|
|
204
|
+
"MultiSignalSettings",
|
|
205
|
+
"ICMethod",
|
|
206
|
+
"QuantileMethod",
|
|
207
|
+
# Event study (consolidated)
|
|
208
|
+
"EventConfig",
|
|
209
|
+
"EventWindowSettings",
|
|
210
|
+
# Multi-signal analysis
|
|
211
|
+
"MultiSignalAnalysisConfig",
|
|
212
|
+
# Barrier analysis (consolidated)
|
|
213
|
+
"BarrierConfig",
|
|
214
|
+
"BarrierAnalysisSettings",
|
|
215
|
+
"BarrierColumnSettings",
|
|
216
|
+
"BarrierVisualizationSettings",
|
|
217
|
+
"BarrierLabel",
|
|
218
|
+
"DecileMethod",
|
|
219
|
+
]
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
"""Configuration for Barrier Analysis module.
|
|
2
|
+
|
|
3
|
+
This module provides Pydantic configuration classes for controlling
|
|
4
|
+
barrier analysis behavior including hit rate calculation, profit factor
|
|
5
|
+
analysis, and visualization options.
|
|
6
|
+
|
|
7
|
+
Triple barrier outcomes from ml4t.features:
|
|
8
|
+
- label: int (-1=SL hit, 0=timeout, 1=TP hit)
|
|
9
|
+
- label_return: float (actual return at exit)
|
|
10
|
+
- label_bars: int (bars from entry to exit)
|
|
11
|
+
|
|
12
|
+
References
|
|
13
|
+
----------
|
|
14
|
+
Lopez de Prado, M. (2018). "Advances in Financial Machine Learning"
|
|
15
|
+
Chapter 3: Labeling (Triple Barrier Method)
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
from enum import Enum
|
|
21
|
+
from typing import Literal
|
|
22
|
+
|
|
23
|
+
from pydantic import Field, field_validator, model_validator
|
|
24
|
+
|
|
25
|
+
from ml4t.diagnostic.config.base import BaseConfig
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class BarrierLabel(int, Enum):
|
|
29
|
+
"""Triple barrier outcome labels."""
|
|
30
|
+
|
|
31
|
+
STOP_LOSS = -1 # Lower barrier hit
|
|
32
|
+
TIMEOUT = 0 # Time barrier hit
|
|
33
|
+
TAKE_PROFIT = 1 # Upper barrier hit
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class DecileMethod(str, Enum):
|
|
37
|
+
"""Method for assigning decile labels."""
|
|
38
|
+
|
|
39
|
+
QUANTILE = "quantile" # Equal frequency bins (pd.qcut style)
|
|
40
|
+
UNIFORM = "uniform" # Equal width bins (pd.cut style)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
# =============================================================================
|
|
44
|
+
# Settings Classes (Single-Level Nesting)
|
|
45
|
+
# =============================================================================
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class AnalysisSettings(BaseConfig):
|
|
49
|
+
"""Settings for barrier analysis calculations."""
|
|
50
|
+
|
|
51
|
+
n_quantiles: int = Field(
|
|
52
|
+
default=10,
|
|
53
|
+
ge=2,
|
|
54
|
+
le=20,
|
|
55
|
+
description="Number of quantile bins (deciles=10)",
|
|
56
|
+
)
|
|
57
|
+
decile_method: DecileMethod = Field(
|
|
58
|
+
default=DecileMethod.QUANTILE,
|
|
59
|
+
description="Method for quantile binning",
|
|
60
|
+
)
|
|
61
|
+
min_observations_per_quantile: int = Field(
|
|
62
|
+
default=30,
|
|
63
|
+
ge=10,
|
|
64
|
+
le=1000,
|
|
65
|
+
description="Minimum observations per quantile",
|
|
66
|
+
)
|
|
67
|
+
filter_zscore: float | None = Field(
|
|
68
|
+
default=3.0,
|
|
69
|
+
ge=1.0,
|
|
70
|
+
le=10.0,
|
|
71
|
+
description="Z-score threshold for outlier filtering (None to disable)",
|
|
72
|
+
)
|
|
73
|
+
drop_timeout: bool = Field(
|
|
74
|
+
default=False,
|
|
75
|
+
description="Exclude timeout outcomes from calculations",
|
|
76
|
+
)
|
|
77
|
+
significance_level: float = Field(
|
|
78
|
+
default=0.05,
|
|
79
|
+
ge=0.001,
|
|
80
|
+
le=0.20,
|
|
81
|
+
description="Significance level for statistical tests",
|
|
82
|
+
)
|
|
83
|
+
bootstrap_n_resamples: int = Field(
|
|
84
|
+
default=1000,
|
|
85
|
+
ge=100,
|
|
86
|
+
le=10000,
|
|
87
|
+
description="Number of bootstrap resamples",
|
|
88
|
+
)
|
|
89
|
+
hit_rate_min_observations: int = Field(
|
|
90
|
+
default=20,
|
|
91
|
+
ge=5,
|
|
92
|
+
le=500,
|
|
93
|
+
description="Minimum observations for hit rate reporting",
|
|
94
|
+
)
|
|
95
|
+
profit_factor_epsilon: float = Field(
|
|
96
|
+
default=1e-10,
|
|
97
|
+
ge=1e-15,
|
|
98
|
+
le=1e-6,
|
|
99
|
+
description="Epsilon for division safety",
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
class ColumnSettings(BaseConfig):
|
|
104
|
+
"""Settings for column name mappings."""
|
|
105
|
+
|
|
106
|
+
signal_col: str = Field(default="signal", description="Signal column name")
|
|
107
|
+
date_col: str = Field(default="date", description="Date column name")
|
|
108
|
+
asset_col: str = Field(default="asset", description="Asset column name")
|
|
109
|
+
label_col: str = Field(default="label", description="Barrier label column")
|
|
110
|
+
label_return_col: str = Field(default="label_return", description="Return at exit column")
|
|
111
|
+
label_bars_col: str = Field(default="label_bars", description="Bars to exit column")
|
|
112
|
+
|
|
113
|
+
@field_validator(
|
|
114
|
+
"signal_col", "date_col", "asset_col", "label_col", "label_return_col", "label_bars_col"
|
|
115
|
+
)
|
|
116
|
+
@classmethod
|
|
117
|
+
def validate_column_names(cls, v: str) -> str:
|
|
118
|
+
"""Ensure column names are non-empty."""
|
|
119
|
+
if not v or not v.strip():
|
|
120
|
+
raise ValueError("Column name must be non-empty")
|
|
121
|
+
return v.strip()
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
class VisualizationSettings(BaseConfig):
|
|
125
|
+
"""Settings for barrier tear sheet visualization."""
|
|
126
|
+
|
|
127
|
+
theme: Literal["default", "dark", "print", "presentation"] = Field(
|
|
128
|
+
default="default",
|
|
129
|
+
description="Plotly theme",
|
|
130
|
+
)
|
|
131
|
+
width: int = Field(
|
|
132
|
+
default=1000,
|
|
133
|
+
ge=400,
|
|
134
|
+
le=2000,
|
|
135
|
+
description="Plot width in pixels",
|
|
136
|
+
)
|
|
137
|
+
height_multiplier: float = Field(
|
|
138
|
+
default=1.0,
|
|
139
|
+
ge=0.5,
|
|
140
|
+
le=2.0,
|
|
141
|
+
description="Height scaling factor",
|
|
142
|
+
)
|
|
143
|
+
include_hit_rate_heatmap: bool = Field(default=True)
|
|
144
|
+
include_profit_factor: bool = Field(default=True)
|
|
145
|
+
include_time_to_target: bool = Field(default=True)
|
|
146
|
+
include_precision_recall: bool = Field(default=True)
|
|
147
|
+
include_summary_table: bool = Field(default=True)
|
|
148
|
+
html_self_contained: bool = Field(default=True)
|
|
149
|
+
html_include_plotlyjs: Literal["cdn", "directory", True, False] = Field(default="cdn")
|
|
150
|
+
export_data: bool = Field(default=False)
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
# =============================================================================
|
|
154
|
+
# Consolidated Config
|
|
155
|
+
# =============================================================================
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
class BarrierConfig(BaseConfig):
|
|
159
|
+
"""Consolidated configuration for barrier analysis.
|
|
160
|
+
|
|
161
|
+
Combines analysis settings, column mappings, and visualization options
|
|
162
|
+
into a single configuration class.
|
|
163
|
+
|
|
164
|
+
Examples
|
|
165
|
+
--------
|
|
166
|
+
>>> config = BarrierConfig(
|
|
167
|
+
... analysis=AnalysisSettings(n_quantiles=5),
|
|
168
|
+
... visualization=VisualizationSettings(theme="dark"),
|
|
169
|
+
... )
|
|
170
|
+
>>> config.to_yaml("barrier_config.yaml")
|
|
171
|
+
"""
|
|
172
|
+
|
|
173
|
+
analysis: AnalysisSettings = Field(
|
|
174
|
+
default_factory=AnalysisSettings,
|
|
175
|
+
description="Analysis calculation settings",
|
|
176
|
+
)
|
|
177
|
+
columns: ColumnSettings = Field(
|
|
178
|
+
default_factory=ColumnSettings,
|
|
179
|
+
description="Column name mappings",
|
|
180
|
+
)
|
|
181
|
+
visualization: VisualizationSettings = Field(
|
|
182
|
+
default_factory=VisualizationSettings,
|
|
183
|
+
description="Visualization settings",
|
|
184
|
+
)
|
|
185
|
+
signal_name: str = Field(
|
|
186
|
+
default="signal",
|
|
187
|
+
description="Signal name for reports",
|
|
188
|
+
)
|
|
189
|
+
return_pandas: bool = Field(
|
|
190
|
+
default=False,
|
|
191
|
+
description="Return pandas instead of Polars",
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
@model_validator(mode="after")
|
|
195
|
+
def validate_column_uniqueness(self) -> BarrierConfig:
|
|
196
|
+
"""Ensure column names don't conflict."""
|
|
197
|
+
cols = [self.columns.signal_col, self.columns.date_col, self.columns.asset_col]
|
|
198
|
+
if len(cols) != len(set(cols)):
|
|
199
|
+
raise ValueError(f"Column names must be unique: {cols}")
|
|
200
|
+
return self
|
|
201
|
+
|
|
202
|
+
# Convenience properties for flat access (backward compatibility)
|
|
203
|
+
@property
|
|
204
|
+
def n_quantiles(self) -> int:
|
|
205
|
+
"""Number of quantiles (shortcut)."""
|
|
206
|
+
return self.analysis.n_quantiles
|
|
207
|
+
|
|
208
|
+
@property
|
|
209
|
+
def significance_level(self) -> float:
|
|
210
|
+
"""Significance level (shortcut)."""
|
|
211
|
+
return self.analysis.significance_level
|
|
212
|
+
|
|
213
|
+
@property
|
|
214
|
+
def decile_method(self) -> DecileMethod:
|
|
215
|
+
"""Decile method (shortcut)."""
|
|
216
|
+
return self.analysis.decile_method
|
|
217
|
+
|
|
218
|
+
@property
|
|
219
|
+
def min_observations_per_quantile(self) -> int:
|
|
220
|
+
"""Minimum observations per quantile (shortcut)."""
|
|
221
|
+
return self.analysis.min_observations_per_quantile
|
|
222
|
+
|
|
223
|
+
@property
|
|
224
|
+
def filter_zscore(self) -> float | None:
|
|
225
|
+
"""Z-score filter threshold (shortcut)."""
|
|
226
|
+
return self.analysis.filter_zscore
|
|
227
|
+
|
|
228
|
+
@property
|
|
229
|
+
def drop_timeout(self) -> bool:
|
|
230
|
+
"""Drop timeout outcomes (shortcut)."""
|
|
231
|
+
return self.analysis.drop_timeout
|
|
232
|
+
|
|
233
|
+
@property
|
|
234
|
+
def bootstrap_n_resamples(self) -> int:
|
|
235
|
+
"""Bootstrap resamples (shortcut)."""
|
|
236
|
+
return self.analysis.bootstrap_n_resamples
|
|
237
|
+
|
|
238
|
+
@property
|
|
239
|
+
def hit_rate_min_observations(self) -> int:
|
|
240
|
+
"""Hit rate minimum observations (shortcut)."""
|
|
241
|
+
return self.analysis.hit_rate_min_observations
|
|
242
|
+
|
|
243
|
+
@property
|
|
244
|
+
def profit_factor_epsilon(self) -> float:
|
|
245
|
+
"""Profit factor epsilon (shortcut)."""
|
|
246
|
+
return self.analysis.profit_factor_epsilon
|
|
247
|
+
|
|
248
|
+
# Column name properties
|
|
249
|
+
@property
|
|
250
|
+
def signal_col(self) -> str:
|
|
251
|
+
"""Signal column name (shortcut)."""
|
|
252
|
+
return self.columns.signal_col
|
|
253
|
+
|
|
254
|
+
@property
|
|
255
|
+
def date_col(self) -> str:
|
|
256
|
+
"""Date column name (shortcut)."""
|
|
257
|
+
return self.columns.date_col
|
|
258
|
+
|
|
259
|
+
@property
|
|
260
|
+
def asset_col(self) -> str:
|
|
261
|
+
"""Asset column name (shortcut)."""
|
|
262
|
+
return self.columns.asset_col
|
|
263
|
+
|
|
264
|
+
@property
|
|
265
|
+
def label_col(self) -> str:
|
|
266
|
+
"""Label column name (shortcut)."""
|
|
267
|
+
return self.columns.label_col
|
|
268
|
+
|
|
269
|
+
@property
|
|
270
|
+
def label_return_col(self) -> str:
|
|
271
|
+
"""Label return column name (shortcut)."""
|
|
272
|
+
return self.columns.label_return_col
|
|
273
|
+
|
|
274
|
+
@property
|
|
275
|
+
def label_bars_col(self) -> str:
|
|
276
|
+
"""Label bars column name (shortcut)."""
|
|
277
|
+
return self.columns.label_bars_col
|