|
75 | 75 | "cell_type": "markdown", |
76 | 76 | "id": "3", |
77 | 77 | "metadata": {}, |
| 78 | + "source": [ |
| 79 | + "## Step 1b — Tag Your Backtests\n", |
| 80 | + "\n", |
| 81 | + "Tags let you label and group strategies — for example by batch name, experiment,\n", |
| 82 | + "or configuration variant. Tags are **persisted** in a `tag.json` file inside\n", |
| 83 | + "each backtest directory, so they survive across subsequent loads.\n", |
| 84 | + "\n", |
| 85 | + "### How tags get assigned\n", |
| 86 | + "\n", |
| 87 | + "There are three ways a backtest gets a tag:\n", |
| 88 | + "\n", |
| 89 | + "**1. During the backtest run** — Set `tag` in the strategy metadata:\n", |
| 90 | + "```python\n", |
| 91 | + "strategy = TradingStrategy(\n", |
| 92 | + " algorithm_id=\"momentum_v3\",\n", |
| 93 | + " metadata={\"tag\": \"experiment_A\"},\n", |
| 94 | + " ...\n", |
| 95 | + ")\n", |
| 96 | + "```\n", |
| 97 | + "The tag is automatically extracted and saved with the backtest.\n", |
| 98 | + "\n", |
| 99 | + "**2. After the fact with `retag_backtests()`** — Retag all backtests in a\n", |
| 100 | + "directory (or filter by strategy_id):\n", |
| 101 | + "```python\n", |
| 102 | + "from investing_algorithm_framework import retag_backtests\n", |
| 103 | + "\n", |
| 104 | + "# Tag everything in a directory\n", |
| 105 | + "retag_backtests(\"experiment_A\", directory_path=\"my_batch\")\n", |
| 106 | + "\n", |
| 107 | + "# Tag only a specific strategy\n", |
| 108 | + "retag_backtests(\"experiment_B\", directory_path=\"my_batch\", strategy_id=\"momentum_v3\")\n", |
| 109 | + "```\n", |
| 110 | + "\n", |
| 111 | + "**3. Multi-directory loading** — When you load from multiple directories,\n", |
| 112 | + "each directory name is used as the default tag (unless a persisted tag exists):\n", |
| 113 | + "```python\n", |
| 114 | + "report = BacktestReport.open(directory_path=[\"batch_A\", \"batch_B\"])\n", |
| 115 | + "# Strategies from batch_A get tag \"batch_A\", etc.\n", |
| 116 | + "```\n", |
| 117 | + "\n", |
| 118 | + "### What tags do in the dashboard\n", |
| 119 | + "\n", |
| 120 | + "- **Filter bar** — When 2+ tags exist, a chip-based filter bar appears at the top\n", |
| 121 | + "- **Tag badges** — Every strategy name shows its tag badge in all tables\n", |
| 122 | + "- **Collapsible sidebar groups** — Strategies are grouped by tag with collapsible headers\n", |
| 123 | + "- **MCP server** — The `list_strategies` and `get_strategy_details` tools include tag info" |
| 124 | + ] |
| 125 | + }, |
| 126 | + { |
| 127 | + "cell_type": "code", |
| 128 | + "execution_count": null, |
| 129 | + "id": "4", |
| 130 | + "metadata": {}, |
| 131 | + "outputs": [], |
| 132 | + "source": [ |
| 133 | + "from investing_algorithm_framework import retag_backtests\n", |
| 134 | + "\n", |
| 135 | + "# Retag all backtests in a directory\n", |
| 136 | + "count = retag_backtests(\"experiment_A\", directory_path=batch_dir)\n", |
| 137 | + "print(f\"Retagged {count} backtests with tag 'experiment_A'\")\n", |
| 138 | + "\n", |
| 139 | + "# Retag a single strategy by its algorithm_id\n", |
| 140 | + "count = retag_backtests(\n", |
| 141 | + " \"experiment_B\",\n", |
| 142 | + " directory_path=batch_dir,\n", |
| 143 | + " strategy_id=\"momentum_v3\"\n", |
| 144 | + ")\n", |
| 145 | + "print(f\"Retagged {count} backtests with tag 'experiment_B'\")\n", |
| 146 | + "\n", |
| 147 | + "# Reload to see the tags\n", |
| 148 | + "report = BacktestReport.open(directory_path=batch_dir)\n", |
| 149 | + "for bt in report.backtests:\n", |
| 150 | + " print(f\" • {bt.algorithm_id}: tag={bt.tag}\")" |
| 151 | + ] |
| 152 | + }, |
| 153 | + { |
| 154 | + "cell_type": "markdown", |
| 155 | + "id": "5", |
| 156 | + "metadata": {}, |
| 157 | + "source": [ |
| 158 | + "### Multi-directory loading\n", |
| 159 | + "\n", |
| 160 | + "You can also load backtests from **multiple directories** at once by passing a list.\n", |
| 161 | + "Each directory name becomes the default tag for its strategies (unless they already\n", |
| 162 | + "have a persisted tag)." |
| 163 | + ] |
| 164 | + }, |
| 165 | + { |
| 166 | + "cell_type": "code", |
| 167 | + "execution_count": null, |
| 168 | + "id": "6", |
| 169 | + "metadata": {}, |
| 170 | + "outputs": [], |
| 171 | + "source": [ |
| 172 | + "# Load from multiple directories — each dir name becomes the tag\n", |
| 173 | + "report = BacktestReport.open(directory_path=[\"batch_A\", \"batch_B\"])\n", |
| 174 | + "\n", |
| 175 | + "for bt in report.backtests:\n", |
| 176 | + " print(f\" • {bt.algorithm_id}: tag={bt.tag}\")\n", |
| 177 | + "\n", |
| 178 | + "# Open the dashboard — strategies will be grouped by tag in the sidebar\n", |
| 179 | + "report.show()" |
| 180 | + ] |
| 181 | + }, |
| 182 | + { |
| 183 | + "cell_type": "markdown", |
| 184 | + "id": "7", |
| 185 | + "metadata": {}, |
78 | 186 | "source": [ |
79 | 187 | "## Step 2 — Open the Interactive Dashboard\n", |
80 | 188 | "\n", |
|
91 | 199 | { |
92 | 200 | "cell_type": "code", |
93 | 201 | "execution_count": null, |
94 | | - "id": "4", |
| 202 | + "id": "8", |
95 | 203 | "metadata": {}, |
96 | 204 | "outputs": [], |
97 | 205 | "source": [] |
98 | 206 | }, |
99 | 207 | { |
100 | 208 | "cell_type": "code", |
101 | 209 | "execution_count": null, |
102 | | - "id": "5", |
| 210 | + "id": "9", |
103 | 211 | "metadata": {}, |
104 | 212 | "outputs": [], |
105 | 213 | "source": [ |
|
109 | 217 | }, |
110 | 218 | { |
111 | 219 | "cell_type": "markdown", |
112 | | - "id": "6", |
| 220 | + "id": "10", |
113 | 221 | "metadata": {}, |
114 | 222 | "source": [ |
115 | 223 | "## Step 3 — Start the MCP Server (Connect Your LLM)\n", |
|
155 | 263 | }, |
156 | 264 | { |
157 | 265 | "cell_type": "markdown", |
158 | | - "id": "7", |
| 266 | + "id": "11", |
159 | 267 | "metadata": {}, |
160 | 268 | "source": [ |
161 | 269 | "## Step 4 — The LLM Toolkit (23 MCP Tools)\n", |
|
204 | 312 | }, |
205 | 313 | { |
206 | 314 | "cell_type": "markdown", |
207 | | - "id": "8", |
| 315 | + "id": "12", |
208 | 316 | "metadata": {}, |
209 | 317 | "source": [ |
210 | 318 | "## Step 5 — Ask the LLM to Analyze Your Strategies\n", |
|
265 | 373 | }, |
266 | 374 | { |
267 | 375 | "cell_type": "markdown", |
268 | | - "id": "9", |
| 376 | + "id": "13", |
269 | 377 | "metadata": {}, |
270 | 378 | "source": [ |
271 | 379 | "## Step 6 — The Iterative Workflow\n", |
|
320 | 428 | }, |
321 | 429 | { |
322 | 430 | "cell_type": "markdown", |
323 | | - "id": "10", |
| 431 | + "id": "14", |
324 | 432 | "metadata": {}, |
325 | 433 | "source": [ |
326 | 434 | "## Step 7 — Notes as Self-Contained Analysis Documents\n", |
|
360 | 468 | }, |
361 | 469 | { |
362 | 470 | "cell_type": "markdown", |
363 | | - "id": "11", |
| 471 | + "id": "15", |
364 | 472 | "metadata": {}, |
365 | 473 | "source": [ |
366 | 474 | "## Step 8 — Example Conversation with the LLM\n", |
|
419 | 527 | }, |
420 | 528 | { |
421 | 529 | "cell_type": "markdown", |
422 | | - "id": "12", |
| 530 | + "id": "16", |
423 | 531 | "metadata": {}, |
424 | 532 | "source": [ |
425 | 533 | "## Step 9 — Apply Selections & Export\n", |
|
456 | 564 | }, |
457 | 565 | { |
458 | 566 | "cell_type": "markdown", |
459 | | - "id": "13", |
| 567 | + "id": "17", |
460 | 568 | "metadata": {}, |
461 | 569 | "source": [ |
462 | 570 | "## Step 10 — You Can Also Save / Reload Programmatically\n", |
|
469 | 577 | { |
470 | 578 | "cell_type": "code", |
471 | 579 | "execution_count": null, |
472 | | - "id": "14", |
| 580 | + "id": "18", |
473 | 581 | "metadata": {}, |
474 | 582 | "outputs": [], |
475 | 583 | "source": [ |
|
480 | 588 | }, |
481 | 589 | { |
482 | 590 | "cell_type": "markdown", |
483 | | - "id": "15", |
| 591 | + "id": "19", |
484 | 592 | "metadata": {}, |
485 | 593 | "source": [ |
486 | 594 | "## TL;DR — The Complete Workflow\n", |
487 | 595 | "\n", |
488 | 596 | "```python\n", |
489 | | - "from investing_algorithm_framework import BacktestReport, recalculate_backtests\n", |
| 597 | + "from investing_algorithm_framework import (\n", |
| 598 | + " BacktestReport, recalculate_backtests, retag_backtests\n", |
| 599 | + ")\n", |
490 | 600 | "\n", |
491 | 601 | "# 1. Load all backtests\n", |
492 | 602 | "report = BacktestReport.open(directory_path=\"my_batch\")\n", |
493 | 603 | "recalculate_backtests(report.backtests)\n", |
494 | 604 | "\n", |
| 605 | + "# 1b. (Optional) Tag your backtests\n", |
| 606 | + "retag_backtests(\"experiment_A\", directory_path=\"my_batch\")\n", |
| 607 | + "\n", |
| 608 | + "# 1c. (Optional) Load from multiple directories (auto-tagged by dir name)\n", |
| 609 | + "report = BacktestReport.open(directory_path=[\"batch_A\", \"batch_B\"])\n", |
| 610 | + "\n", |
495 | 611 | "# 2. Open the dashboard\n", |
496 | 612 | "report.show()\n", |
497 | 613 | "```\n", |
|
510 | 626 | "# 5. On the dashboard:\n", |
511 | 627 | "- Read the LLM's notes\n", |
512 | 628 | "- Click \"Apply Selection\" to filter\n", |
| 629 | + "- Use the tag filter bar to show/hide batches\n", |
513 | 630 | "- Capture more snapshots\n", |
514 | 631 | "- Export the final report\n", |
515 | 632 | "```\n", |
|
0 commit comments