|
1 | | -# Predix Results Documentation |
| 1 | +# Predix Results Directory |
2 | 2 |
|
3 | | -Dieser Ordner enthält alle Backtesting-Ergebnisse, Faktor-Analysen und Performance-Daten. |
| 3 | +This directory stores all backtesting results, databases, and reports. |
4 | 4 |
|
5 | | -## ⚠️ WICHTIG |
6 | | - |
7 | | -**Dieser Ordner ist in `.gitignore` aufgenommen!** |
8 | | - |
9 | | -- Ergebnisse werden **NICHT** zu Git hinzugefügt |
10 | | -- Jeder Entwickler hat lokale Ergebnisse |
11 | | -- Sensible Performance-Daten bleiben privat |
| 5 | +**⚠️ IMPORTANT:** This directory is in `.gitignore` and will NOT be committed to GitHub. |
12 | 6 |
|
13 | 7 | --- |
14 | 8 |
|
15 | | -## 📁 Ordner-Struktur |
| 9 | +## 📁 Directory Structure |
16 | 10 |
|
17 | 11 | ``` |
18 | 12 | results/ |
19 | | -├── backtests/ # Einzelne Backtest-Ergebnisse (JSON, CSV) |
20 | | -│ ├── FactorName_20240402_120000.json |
21 | | -│ ├── FactorName_20240402_120000_returns.csv |
22 | | -│ └── FactorName_20240402_120000_equity.csv |
| 13 | +├── backtests/ # Individual factor backtest results (JSON, CSV) |
| 14 | +│ ├── FactorName_20260402_120000.json |
| 15 | +│ ├── FactorName_20260402_120000_returns.csv |
| 16 | +│ └── FactorName_20260402_120000_equity.csv |
23 | 17 | │ |
24 | | -├── factors/ # Faktor-spezifische Analysen |
| 18 | +├── db/ # SQLite database for all results |
| 19 | +│ └── backtest_results.db |
| 20 | +│ |
| 21 | +├── factors/ # Factor-specific analysis |
25 | 22 | │ ├── factor_performance.json |
26 | 23 | │ └── ic_history.csv |
27 | 24 | │ |
28 | | -├── runs/ # Komplette Run-Ergebnisse |
29 | | -│ ├── risk_report_20240402_120000.json |
30 | | -│ └── portfolio_weights_20240402.json |
31 | | -│ |
32 | | -├── logs/ # Backtesting-Logs |
33 | | -│ └── backtest_20240402.log |
| 25 | +├── runs/ # Complete run results & risk reports |
| 26 | +│ ├── risk_report_20260402_120000.json |
| 27 | +│ └── portfolio_weights_20260402.json |
34 | 28 | │ |
35 | | -└── db/ # SQLite-Datenbank |
36 | | - ├── backtest_results.db |
37 | | - └── test_export.json |
| 29 | +└── logs/ # Backtest logs |
| 30 | + └── backtest_20260402.log |
38 | 31 | ``` |
39 | 32 |
|
40 | 33 | --- |
41 | 34 |
|
42 | | -## 📊 Gespeicherte Daten |
| 35 | +## 📊 What Gets Stored |
43 | 36 |
|
44 | 37 | ### Backtests (`backtests/`) |
45 | 38 |
|
46 | | -Für jeden Faktor werden gespeichert: |
47 | | - |
48 | | -| Datei | Inhalt | |
49 | | -|-------|--------| |
50 | | -| `{Factor}_{Timestamp}.json` | Alle Metriken (IC, Sharpe, Drawdown, etc.) | |
51 | | -| `{Factor}_{Timestamp}_returns.csv` | Tägliche Returns | |
52 | | -| `{Factor}_{Timestamp}_equity.csv` | Equity Curve | |
53 | | - |
54 | | -**Metriken pro Faktor:** |
55 | | -- IC (Information Coefficient) |
56 | | -- ICIR (IC Information Ratio) |
57 | | -- Sharpe Ratio |
58 | | -- Sortino Ratio |
59 | | -- Calmar Ratio |
60 | | -- Annualized Return |
61 | | -- Max Drawdown |
62 | | -- Win Rate |
63 | | -- Total Trades |
64 | | - |
65 | | ---- |
66 | | - |
67 | | -### Datenbank (`db/backtest_results.db`) |
68 | | - |
69 | | -**Tabellen:** |
70 | | - |
71 | | -| Tabelle | Inhalt | |
72 | | -|---------|--------| |
73 | | -| `factors` | Alle generierten Faktoren | |
74 | | -| `backtest_runs` | Backtest-Durchläufe | |
75 | | -| `backtest_metrics` | Performance-Metriken pro Run | |
76 | | -| `daily_returns` | Tägliche Returns pro Run | |
77 | | -| `loop_results` | Loop-Zusammenfassungen | |
78 | | -| `factor_correlations` | Korrelationen zwischen Faktoren | |
79 | | - |
80 | | -**Abfragen:** |
81 | | - |
82 | | -```python |
83 | | -from rdagent.components.backtesting import ResultsDatabase |
84 | | - |
85 | | -db = ResultsDatabase() |
86 | | - |
87 | | -# Top 20 Faktoren nach Sharpe Ratio |
88 | | -top_factors = db.get_top_factors('sharpe_ratio', limit=20) |
89 | | - |
90 | | -# Performance-Historie für Faktor |
91 | | -perf = db.get_factor_performance('Momentum_8Bar') |
92 | | - |
93 | | -# Loop-Zusammenfassung |
94 | | -loops = db.get_loop_summary() |
95 | | - |
96 | | -# Aggregierte Statistiken |
97 | | -stats = db.get_aggregate_stats() |
| 39 | +For each factor backtest: |
| 40 | +- **JSON file**: All metrics (IC, Sharpe, Drawdown, Win Rate, etc.) |
| 41 | +- **Returns CSV**: Daily returns time series |
| 42 | +- **Equity CSV**: Equity curve |
| 43 | + |
| 44 | +**Example JSON:** |
| 45 | +```json |
| 46 | +{ |
| 47 | + "factor_name": "Momentum_8Bar", |
| 48 | + "ic": 0.045, |
| 49 | + "sharpe_ratio": 1.85, |
| 50 | + "max_drawdown": -0.08, |
| 51 | + "win_rate": 0.58, |
| 52 | + "total_trades": 252, |
| 53 | + "timestamp": "2026-04-02T12:00:00" |
| 54 | +} |
98 | 55 | ``` |
99 | 56 |
|
100 | | ---- |
| 57 | +### Database (`db/backtest_results.db`) |
| 58 | + |
| 59 | +SQLite database with tables: |
| 60 | +- `factors` - All generated factors |
| 61 | +- `backtest_runs` - Backtest results with metrics |
| 62 | +- `backtest_metrics` - Detailed metrics per run |
| 63 | +- `daily_returns` - Daily returns time series |
| 64 | +- `loop_results` - Loop execution summaries |
101 | 65 |
|
102 | 66 | ### Risk Reports (`runs/`) |
103 | 67 |
|
104 | | -**Inhalt:** |
105 | | -- Portfolio-Volatilität |
| 68 | +- Portfolio volatility |
106 | 69 | - Sharpe Ratio |
107 | | -- Diversifikations-Ratio |
| 70 | +- Diversification Ratio |
108 | 71 | - Max Drawdown |
109 | | -- Limit-Checks (Position Size, Leverage, Drawdown) |
110 | | -- Korrelationsmatrix |
| 72 | +- Limit Checks (Position Size, Leverage, Drawdown) |
| 73 | +- Correlation Matrix |
111 | 74 |
|
112 | 75 | --- |
113 | 76 |
|
114 | | -## 🔧 Verwendung |
| 77 | +## 🔍 Querying Results |
115 | 78 |
|
116 | | -### 1. Backtest durchführen |
| 79 | +### Python Example |
117 | 80 |
|
118 | 81 | ```python |
119 | | -from rdagent.components.backtesting import FactorBacktester, ResultsDatabase |
| 82 | +from rdagent.components.backtesting import ResultsDatabase |
120 | 83 |
|
121 | | -# Backtester initialisieren |
122 | | -backtester = FactorBacktester() |
| 84 | +# Connect to database |
123 | 85 | db = ResultsDatabase() |
124 | 86 |
|
125 | | -# Faktor-Daten laden |
126 | | -factor_values = pd.Series(...) # Faktorwerte |
127 | | -forward_returns = pd.Series(...) # Forward Returns |
128 | | - |
129 | | -# Backtest durchführen |
130 | | -metrics = backtester.run_backtest( |
131 | | - factor_values=factor_values, |
132 | | - forward_returns=forward_returns, |
133 | | - factor_name="MyFactor" |
134 | | -) |
135 | | - |
136 | | -# In Datenbank speichern |
137 | | -db.add_backtest_run( |
138 | | - factor_name="MyFactor", |
139 | | - metrics=metrics, |
140 | | - returns=..., |
141 | | - equity_curve=... |
142 | | -) |
143 | | -``` |
144 | | - |
145 | | -### 2. Portfolio-Optimierung |
146 | | - |
147 | | -```python |
148 | | -from rdagent.components.backtesting import PortfolioOptimizer, CorrelationAnalyzer |
149 | | - |
150 | | -# Korrelationsmatrix |
151 | | -corr_analyzer = CorrelationAnalyzer() |
152 | | -corr_matrix = corr_analyzer.calculate_correlation_matrix(factor_returns) |
153 | | - |
154 | | -# Optimierung |
155 | | -optimizer = PortfolioOptimizer() |
156 | | -weights = optimizer.mean_variance_optimization( |
157 | | - expected_returns=expected_returns, |
158 | | - cov_matrix=cov_matrix |
159 | | -) |
160 | | - |
161 | | -# Speichern |
162 | | -optimizer.save_optimization_results(weights, factor_names, 'mean_variance') |
163 | | -``` |
164 | | - |
165 | | -### 3. Risiko-Bericht |
166 | | - |
167 | | -```python |
168 | | -from rdagent.components.backtesting import AdvancedRiskManager |
169 | | - |
170 | | -risk_manager = AdvancedRiskManager() |
| 87 | +# Get top 20 factors by Sharpe Ratio |
| 88 | +top_factors = db.get_top_factors('sharpe_ratio', limit=20) |
| 89 | +print(top_factors) |
171 | 90 |
|
172 | | -report = risk_manager.generate_risk_report( |
173 | | - factor_returns=factor_returns, |
174 | | - portfolio_weights=weights |
175 | | -) |
| 91 | +# Get aggregate statistics |
| 92 | +stats = db.get_aggregate_stats() |
| 93 | +print(f"Total factors: {stats['total_factors']}") |
| 94 | +print(f"Average IC: {stats['avg_ic']}") |
| 95 | +print(f"Max Sharpe: {stats['max_sharpe']}") |
176 | 96 |
|
177 | | -print(f"Sharpe: {report['sharpe_ratio']:.2f}") |
178 | | -print(f"Alle Limits OK: {report['all_limits_ok']}") |
| 97 | +# Close connection |
| 98 | +db.close() |
179 | 99 | ``` |
180 | 100 |
|
181 | | ---- |
| 101 | +### SQL Example |
182 | 102 |
|
183 | | -## 📈 Export |
| 103 | +```bash |
| 104 | +# Open database |
| 105 | +sqlite3 results/db/backtest_results.db |
184 | 106 |
|
185 | | -### JSON Export |
| 107 | +# Query top factors |
| 108 | +SELECT factor_name, sharpe, ic, win_rate |
| 109 | +FROM backtest_runs |
| 110 | +ORDER BY sharpe DESC |
| 111 | +LIMIT 10; |
186 | 112 |
|
187 | | -```python |
188 | | -db.export_to_json("results/db/full_export.json") |
| 113 | +# Get aggregate stats |
| 114 | +SELECT COUNT(*) as total_factors, |
| 115 | + AVG(ic) as avg_ic, |
| 116 | + MAX(sharpe) as max_sharpe |
| 117 | +FROM backtest_runs; |
189 | 118 | ``` |
190 | 119 |
|
191 | | -**Inhalt:** |
192 | | -- Aggregierte Statistiken |
193 | | -- Top-Faktoren |
194 | | -- Loop-Zusammenfassung |
195 | | -- Export-Datum |
196 | | - |
197 | 120 | --- |
198 | 121 |
|
199 | | -## 🎯 Ziel-Metriken |
| 122 | +## 🧹 Cleanup |
200 | 123 |
|
201 | | -| Metrik | Ziel | Minimum | |
202 | | -|--------|------|---------| |
203 | | -| **IC** | > 0.05 | > 0.02 | |
204 | | -| **ICIR** | > 2.0 | > 1.0 | |
205 | | -| **Sharpe Ratio** | > 2.0 | > 1.0 | |
206 | | -| **Max Drawdown** | < 15% | < 25% | |
207 | | -| **Win Rate** | > 55% | > 45% | |
208 | | -| **Annualized Return** | > 10% | > 5% | |
| 124 | +To clean up old results: |
209 | 125 |
|
210 | | ---- |
211 | | - |
212 | | -## 📝 Dokumentation |
213 | | - |
214 | | -Jeder Backtest wird automatisch dokumentiert mit: |
215 | | -- Timestamp |
216 | | -- Faktor-Name |
217 | | -- Alle Metriken |
218 | | -- Returns & Equity Curve |
219 | | -- Konfigurierte Parameter (Transaction Costs, etc.) |
| 126 | +```bash |
| 127 | +# Remove all results |
| 128 | +rm -rf results/* |
220 | 129 |
|
221 | | -**Manuelle Notizen:** |
222 | | -- Erstelle `results/logs/notes_YYYYMMDD.md` für manuelle Notizen |
223 | | -- Dokumentiere besondere Ereignisse (Markt-Crashes, etc.) |
| 130 | +# Remove only backtests |
| 131 | +rm -rf results/backtests/* |
224 | 132 |
|
225 | | ---- |
226 | | - |
227 | | -## 🔒 Datenschutz |
| 133 | +# Remove database |
| 134 | +rm -f results/db/backtest_results.db |
228 | 135 |
|
229 | | -- Ergebnisse sind **lokal** (nicht in Git) |
230 | | -- Datenbank ist **lokal** (SQLite) |
231 | | -- Bei Team-Nutzung: Ergebnisse manuell teilen oder zentrale DB verwenden |
| 136 | +# Keep logs but remove everything else |
| 137 | +find results/ -type f ! -path "*/logs/*" -delete |
| 138 | +``` |
232 | 139 |
|
233 | 140 | --- |
234 | 141 |
|
235 | | -## 🚀 Nächste Schritte |
| 142 | +## 📝 Notes |
236 | 143 |
|
237 | | -1. **Backtesting für alle 110 Faktoren durchführen** |
238 | | -2. **Top-20 Faktoren nach IC/Sharpe auswählen** |
239 | | -3. **Portfolio-Optimierung durchführen** |
240 | | -4. **4 Wochen Paper-Trading** |
241 | | -5. **Live-Performance dokumentieren** |
| 144 | +- Results are stored locally and never committed to Git |
| 145 | +- Database is automatically created on first run |
| 146 | +- JSON files are human-readable for quick inspection |
| 147 | +- Use SQLite database for programmatic access |
| 148 | +- Logs are stored separately for debugging |
242 | 149 |
|
243 | 150 | --- |
244 | 151 |
|
245 | | -**Stand:** April 2026 |
246 | | -**Version:** 1.0 |
| 152 | +**For detailed usage guidelines, see [README.md](../README.md)** |
0 commit comments