Skip to content

Commit 223a9c0

Browse files
Merge pull request #42 from The-Pulse-Engine/docs/sync-v0.2.2-flow-ver
Sync documentation to current codebase state (v0.2.2)
2 parents bbe770f + e075d14 commit 223a9c0

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

Docs/code_flow.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ flowchart TD
4545

4646
## 2. Background Full-Market Scan
4747

48-
`_run_background_scan` delegates entirely to `app.scan.run_scan()`. News is fetched once and reused across all 24 assets processed sequentially. Per-asset snapshots are saved via `analyse_asset(save=True)`.
48+
`_run_background_scan` delegates entirely to `app.scan.run_scan()`. News is fetched once and reused across all 24 assets. A `price_cache` (`{ticker: change_1d}`) is pre-built via `fetch_all_metrics_parallel` before the loop, eliminating redundant yfinance calls during context analysis. Each asset is analysed with `with_market_ctx=True` and `save=True`.
4949

5050
```mermaid
5151
flowchart TD
@@ -57,7 +57,7 @@ flowchart TD
5757
5858
FETCHNEWS --> LOOPSTART{Next asset in\nTRACKED_ASSETS?}
5959
60-
LOOPSTART -->|More assets| ANALYSE[analyse_asset\nasset_name ticker category articles\nwith_market_ctx=False\nsave=True]
60+
LOOPSTART -->|More assets| ANALYSE[analyse_asset\nasset_name ticker category articles\nwith_market_ctx=True\nsave=True\nprice_cache=price_cache]
6161
LOOPSTART -->|All done| SUMMARY
6262
6363
ANALYSE --> ASUCCESS{Success?}

Docs/variable_list.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ Returns `dict`:
301301

302302
---
303303

304-
#### `analyse_asset(asset_name, ticker, category, articles, with_market_ctx, save)`
304+
#### `analyse_asset(asset_name, ticker, category, articles, with_market_ctx, save, price_cache)`
305305

306306
| Parameter | Type | Default | Description |
307307
|---|---|---|---|
@@ -311,6 +311,7 @@ Returns `dict`:
311311
| `articles` | `list[dict]` || Pre-fetched article pool |
312312
| `with_market_ctx` | `bool` | `False` | Whether to run `analyse_market_context` |
313313
| `save` | `bool` | `False` | Whether to persist a snapshot via `save_snapshot`. Only the batch scan pipeline passes `True`. |
314+
| `price_cache` | `Optional[dict[str, float]]` | `None` | Pre-built `{ticker: change_1d}` map. Passed to `analyse_market_context` so peer/benchmark lookups are served from memory instead of making extra yfinance calls. Has no effect when `with_market_ctx=False`. |
314315

315316
Returns `dict`:
316317

@@ -326,6 +327,7 @@ Returns `dict`:
326327
| `signal` | `dict` | Output of `compute_signal_score` |
327328
| `explanation` | `dict` | Output of `build_explanation` |
328329
| `historical_features` | `dict` | Output of `storage.get_historical_features` |
330+
| `error` | `Optional[dict]` | Error payload dict if price fetch failed, otherwise `None`. Contains `type`, `exception`, `stage`, `message` keys. |
329331

330332
---
331333

@@ -341,7 +343,7 @@ Fetches price metrics and momentum for every tracked asset in parallel using `PR
341343
{category: {asset_name: {"metrics": <price_metrics_dict>, "momentum": <momentum_dict>}}}
342344
```
343345

344-
Available for external use but not called by the dashboard directly. The dashboard heatmap and category overview use `cached_scan_summary()` in `dashboard/data.py` instead.
346+
Called by `app/scan.py` during the batch pipeline to pre-build the `price_cache` before the per-asset loop (eliminating ~50–80 redundant yfinance calls). Also available for external use. The dashboard heatmap and category overview use `cached_scan_summary()` in `dashboard/data.py` rather than calling this directly.
345347

346348
---
347349

@@ -509,8 +511,11 @@ These functions live in `dashboard/components.py`.
509511
| `scan_time` | `str` | ISO datetime string of scan start |
510512
| `total` | `int` | Total number of assets processed |
511513
| `succeeded` | `int` | Number of assets that completed without error |
512-
| `errors` | `list[dict]` | List of error dicts each with `asset`, `category`, `error` keys |
514+
| `errors` | `list[dict]` | List of error dicts each with `asset`, `category`, `type`, `stage`, `message` keys |
513515
| `results` | `dict[str, dict[str, dict]]` | Nested `{category: {asset_name: entry_dict}}` |
516+
| `top_movers` | `dict` | Pre-computed dict with `gainers` and `losers` lists (top 5 each by 24h change) |
517+
| `heatmap` | `dict` | Pre-computed heatmap matrix with `z`, `text`, `categories`, `max_assets` keys for the Plotly heatmap |
518+
| `category_rows` | `dict` | Pre-computed per-category row data: `{category: {"rows": list, "missing": list}}` |
514519

515520
### Entry Dict Within `results`
516521

@@ -522,14 +527,18 @@ These functions live in `dashboard/components.py`.
522527
| `price` | `Optional[float]` | Latest close price |
523528
| `change_1d` | `Optional[float]` | 1-day percentage change |
524529
| `change_7d` | `Optional[float]` | 7-day percentage change |
530+
| `change_30d` | `Optional[float]` | 30-day percentage change |
531+
| `volatility` | `Optional[float]` | Daily return std deviation * 100 |
525532
| `trend` | `Optional[str]` | Trend classification |
526533
| `rsi` | `Optional[float]` | 14-period RSI |
527534
| `roc_10d` | `Optional[float]` | 10-day ROC |
535+
| `trend_strength` | `Optional[float]` | MA divergence percentage |
536+
| `momentum_accel` | `Optional[float]` | ROC acceleration |
528537
| `confidence` | `Optional[str]` | Explanation confidence level |
529538
| `verdict` | `str` | One-line summary string |
530-
| `top_movers` | `dict` | Pre-computed dict with `gainers` and `losers` lists (top 5 each by 24h change) |
531-
| `heatmap` | `dict` | Pre-computed heatmap matrix with `z`, `text`, `categories`, `max_assets` keys for the Plotly heatmap |
532-
| `category_rows` | `dict` | Pre-computed per-category row data for the category overview table: `{category: {"rows": list, "missing": list}}` |
539+
| `is_market_wide` | `bool` | True if the benchmark moved > 0.5% in the same direction |
540+
| `is_sector_wide` | `bool` | True if >= 60% of sector peers moved in the same direction |
541+
| `error` | `Optional[dict]` | Error payload if price fetch failed, otherwise absent |
533542

534543
### `load_last_scan_summary()` Return Structure
535544

0 commit comments

Comments
 (0)