|
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", |
|
123 | 231 | "### Start the server from your terminal\n", |
124 | 232 | "\n", |
125 | 233 | "```bash\n", |
| 234 | + "# Single directory\n", |
126 | 235 | "iaf mcp -d your_batch_directory\n", |
| 236 | + "\n", |
| 237 | + "# Multiple directories — repeat -d for each\n", |
| 238 | + "iaf mcp -d batch_one -d batch_two -d batch_three\n", |
127 | 239 | "```\n", |
128 | 240 | "\n", |
129 | 241 | "Or if you haven't installed the CLI:\n", |
130 | 242 | "\n", |
131 | 243 | "```bash\n", |
132 | 244 | "python -m investing_algorithm_framework.cli.mcp_server -d your_batch_directory\n", |
| 245 | + "\n", |
| 246 | + "# Multiple directories\n", |
| 247 | + "python -m investing_algorithm_framework.cli.mcp_server -d batch_one -d batch_two\n", |
133 | 248 | "```\n", |
134 | 249 | "\n", |
135 | 250 | "### Configure VS Code to use it\n", |
|
142 | 257 | " \"servers\": {\n", |
143 | 258 | " \"backtest-analysis\": {\n", |
144 | 259 | " \"command\": \"iaf\",\n", |
145 | | - " \"args\": [\"mcp\", \"-d\", \"your_batch_directory\"]\n", |
| 260 | + " \"args\": [\"mcp\", \"-d\", \"batch_one\", \"-d\", \"batch_two\"]\n", |
146 | 261 | " }\n", |
147 | 262 | " }\n", |
148 | 263 | " }\n", |
|
155 | 270 | }, |
156 | 271 | { |
157 | 272 | "cell_type": "markdown", |
158 | | - "id": "7", |
| 273 | + "id": "11", |
159 | 274 | "metadata": {}, |
160 | 275 | "source": [ |
161 | 276 | "## Step 4 — The LLM Toolkit (23 MCP Tools)\n", |
|
204 | 319 | }, |
205 | 320 | { |
206 | 321 | "cell_type": "markdown", |
207 | | - "id": "8", |
| 322 | + "id": "12", |
208 | 323 | "metadata": {}, |
209 | 324 | "source": [ |
210 | 325 | "## Step 5 — Ask the LLM to Analyze Your Strategies\n", |
|
265 | 380 | }, |
266 | 381 | { |
267 | 382 | "cell_type": "markdown", |
268 | | - "id": "9", |
| 383 | + "id": "13", |
269 | 384 | "metadata": {}, |
270 | 385 | "source": [ |
271 | 386 | "## Step 6 — The Iterative Workflow\n", |
|
320 | 435 | }, |
321 | 436 | { |
322 | 437 | "cell_type": "markdown", |
323 | | - "id": "10", |
| 438 | + "id": "14", |
324 | 439 | "metadata": {}, |
325 | 440 | "source": [ |
326 | 441 | "## Step 7 — Notes as Self-Contained Analysis Documents\n", |
|
360 | 475 | }, |
361 | 476 | { |
362 | 477 | "cell_type": "markdown", |
363 | | - "id": "11", |
| 478 | + "id": "15", |
364 | 479 | "metadata": {}, |
365 | 480 | "source": [ |
366 | 481 | "## Step 8 — Example Conversation with the LLM\n", |
|
419 | 534 | }, |
420 | 535 | { |
421 | 536 | "cell_type": "markdown", |
422 | | - "id": "12", |
| 537 | + "id": "16", |
423 | 538 | "metadata": {}, |
424 | 539 | "source": [ |
425 | 540 | "## Step 9 — Apply Selections & Export\n", |
|
456 | 571 | }, |
457 | 572 | { |
458 | 573 | "cell_type": "markdown", |
459 | | - "id": "13", |
| 574 | + "id": "17", |
460 | 575 | "metadata": {}, |
461 | 576 | "source": [ |
462 | 577 | "## Step 10 — You Can Also Save / Reload Programmatically\n", |
|
469 | 584 | { |
470 | 585 | "cell_type": "code", |
471 | 586 | "execution_count": null, |
472 | | - "id": "14", |
| 587 | + "id": "18", |
473 | 588 | "metadata": {}, |
474 | 589 | "outputs": [], |
475 | 590 | "source": [ |
|
480 | 595 | }, |
481 | 596 | { |
482 | 597 | "cell_type": "markdown", |
483 | | - "id": "15", |
| 598 | + "id": "19", |
484 | 599 | "metadata": {}, |
485 | 600 | "source": [ |
486 | 601 | "## TL;DR — The Complete Workflow\n", |
|
499 | 614 | "```bash\n", |
500 | 615 | "# 3. Start the MCP server (in a separate terminal)\n", |
501 | 616 | "iaf mcp -d my_batch\n", |
| 617 | + "\n", |
| 618 | + "# Or load multiple batch directories at once\n", |
| 619 | + "iaf mcp -d batch_one -d batch_two\n", |
502 | 620 | "```\n", |
503 | 621 | "\n", |
504 | 622 | "```\n", |
|
0 commit comments