thetabook 2.1.2__tar.gz → 2.2.0__tar.gz
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.
- {thetabook-2.1.2 → thetabook-2.2.0}/CHANGELOG.md +61 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/CLAUDE.md +3 -1
- {thetabook-2.1.2 → thetabook-2.2.0}/PKG-INFO +1 -1
- {thetabook-2.1.2 → thetabook-2.2.0}/README.md +37 -6
- {thetabook-2.1.2 → thetabook-2.2.0}/pyproject.toml +4 -1
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/cli/__init__.py +1 -1
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/cli/import_csv.py +5 -3
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/portfolio/accounts.py +8 -1
- thetabook-2.2.0/src/thetabook/portfolio/csv_parsers/__init__.py +55 -0
- thetabook-2.2.0/src/thetabook/portfolio/csv_parsers/_base.py +118 -0
- thetabook-2.2.0/src/thetabook/portfolio/csv_parsers/empower.py +208 -0
- thetabook-2.2.0/src/thetabook/portfolio/csv_parsers/fidelity.py +161 -0
- thetabook-2.2.0/src/thetabook/portfolio/csv_parsers/schwab.py +152 -0
- thetabook-2.2.0/src/thetabook/portfolio/import_csv_snapshot.py +132 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/templates/accounts.toml.example +17 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/uv.lock +1 -1
- thetabook-2.1.2/.claude/commands/accounts-init.md +0 -45
- thetabook-2.1.2/.claude/commands/adjust.md +0 -84
- thetabook-2.1.2/.claude/commands/chain.md +0 -57
- thetabook-2.1.2/.claude/commands/close.md +0 -51
- thetabook-2.1.2/.claude/commands/diff.md +0 -47
- thetabook-2.1.2/.claude/commands/evaluate.md +0 -48
- thetabook-2.1.2/.claude/commands/greeks.md +0 -35
- thetabook-2.1.2/.claude/commands/idea.md +0 -48
- thetabook-2.1.2/.claude/commands/ideas.md +0 -29
- thetabook-2.1.2/.claude/commands/open.md +0 -40
- thetabook-2.1.2/.claude/commands/portfolio.md +0 -59
- thetabook-2.1.2/.claude/commands/price.md +0 -28
- thetabook-2.1.2/.claude/commands/refresh.md +0 -9
- thetabook-2.1.2/.claude/commands/roll-scenarios.md +0 -72
- thetabook-2.1.2/.claude/commands/roll.md +0 -125
- thetabook-2.1.2/.claude/commands/setup.md +0 -98
- thetabook-2.1.2/.claude/commands/wiki-lint.md +0 -77
- thetabook-2.1.2/docs/architecture.md +0 -406
- thetabook-2.1.2/docs/behaviors.md +0 -138
- thetabook-2.1.2/docs/cli.md +0 -136
- thetabook-2.1.2/docs/hosted-service-proposal.md +0 -113
- thetabook-2.1.2/docs/m23-audit.md +0 -43
- thetabook-2.1.2/docs/skills-roadmap.md +0 -174
- thetabook-2.1.2/docs/skills.md +0 -91
- thetabook-2.1.2/src/thetabook/portfolio/import_csv_snapshot.py +0 -397
- thetabook-2.1.2/tests/analysis/test_hv.py +0 -133
- thetabook-2.1.2/tests/analysis/test_scenarios.py +0 -364
- thetabook-2.1.2/tests/analysis/test_ta.py +0 -310
- thetabook-2.1.2/tests/cli/test_analysis_cli.py +0 -658
- thetabook-2.1.2/tests/cli/test_bs_cli.py +0 -120
- thetabook-2.1.2/tests/cli/test_init.py +0 -480
- thetabook-2.1.2/tests/cli/test_migrate_home.py +0 -183
- thetabook-2.1.2/tests/conftest.py +0 -277
- thetabook-2.1.2/tests/ideas/test_adjust.py +0 -1739
- thetabook-2.1.2/tests/ideas/test_core.py +0 -288
- thetabook-2.1.2/tests/ideas/test_evaluate_idea.py +0 -1921
- thetabook-2.1.2/tests/ideas/test_manage_ideas.py +0 -759
- thetabook-2.1.2/tests/ideas/test_roll_scenarios.py +0 -729
- thetabook-2.1.2/tests/market/test_bars.py +0 -884
- thetabook-2.1.2/tests/market/test_chains.py +0 -654
- thetabook-2.1.2/tests/market/test_dividends.py +0 -780
- thetabook-2.1.2/tests/market/test_earnings.py +0 -321
- thetabook-2.1.2/tests/market/test_leg_marks.py +0 -106
- thetabook-2.1.2/tests/market/test_prices.py +0 -658
- thetabook-2.1.2/tests/market/test_schwab.py +0 -106
- thetabook-2.1.2/tests/market/test_vol_lookup.py +0 -372
- thetabook-2.1.2/tests/portfolio/test_accounts.py +0 -981
- thetabook-2.1.2/tests/portfolio/test_diff_snapshots.py +0 -356
- thetabook-2.1.2/tests/portfolio/test_get_positions.py +0 -495
- thetabook-2.1.2/tests/portfolio/test_import_csv_snapshot.py +0 -375
- thetabook-2.1.2/tests/portfolio/test_scaffold.py +0 -92
- thetabook-2.1.2/tests/pricing/test_bs.py +0 -254
- thetabook-2.1.2/tests/pricing/test_greeks.py +0 -828
- thetabook-2.1.2/tests/skills/__init__.py +0 -0
- thetabook-2.1.2/tests/skills/conftest.py +0 -52
- thetabook-2.1.2/tests/skills/test_install.py +0 -641
- thetabook-2.1.2/tests/skills/test_lint.py +0 -220
- thetabook-2.1.2/tests/skills/test_models.py +0 -96
- thetabook-2.1.2/tests/skills/test_parse.py +0 -70
- thetabook-2.1.2/tests/skills/test_policy.py +0 -54
- thetabook-2.1.2/tests/skills/test_registry.py +0 -388
- thetabook-2.1.2/tests/skills/test_render.py +0 -55
- thetabook-2.1.2/tests/test_cache.py +0 -149
- thetabook-2.1.2/tests/test_cli.py +0 -800
- thetabook-2.1.2/tests/test_config.py +0 -77
- thetabook-2.1.2/tests/test_factories.py +0 -92
- thetabook-2.1.2/tests/test_leg_parse.py +0 -228
- thetabook-2.1.2/tests/test_log.py +0 -42
- thetabook-2.1.2/tests/test_models.py +0 -412
- thetabook-2.1.2/tests/test_paths.py +0 -502
- thetabook-2.1.2/tests/test_tickers.py +0 -262
- thetabook-2.1.2/tests/wiki/test_lint.py +0 -1069
- thetabook-2.1.2/tests/wiki/test_render.py +0 -442
- {thetabook-2.1.2 → thetabook-2.2.0}/.env.example +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/.github/workflows/ci.yml +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/.github/workflows/publish.yml +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/.gitignore +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/.python-version +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/CONTRIBUTING.md +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/LICENSE +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/ROADMAP.md +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/SECURITY.md +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/__init__.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/analysis/__init__.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/analysis/hv.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/analysis/scenarios.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/analysis/ta.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/cache.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/cli/_shared.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/cli/accounts.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/cli/adjust.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/cli/bars.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/cli/bs.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/cli/chain.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/cli/diff.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/cli/dividends.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/cli/earnings.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/cli/evaluate.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/cli/greeks.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/cli/hv.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/cli/ideas.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/cli/init.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/cli/leg_mark.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/cli/migrate_home.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/cli/price.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/cli/refresh.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/cli/roll.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/cli/scenarios.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/cli/skills.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/cli/snapshot.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/cli/ta.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/cli/tickers.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/cli/wiki.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/config.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/ideas/__init__.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/ideas/adjust.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/ideas/core.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/ideas/evaluate_idea.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/ideas/manage_ideas.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/ideas/roll_scenarios.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/leg_parse.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/log.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/market/__init__.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/market/_schwab.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/market/bars.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/market/chains.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/market/dividends.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/market/earnings.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/market/leg_marks.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/market/prices.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/market/vol_lookup.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/models.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/paths.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/portfolio/__init__.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/portfolio/diff_snapshots.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/portfolio/get_positions.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/portfolio/scaffold.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/pricing/__init__.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/pricing/bs.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/pricing/greeks.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/skills/__init__.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/skills/install.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/skills/lint.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/skills/models.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/skills/parse.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/skills/policy.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/skills/registry.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/skills/render.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/templates/README.md +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/templates/config.toml.example +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/templates/idea.md +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/templates/journal.md +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/templates/learnings.md +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/templates/skill.md +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/templates/skills/setup-thetabook.md +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/templates/wiki/index.md +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/templates/wiki/log.md +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/templates/wiki/overview.md +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/templates/wiki/strategy.md +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/templates/wiki/underlying.md +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/tickers.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/wiki/__init__.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/wiki/lint.py +0 -0
- {thetabook-2.1.2 → thetabook-2.2.0}/src/thetabook/wiki/render.py +0 -0
|
@@ -5,6 +5,67 @@ All notable changes to this project are recorded here. Format loosely follows
|
|
|
5
5
|
|
|
6
6
|
## [Unreleased]
|
|
7
7
|
|
|
8
|
+
## [2.2.0] — 2026-06-04
|
|
9
|
+
|
|
10
|
+
Multi-broker CSV import. The Schwab/Fidelity CSV importer is rebuilt as a
|
|
11
|
+
format-agnostic parser registry, **Empower** (employer 401(k) / EquatePlus)
|
|
12
|
+
joins the supported brokers, and adding the next broker is now a subclass +
|
|
13
|
+
one-line registration. No changes to the trading/analysis CLIs.
|
|
14
|
+
**1604 tests pass, ruff + mypy clean.**
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
|
|
18
|
+
- **Empower Holdings CSV import** ([#56](https://github.com/subsriram/thetabook/pull/56)).
|
|
19
|
+
`import-csv` now recognizes Empower's multi-account holdings export
|
|
20
|
+
(equities, ETFs, mutual funds, and options) alongside Schwab and Fidelity.
|
|
21
|
+
- **Extensible broker CSV parser registry** ([#56](https://github.com/subsriram/thetabook/pull/56)).
|
|
22
|
+
The monolithic `import_csv_snapshot.py` is split into a `portfolio/csv_parsers/`
|
|
23
|
+
package: a `BrokerCsvParser` ABC (`detect()` / `parse()`), one module per
|
|
24
|
+
broker, and a `REGISTRY` walked by `detect_and_parse()` (first match wins,
|
|
25
|
+
most-specific first). A new broker is a subclass + a line in `REGISTRY` — no
|
|
26
|
+
changes to the importer or CLI. Format is auto-detected per file, so one
|
|
27
|
+
`import-csv` invocation can mix exports from different brokers.
|
|
28
|
+
- **`instrument_symbol` per-account override** ([#56](https://github.com/subsriram/thetabook/pull/56)).
|
|
29
|
+
For single-stock employer plans (e.g. EquatePlus) whose Fidelity rows carry
|
|
30
|
+
no ticker, `accounts.toml` can map the account to a symbol so the shares
|
|
31
|
+
import with the right underlying. Documented in `accounts.toml.example`.
|
|
32
|
+
|
|
33
|
+
### Changed
|
|
34
|
+
|
|
35
|
+
- **Account numbers stored as the broker exposes them** ([#56](https://github.com/subsriram/thetabook/pull/56)).
|
|
36
|
+
Fidelity and Empower numbers are now stored verbatim; Schwab stays masked to
|
|
37
|
+
`****<last4>` because the export only carries the last four (a broker
|
|
38
|
+
limitation, not a masking decision). `import-csv` warns when a now-verbatim
|
|
39
|
+
number no longer matches a masked `****<last4>` key left in `accounts.toml`,
|
|
40
|
+
so per-account rules don't silently stop matching — re-key or re-run
|
|
41
|
+
`/accounts-init`.
|
|
42
|
+
- **Empower account subtype feeds `/accounts-init`** ([#56](https://github.com/subsriram/thetabook/pull/56)).
|
|
43
|
+
Empower exports tell us Roth vs. traditional, so `accounts totals` surfaces a
|
|
44
|
+
`roth-401k` / `traditional-401k` suggestion for unconfigured accounts instead
|
|
45
|
+
of a bare `?` — unlike Schwab, which can't distinguish IRA from taxable.
|
|
46
|
+
- **`import_csv_snapshot.py` reduced to a thin entry point** ([#56](https://github.com/subsriram/thetabook/pull/56)).
|
|
47
|
+
The legacy `parse_schwab_csv` / `parse_fidelity_csv` shim functions were
|
|
48
|
+
removed; callers use the `csv_parsers` package directly.
|
|
49
|
+
- **sdist excludes `personal/`, `.claude/`, `tests/`, `docs/`** ([#62](https://github.com/subsriram/thetabook/pull/62)).
|
|
50
|
+
Smaller source distribution that no longer risks shipping local PII fixtures.
|
|
51
|
+
|
|
52
|
+
### Fixed
|
|
53
|
+
|
|
54
|
+
- **`parse_money` handles the `$-114.50` ordering** ([#56](https://github.com/subsriram/thetabook/pull/56)).
|
|
55
|
+
A negative sign after the currency symbol is now parsed as negative (only the
|
|
56
|
+
`-$114.50` and `($114.50)` forms worked before).
|
|
57
|
+
- **Empower import fails cleanly on a malformed file** ([#56](https://github.com/subsriram/thetabook/pull/56)).
|
|
58
|
+
A Holdings CSV missing a required column now warns and skips the file instead
|
|
59
|
+
of raising `KeyError` mid-parse.
|
|
60
|
+
|
|
61
|
+
### Docs
|
|
62
|
+
|
|
63
|
+
- Documented Empower support, the `csv_parsers/` package, and the `import-csv`
|
|
64
|
+
command across README, `docs/cli.md`, and `docs/architecture.md`
|
|
65
|
+
([#56](https://github.com/subsriram/thetabook/pull/56)); documented the
|
|
66
|
+
v2.1.x technical-analysis stack across the reference docs
|
|
67
|
+
([#63](https://github.com/subsriram/thetabook/pull/63)).
|
|
68
|
+
|
|
8
69
|
## [2.1.2] — 2026-06-01
|
|
9
70
|
|
|
10
71
|
First-time-setup bug fixes plus a CI hardening so releases stop being hostage
|
|
@@ -22,6 +22,8 @@ The name nods to **theta**, the daily decay that quietly drives most options P&L
|
|
|
22
22
|
|
|
23
23
|
- **Use the `thetabook` CLI as much as possible** to fetch data, answer questions, and run analysis. The CLI loads `.env`, applies the source cascade (Schwab → Massive → yfinance), and uses consistent IV/rate/yield conventions. Examples: `thetabook chain ... --greeks`, `thetabook evaluate <id>`, `thetabook greeks`, `thetabook price`, `thetabook dividends -v`. Don't reach for `uv run python -c "from thetabook... import"` when a CLI command exists for the same job.
|
|
24
24
|
- **When the CLI doesn't expose what you need, drop into Python** — but always call `thetabook.paths.load_env()` first. Without it, the Schwab client returns `None` and the data cascade silently falls through to a worse source (yfinance), producing answers that disagree with the CLI's. If the gap is reusable, file an issue to surface it via a flag or new subcommand rather than letting the Python escape hatch normalize.
|
|
25
|
+
- **For technical analysis, use `thetabook hv` / `ta` / `scenarios` / `bars`.** `thetabook ta TICKER` gives RSI/MACD/Bollinger with interpretive labels; `thetabook hv TICKER` gives realized vol + HV-rank/percentile (the IV-rank substitute — there's no historical option IV); `thetabook scenarios match TICKER` answers "has this regime happened before?" with forward-return outcomes (run both `--mode trajectory` and `--mode state`; when they disagree, present both rather than averaging). These read daily *closes* from a historical-bars backbone, not the live price cascade — see [docs/cli.md](docs/cli.md) for the full flag set and [docs/behaviors.md](docs/behaviors.md) for the stitch.
|
|
26
|
+
- **Know how fresh each source is before quoting a number.** The historical bars under `hv`/`ta`/`scenarios` are a stitch: defeatbeta (weekly HuggingFace dataset) covers history up to the **most recent Friday's close**, and yfinance fills the rolling tail through today — so the latest *complete* indicator bar is usually last Friday, and intraday moves aren't reflected until the day closes. In the live price cascade, **Massive returns the previous business day's close, not an intraday quote** (Polygon `get_previous_close_agg`); only Schwab is real-time and yfinance is ~15-min delayed. When a figure comes from Massive or from the defeatbeta history, say so — don't present it as the current price.
|
|
25
27
|
|
|
26
28
|
## Repo layout
|
|
27
29
|
|
|
@@ -54,7 +56,7 @@ For the rationale behind the layers, the data-flow diagram, the source cascade,
|
|
|
54
56
|
|
|
55
57
|
## Running things
|
|
56
58
|
|
|
57
|
-
After `uv sync`, every CLI lives under a single `thetabook` umbrella. The full subcommand list grouped by area (snapshots, evaluate/adjust, ideas lifecycle, Greeks, chain, earnings/dividends, accounts, tickers, wiki, skills) lives in [docs/cli.md](docs/cli.md). The typical loop:
|
|
59
|
+
After `uv sync`, every CLI lives under a single `thetabook` umbrella. The full subcommand list grouped by area (snapshots, evaluate/adjust, ideas lifecycle, Greeks, chain, technical analysis, earnings/dividends, accounts, tickers, wiki, skills) lives in [docs/cli.md](docs/cli.md). The typical loop:
|
|
58
60
|
|
|
59
61
|
```bash
|
|
60
62
|
thetabook refresh # pull positions from Schwab → personal/snapshots/YYYY-MM-DD.json
|
|
@@ -107,7 +107,7 @@ This is a one-shot move of `.env` + `schwab_token.json` into `personal/` so the
|
|
|
107
107
|
|
|
108
108
|
### Bootstrapping from a CSV instead of the Schwab API
|
|
109
109
|
|
|
110
|
-
If you want to try thetabook before going through Schwab dev-app approval, export positions as CSV and import them.
|
|
110
|
+
If you want to try thetabook before going through Schwab dev-app approval, export positions as CSV and import them. Schwab, Fidelity, and Empower CSV formats are auto-detected:
|
|
111
111
|
|
|
112
112
|
```bash
|
|
113
113
|
# Schwab: Positions tab → Export
|
|
@@ -116,8 +116,11 @@ thetabook import-csv path/to/Individual-Positions-*.csv path/to/Joint-Positions-
|
|
|
116
116
|
# Fidelity: Positions → Download
|
|
117
117
|
thetabook import-csv path/to/Portfolio_Positions.csv
|
|
118
118
|
|
|
119
|
+
# Empower: Holdings → Export
|
|
120
|
+
thetabook import-csv path/to/holdings.csv
|
|
121
|
+
|
|
119
122
|
# Mixed: multiple brokers in one snapshot
|
|
120
|
-
thetabook import-csv schwab.csv fidelity.csv
|
|
123
|
+
thetabook import-csv schwab.csv fidelity.csv empower.csv
|
|
121
124
|
```
|
|
122
125
|
|
|
123
126
|
This produces the same snapshot format as the API path, so everything downstream works identically. Both option symbols and cash balances are handled.
|
|
@@ -183,7 +186,7 @@ Every workflow runs through the unified `thetabook` console script (installed by
|
|
|
183
186
|
thetabook refresh # fetch & snapshot from Schwab API
|
|
184
187
|
thetabook snapshot # path | fetched_at | age | fresh|stale | counts
|
|
185
188
|
thetabook snapshot --path # absolute path only (for shell substitution)
|
|
186
|
-
thetabook import-csv <csv> [<csv> ...] # import Schwab or
|
|
189
|
+
thetabook import-csv <csv> [<csv> ...] # import Schwab, Fidelity, or Empower CSV exports
|
|
187
190
|
thetabook migrate # one-time: move pre-v1 dirs under personal/
|
|
188
191
|
|
|
189
192
|
# Snapshot diff
|
|
@@ -248,6 +251,16 @@ thetabook dividends AAPL # yield + next ex-div for one
|
|
|
248
251
|
thetabook dividends AAPL T VZ # multiple; exit 1 if none paying
|
|
249
252
|
thetabook dividends AAPL --no-cache # force a fresh yfinance fetch
|
|
250
253
|
|
|
254
|
+
# Technical analysis on historical bars (defeatbeta deep history + yfinance tail)
|
|
255
|
+
thetabook hv AAPL # realized vol + HV-rank/percentile (IV-rank substitute)
|
|
256
|
+
thetabook ta AAPL # RSI / MACD / Bollinger with interpretive labels
|
|
257
|
+
thetabook ta AAPL --indicator rsi --series # one indicator, full rolling series
|
|
258
|
+
thetabook scenarios features AAPL # today's 4-feature regime vector + reading
|
|
259
|
+
thetabook scenarios match AAPL # trajectory analogues + forward returns (5/20/60/120d)
|
|
260
|
+
thetabook scenarios match AAPL --mode state # match current regime instead of recent-move shape
|
|
261
|
+
thetabook bars boundary AAPL # defeatbeta's last date (the stitch seam — usually last Fri)
|
|
262
|
+
thetabook bars actions AAPL --type split # corporate actions (splits / dividends)
|
|
263
|
+
|
|
251
264
|
# Per-account rules + tax notes (reads personal/accounts.toml)
|
|
252
265
|
thetabook accounts show # posture line per account (nickname + last4)
|
|
253
266
|
thetabook accounts totals # NLV / cash table per account, sorted by liquidation desc
|
|
@@ -378,11 +391,23 @@ thetabook/
|
|
|
378
391
|
│ │ ├── vol_lookup.py # per-leg IV, ATM IV, leg marks (shared cache)
|
|
379
392
|
│ │ ├── leg_marks.py # fetch_leg_mark + pick_mark (conservative/mid)
|
|
380
393
|
│ │ ├── earnings.py # upcoming-earnings lookup (7-day on-disk cache)
|
|
381
|
-
│ │
|
|
394
|
+
│ │ ├── dividends.py # yield + next ex-div lookup (7-day on-disk cache)
|
|
395
|
+
│ │ └── bars.py # historical daily OHLCV (defeatbeta deep history + yfinance tail, stitched)
|
|
396
|
+
│ │
|
|
397
|
+
│ ├── analysis/ # derived signals computed on historical bars
|
|
398
|
+
│ │ ├── hv.py # realized vol + HV-rank/percentile (the IV-rank substitute)
|
|
399
|
+
│ │ ├── ta.py # RSI / MACD / Bollinger Bands (pure functions on a close series)
|
|
400
|
+
│ │ └── scenarios.py # historical-analogue lookup (trajectory + state) with forward returns
|
|
382
401
|
│ │
|
|
383
402
|
│ ├── portfolio/ # snapshot I/O + per-account rules
|
|
384
403
|
│ │ ├── get_positions.py # Schwab API → snapshot (OAuth via schwab-py)
|
|
385
|
-
│ │ ├── import_csv_snapshot.py #
|
|
404
|
+
│ │ ├── import_csv_snapshot.py # broker CSV → snapshot (entry point; delegates to csv_parsers/)
|
|
405
|
+
│ │ ├── csv_parsers/ # per-broker CSV format handlers (extensible via BrokerCsvParser)
|
|
406
|
+
│ │ │ ├── __init__.py # REGISTRY + detect_and_parse() dispatch
|
|
407
|
+
│ │ │ ├── _base.py # BrokerCsvParser ABC + shared helpers
|
|
408
|
+
│ │ │ ├── schwab.py # Schwab positions export
|
|
409
|
+
│ │ │ ├── fidelity.py # Fidelity FullView export
|
|
410
|
+
│ │ │ └── empower.py # Empower Holdings export
|
|
386
411
|
│ │ ├── diff_snapshots.py # compare two snapshots
|
|
387
412
|
│ │ ├── accounts.py # per-account risk rules + tax notes
|
|
388
413
|
│ │ └── migrate_to_personal.py # one-time migration from pre-v1 layout
|
|
@@ -445,7 +470,13 @@ thetabook/
|
|
|
445
470
|
│ │ ├── test_vol_lookup.py
|
|
446
471
|
│ │ ├── test_leg_marks.py
|
|
447
472
|
│ │ ├── test_earnings.py
|
|
448
|
-
│ │
|
|
473
|
+
│ │ ├── test_dividends.py
|
|
474
|
+
│ │ └── test_bars.py
|
|
475
|
+
│ │
|
|
476
|
+
│ ├── analysis/
|
|
477
|
+
│ │ ├── test_hv.py
|
|
478
|
+
│ │ ├── test_ta.py
|
|
479
|
+
│ │ └── test_scenarios.py
|
|
449
480
|
│ │
|
|
450
481
|
│ ├── portfolio/
|
|
451
482
|
│ │ ├── test_get_positions.py
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "thetabook"
|
|
3
|
-
version = "2.
|
|
3
|
+
version = "2.2.0"
|
|
4
4
|
description = "A journal for options traders who think in Greeks — Schwab portfolio review and strategy log with an AI copilot."
|
|
5
5
|
requires-python = ">=3.12"
|
|
6
6
|
dependencies = [
|
|
@@ -27,6 +27,9 @@ build-backend = "hatchling.build"
|
|
|
27
27
|
[tool.hatch.build.targets.wheel]
|
|
28
28
|
packages = ["src/thetabook"]
|
|
29
29
|
|
|
30
|
+
[tool.hatch.build.targets.sdist]
|
|
31
|
+
exclude = ["personal/", ".claude/", "tests/", "docs/"]
|
|
32
|
+
|
|
30
33
|
[dependency-groups]
|
|
31
34
|
dev = [
|
|
32
35
|
"mypy>=1.13.0",
|
|
@@ -21,7 +21,7 @@ Tools (each maps to a thin typer wrapper that delegates to the underlying
|
|
|
21
21
|
earnings — next earnings date(s) via yfinance cache
|
|
22
22
|
dividends — yield + next ex-div date(s) via yfinance cache
|
|
23
23
|
leg-mark — current bid/ask/mid/last for a leg
|
|
24
|
-
import-csv — convert Schwab/Fidelity CSV exports to snapshot JSON
|
|
24
|
+
import-csv — convert Schwab/Fidelity/Empower CSV exports to snapshot JSON
|
|
25
25
|
init — install setup skill; --non-interactive does the install
|
|
26
26
|
migrate-home — one-time move of repo-root .env + token under personal/
|
|
27
27
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""thetabook import-csv — convert Schwab/Fidelity CSV exports to snapshot JSON."""
|
|
1
|
+
"""thetabook import-csv — convert Schwab/Fidelity/Empower CSV exports to snapshot JSON."""
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
@@ -9,13 +9,15 @@ import typer
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
def import_csv(
|
|
12
|
-
csvs: Annotated[
|
|
12
|
+
csvs: Annotated[
|
|
13
|
+
list[Path], typer.Argument(help="Schwab, Fidelity, or Empower position CSV file(s).")
|
|
14
|
+
],
|
|
13
15
|
date: Annotated[
|
|
14
16
|
str | None,
|
|
15
17
|
typer.Option("--date", help="Override snapshot date (YYYY-MM-DD); defaults to date in CSV."),
|
|
16
18
|
] = None,
|
|
17
19
|
) -> None:
|
|
18
|
-
"""Parse Schwab/Fidelity CSVs and write a snapshot JSON file."""
|
|
20
|
+
"""Parse Schwab/Fidelity/Empower CSVs and write a snapshot JSON file."""
|
|
19
21
|
from thetabook.portfolio.import_csv_snapshot import run
|
|
20
22
|
|
|
21
23
|
run(csvs, date_override=date)
|
|
@@ -96,6 +96,7 @@ class AccountConfig:
|
|
|
96
96
|
goal: str = ""
|
|
97
97
|
risk_profile: str = ""
|
|
98
98
|
rules: dict[str, Any] = field(default_factory=dict)
|
|
99
|
+
instrument_symbol: str = "" # override for accounts whose CSV rows have no symbol (e.g. EquatePlus)
|
|
99
100
|
|
|
100
101
|
@property
|
|
101
102
|
def is_ira(self) -> bool:
|
|
@@ -159,6 +160,7 @@ def load_accounts(path: Path | None = None) -> dict[str, AccountConfig]:
|
|
|
159
160
|
goal=cfg.get("goal", ""),
|
|
160
161
|
risk_profile=cfg.get("risk_profile", ""),
|
|
161
162
|
rules=dict(cfg.get("rules") or {}),
|
|
163
|
+
instrument_symbol=cfg.get("instrument_symbol", ""),
|
|
162
164
|
)
|
|
163
165
|
return out
|
|
164
166
|
|
|
@@ -831,7 +833,12 @@ def render_totals_table(snapshot: Snapshot, accounts: dict[str, AccountConfig])
|
|
|
831
833
|
last4 = number[-4:] if len(number) >= 4 else number
|
|
832
834
|
cfg = accounts.get(number)
|
|
833
835
|
nickname = (cfg.nickname if cfg and cfg.nickname else f"…{last4}")
|
|
834
|
-
|
|
836
|
+
# For unconfigured accounts, fall back to a parser-detected subtype
|
|
837
|
+
# (e.g. Empower 401(k) exports set `_account_subtype`) so the suggested
|
|
838
|
+
# type surfaces in `accounts totals` for /accounts-init to pre-fill,
|
|
839
|
+
# instead of a bare "?". Configured accounts always win.
|
|
840
|
+
detected = str(getattr(acct_snap, "_account_subtype", "") or "")
|
|
841
|
+
acct_type = cfg.type if cfg else (detected or "?")
|
|
835
842
|
nlv = float(acct_snap.currentBalances.liquidationValue or 0)
|
|
836
843
|
cash = float(acct_snap.currentBalances.cashBalance or 0)
|
|
837
844
|
rows.append((nickname, acct_type, last4, nlv, cash))
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""Broker CSV parser registry.
|
|
2
|
+
|
|
3
|
+
To add a new broker format:
|
|
4
|
+
1. Create ``csv_parsers/<broker>.py`` subclassing ``BrokerCsvParser``.
|
|
5
|
+
2. Implement ``detect(path, first_rows)`` and ``parse(path)``.
|
|
6
|
+
3. Append the new class to ``REGISTRY`` below — detection runs in order,
|
|
7
|
+
first match wins, so put more-specific formats before more-generic ones.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
from typing import TYPE_CHECKING, Any
|
|
13
|
+
|
|
14
|
+
if TYPE_CHECKING:
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
|
|
17
|
+
from ._base import BrokerCsvParser, read_first_rows
|
|
18
|
+
from .empower import EmpowerCsvParser
|
|
19
|
+
from .fidelity import FidelityCsvParser
|
|
20
|
+
from .schwab import SchwabCsvParser
|
|
21
|
+
|
|
22
|
+
REGISTRY: list[type[BrokerCsvParser]] = [
|
|
23
|
+
SchwabCsvParser, # most specific — unique header sentinel
|
|
24
|
+
EmpowerCsvParser, # "Holdings" first-cell sentinel
|
|
25
|
+
FidelityCsvParser, # "Account Number" first-cell (checked last; most generic)
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def detect_and_parse(
|
|
30
|
+
path: Path, account_cfg: dict[str, Any] | None = None
|
|
31
|
+
) -> list[dict[str, Any]]:
|
|
32
|
+
"""Auto-detect the broker format of *path* and parse it.
|
|
33
|
+
|
|
34
|
+
Returns a list of account blobs on success, or an empty list if no
|
|
35
|
+
registered parser recognises the file.
|
|
36
|
+
|
|
37
|
+
*account_cfg* maps account number → ``AccountConfig`` (or any object with
|
|
38
|
+
an ``instrument_symbol`` attribute); passed through to parsers that need
|
|
39
|
+
per-account overrides.
|
|
40
|
+
"""
|
|
41
|
+
first_rows = read_first_rows(path)
|
|
42
|
+
for parser_cls in REGISTRY:
|
|
43
|
+
if parser_cls.detect(path, first_rows):
|
|
44
|
+
return parser_cls.parse(path, account_cfg=account_cfg)
|
|
45
|
+
return []
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
__all__ = [
|
|
49
|
+
"REGISTRY",
|
|
50
|
+
"BrokerCsvParser",
|
|
51
|
+
"EmpowerCsvParser",
|
|
52
|
+
"FidelityCsvParser",
|
|
53
|
+
"SchwabCsvParser",
|
|
54
|
+
"detect_and_parse",
|
|
55
|
+
]
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"""Shared base class and utilities for broker CSV parsers."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import csv
|
|
6
|
+
from abc import ABC, abstractmethod
|
|
7
|
+
from typing import TYPE_CHECKING, Any
|
|
8
|
+
|
|
9
|
+
if TYPE_CHECKING:
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
from thetabook import log
|
|
13
|
+
from thetabook.tickers import canonicalize
|
|
14
|
+
|
|
15
|
+
# Rows read once for format detection — shared by all parsers.
|
|
16
|
+
DETECT_ROWS = 5
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def read_first_rows(path: Path, n: int = DETECT_ROWS) -> list[list[str]]:
|
|
20
|
+
"""Return the first *n* CSV rows from *path*.
|
|
21
|
+
|
|
22
|
+
Always opens with ``utf-8-sig`` so BOM-prefixed files (Fidelity, Empower)
|
|
23
|
+
and plain UTF-8 files (Schwab) are both handled transparently. Returns an
|
|
24
|
+
empty list on any I/O error so callers can treat it as "unrecognised".
|
|
25
|
+
"""
|
|
26
|
+
rows: list[list[str]] = []
|
|
27
|
+
try:
|
|
28
|
+
with path.open(newline="", encoding="utf-8-sig") as fh:
|
|
29
|
+
reader = csv.reader(fh)
|
|
30
|
+
for _ in range(n):
|
|
31
|
+
try:
|
|
32
|
+
rows.append(next(reader))
|
|
33
|
+
except StopIteration:
|
|
34
|
+
break
|
|
35
|
+
except OSError:
|
|
36
|
+
pass
|
|
37
|
+
return rows
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def parse_money(s: str | None) -> float:
|
|
41
|
+
"""Parse ``'$1,234.56'``, ``'-$114.50'``, ``'$-114.50'``, ``'($208.00)'``,
|
|
42
|
+
``'--'``, ``''`` → float.
|
|
43
|
+
|
|
44
|
+
Negativity is detected from parentheses or a leading ``-`` *after* the
|
|
45
|
+
currency symbol is stripped, so both ``-$x`` and ``$-x`` orderings work.
|
|
46
|
+
"""
|
|
47
|
+
if s is None:
|
|
48
|
+
return 0.0
|
|
49
|
+
s = str(s).strip()
|
|
50
|
+
if not s or s == "--":
|
|
51
|
+
return 0.0
|
|
52
|
+
negative = s.startswith("(") and s.endswith(")")
|
|
53
|
+
s = s.replace("$", "").replace(",", "").replace("(", "").replace(")", "").strip()
|
|
54
|
+
negative = negative or s.startswith("-")
|
|
55
|
+
s = s.replace("-", "")
|
|
56
|
+
try:
|
|
57
|
+
val = float(s)
|
|
58
|
+
except ValueError:
|
|
59
|
+
return 0.0
|
|
60
|
+
return -val if negative else val
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def parse_qty(s: str) -> float:
|
|
64
|
+
if not s or str(s).strip() == "--":
|
|
65
|
+
return 0.0
|
|
66
|
+
return float(str(s).replace(",", ""))
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def to_occ_symbol(root: str, year: int, month: int, day: int, cp: str, strike: float) -> str:
|
|
70
|
+
"""Build an OCC-format option symbol from components."""
|
|
71
|
+
root_padded = f"{root:<6}"
|
|
72
|
+
yymmdd = f"{year % 100:02d}{month:02d}{day:02d}"
|
|
73
|
+
strike_int = round(strike * 1000)
|
|
74
|
+
cp_char = cp[0].upper()
|
|
75
|
+
return f"{root_padded}{yymmdd}{cp_char}{strike_int:08d}"
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def canonicalize_with_log(symbol: str, seen: set[str]) -> str:
|
|
79
|
+
"""Canonicalize *symbol*; emit a one-time stderr note per unique rewrite."""
|
|
80
|
+
canon = canonicalize(symbol)
|
|
81
|
+
if canon != symbol and symbol not in seen:
|
|
82
|
+
seen.add(symbol)
|
|
83
|
+
log.info(f"Note: rewrote {symbol} → {canon} (Schwab-canonical)")
|
|
84
|
+
return canon
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class BrokerCsvParser(ABC):
|
|
88
|
+
"""Contract every broker CSV parser must satisfy.
|
|
89
|
+
|
|
90
|
+
See ``csv_parsers/__init__.py`` for the step-by-step guide to adding and
|
|
91
|
+
registering a new broker format.
|
|
92
|
+
"""
|
|
93
|
+
|
|
94
|
+
@classmethod
|
|
95
|
+
@abstractmethod
|
|
96
|
+
def detect(cls, path: Path, first_rows: list[list[str]]) -> bool:
|
|
97
|
+
"""Return ``True`` if *path* is in this parser's format.
|
|
98
|
+
|
|
99
|
+
*first_rows* is pre-read (first ``DETECT_ROWS`` rows, already parsed as
|
|
100
|
+
CSV). Implementations must **not** open *path* again during detection.
|
|
101
|
+
"""
|
|
102
|
+
|
|
103
|
+
@classmethod
|
|
104
|
+
@abstractmethod
|
|
105
|
+
def parse(
|
|
106
|
+
cls, path: Path, account_cfg: dict[str, Any] | None = None
|
|
107
|
+
) -> list[dict[str, Any]]:
|
|
108
|
+
"""Parse *path* and return a list of account blobs.
|
|
109
|
+
|
|
110
|
+
Each blob must have keys:
|
|
111
|
+
``accountNumber``, ``type``, ``currentBalances``
|
|
112
|
+
(``cashBalance`` + ``liquidationValue``), ``positions``,
|
|
113
|
+
``_source_csv``, ``_snapshot_date``.
|
|
114
|
+
|
|
115
|
+
*account_cfg* maps account number → ``AccountConfig``-like object with
|
|
116
|
+
at least an ``instrument_symbol`` attribute; used by parsers that need
|
|
117
|
+
per-account overrides (e.g. EquatePlus positions that carry no symbol).
|
|
118
|
+
"""
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"""Empower Holdings CSV parser.
|
|
2
|
+
|
|
3
|
+
Detects and parses Empower's multi-account holdings export
|
|
4
|
+
(first cell of row 0 is ``"Holdings"``).
|
|
5
|
+
|
|
6
|
+
Account numbers are stored verbatim from the file (e.g. ``XDR000001``).
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import contextlib
|
|
12
|
+
import csv
|
|
13
|
+
import re
|
|
14
|
+
from collections import defaultdict
|
|
15
|
+
from datetime import datetime
|
|
16
|
+
from typing import TYPE_CHECKING, Any
|
|
17
|
+
|
|
18
|
+
if TYPE_CHECKING:
|
|
19
|
+
from pathlib import Path
|
|
20
|
+
|
|
21
|
+
from thetabook import log
|
|
22
|
+
|
|
23
|
+
from ._base import BrokerCsvParser, parse_money, parse_qty, to_occ_symbol
|
|
24
|
+
|
|
25
|
+
# 'GOOGL 05222026 P 382.5' (ROOT MMDDYYYY C/P STRIKE)
|
|
26
|
+
_EMPOWER_OPT_SYMBOL_RE = re.compile(
|
|
27
|
+
r"^(?P<root>[A-Z./]+)\s+(?P<mmddyyyy>\d{8})\s+(?P<cp>[CP])\s+(?P<strike>[\d.]+)$"
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
# 'Holdings as of : 05/25/2026'
|
|
31
|
+
_EMPOWER_DATE_RE = re.compile(
|
|
32
|
+
r"Holdings as of\s*:\s*(?P<date>\d{2}/\d{2}/\d{4})"
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
# Sub-Asset Classification → snapshot assetType.
|
|
36
|
+
# Add new strings here when Empower introduces new sub-asset categories.
|
|
37
|
+
_EMPOWER_ASSET_MAP: dict[str, str] = {
|
|
38
|
+
"Common Stocks": "EQUITY",
|
|
39
|
+
"American Depository Receipt / Global Depository Receipt (Common)": "EQUITY",
|
|
40
|
+
"Real Estate Investment Trusts": "EQUITY",
|
|
41
|
+
"Exchange-Traded Funds": "ETF",
|
|
42
|
+
"Mutual Funds": "MUTUAL_FUND",
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
# Columns the parser dereferences by name; bail cleanly if any are absent
|
|
46
|
+
# (rather than raising KeyError mid-parse — callers treat [] as "unrecognised").
|
|
47
|
+
_EMPOWER_REQUIRED_COLS: tuple[str, ...] = (
|
|
48
|
+
"Security ID",
|
|
49
|
+
"Account Number",
|
|
50
|
+
"Account Nickname/Title",
|
|
51
|
+
"Description",
|
|
52
|
+
"Asset Classification",
|
|
53
|
+
"Quantity",
|
|
54
|
+
"Price",
|
|
55
|
+
"Market Value",
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class EmpowerCsvParser(BrokerCsvParser):
|
|
60
|
+
@classmethod
|
|
61
|
+
def detect(cls, path: Path, first_rows: list[list[str]]) -> bool:
|
|
62
|
+
if not first_rows or not first_rows[0]:
|
|
63
|
+
return False
|
|
64
|
+
return first_rows[0][0].strip() == "Holdings"
|
|
65
|
+
|
|
66
|
+
@classmethod
|
|
67
|
+
def parse(cls, path: Path, account_cfg: dict[str, Any] | None = None) -> list[dict[str, Any]]:
|
|
68
|
+
with path.open(newline="", encoding="utf-8-sig") as fh:
|
|
69
|
+
raw_rows = list(csv.reader(fh))
|
|
70
|
+
|
|
71
|
+
if not raw_rows or raw_rows[0][0].strip() != "Holdings":
|
|
72
|
+
return []
|
|
73
|
+
|
|
74
|
+
# Find the column header row (starts with "Security ID")
|
|
75
|
+
col_header_idx = next(
|
|
76
|
+
(i for i, row in enumerate(raw_rows) if row and row[0].strip() == "Security ID"),
|
|
77
|
+
None,
|
|
78
|
+
)
|
|
79
|
+
if col_header_idx is None:
|
|
80
|
+
return []
|
|
81
|
+
|
|
82
|
+
headers = raw_rows[col_header_idx]
|
|
83
|
+
col = {name: idx for idx, name in enumerate(headers)}
|
|
84
|
+
|
|
85
|
+
missing = [c for c in _EMPOWER_REQUIRED_COLS if c not in col]
|
|
86
|
+
if missing:
|
|
87
|
+
log.warn(f"Empower: missing expected column(s) {missing}; skipping file.")
|
|
88
|
+
return []
|
|
89
|
+
|
|
90
|
+
# Extract snapshot date from any cell matching the date pattern
|
|
91
|
+
snap_date = None
|
|
92
|
+
for row in raw_rows[:col_header_idx]:
|
|
93
|
+
for cell in row:
|
|
94
|
+
m = _EMPOWER_DATE_RE.search(cell)
|
|
95
|
+
if m:
|
|
96
|
+
with contextlib.suppress(ValueError):
|
|
97
|
+
snap_date = datetime.strptime(m["date"], "%m/%d/%Y").date().isoformat()
|
|
98
|
+
|
|
99
|
+
sub_asset_idx = col.get("Sub-Asset Classification")
|
|
100
|
+
gain_loss_idx = col.get("Gain/Loss $")
|
|
101
|
+
|
|
102
|
+
acct_data: dict[tuple[str, str], dict[str, Any]] = defaultdict(
|
|
103
|
+
lambda: {"positions": [], "cash": 0.0}
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
for row in raw_rows[col_header_idx + 1 :]:
|
|
107
|
+
if not row or not row[0].strip():
|
|
108
|
+
continue
|
|
109
|
+
if len(row) < len(headers):
|
|
110
|
+
continue
|
|
111
|
+
|
|
112
|
+
security_id = row[col["Security ID"]].strip()
|
|
113
|
+
acct_id = row[col["Account Number"]].strip()
|
|
114
|
+
acct_name = row[col["Account Nickname/Title"]].strip()
|
|
115
|
+
description = row[col["Description"]].strip()
|
|
116
|
+
asset_class = row[col["Asset Classification"]].strip()
|
|
117
|
+
sub_asset = row[sub_asset_idx].strip() if sub_asset_idx is not None else ""
|
|
118
|
+
|
|
119
|
+
qty = parse_qty(row[col["Quantity"]])
|
|
120
|
+
price = parse_money(row[col["Price"]])
|
|
121
|
+
mkt_val = parse_money(row[col["Market Value"]])
|
|
122
|
+
gain_loss = parse_money(row[gain_loss_idx]) if gain_loss_idx is not None else 0.0
|
|
123
|
+
|
|
124
|
+
if asset_class == "Cash, Money Funds and Bank Deposits":
|
|
125
|
+
acct_data[(acct_id, acct_name)]["cash"] += mkt_val
|
|
126
|
+
continue
|
|
127
|
+
|
|
128
|
+
if qty == 0 and mkt_val == 0:
|
|
129
|
+
continue
|
|
130
|
+
|
|
131
|
+
instrument: dict[str, Any] = {"symbol": security_id, "description": description}
|
|
132
|
+
|
|
133
|
+
if asset_class == "Derivatives":
|
|
134
|
+
opt = _EMPOWER_OPT_SYMBOL_RE.match(security_id)
|
|
135
|
+
if opt:
|
|
136
|
+
root = opt["root"]
|
|
137
|
+
mmddyyyy = opt["mmddyyyy"]
|
|
138
|
+
mm, dd, yyyy = int(mmddyyyy[:2]), int(mmddyyyy[2:4]), int(mmddyyyy[4:])
|
|
139
|
+
strike = float(opt["strike"])
|
|
140
|
+
cp = opt["cp"]
|
|
141
|
+
instrument.update(
|
|
142
|
+
{
|
|
143
|
+
"assetType": "OPTION",
|
|
144
|
+
"symbol": to_occ_symbol(root, yyyy, mm, dd, cp, strike),
|
|
145
|
+
"underlyingSymbol": root,
|
|
146
|
+
"putCall": "CALL" if cp == "C" else "PUT",
|
|
147
|
+
"optionExpirationDate": f"{yyyy:04d}-{mm:02d}-{dd:02d}",
|
|
148
|
+
"strikePrice": strike,
|
|
149
|
+
}
|
|
150
|
+
)
|
|
151
|
+
else:
|
|
152
|
+
instrument["assetType"] = "OPTION"
|
|
153
|
+
else:
|
|
154
|
+
if sub_asset in _EMPOWER_ASSET_MAP:
|
|
155
|
+
instrument["assetType"] = _EMPOWER_ASSET_MAP[sub_asset]
|
|
156
|
+
elif "ETF" in sub_asset.upper():
|
|
157
|
+
instrument["assetType"] = "ETF"
|
|
158
|
+
else:
|
|
159
|
+
if sub_asset:
|
|
160
|
+
log.warn(
|
|
161
|
+
f"Empower: unknown sub-asset '{sub_asset}' for {security_id}; "
|
|
162
|
+
"classifying as EQUITY. Add to _EMPOWER_ASSET_MAP if incorrect."
|
|
163
|
+
)
|
|
164
|
+
instrument["assetType"] = "EQUITY"
|
|
165
|
+
|
|
166
|
+
cost_basis = mkt_val - gain_loss
|
|
167
|
+
avg_price = cost_basis / qty if qty else price
|
|
168
|
+
|
|
169
|
+
acct_data[(acct_id, acct_name)]["positions"].append(
|
|
170
|
+
{
|
|
171
|
+
"instrument": instrument,
|
|
172
|
+
"longQuantity": max(qty, 0),
|
|
173
|
+
"shortQuantity": max(-qty, 0),
|
|
174
|
+
"marketValue": mkt_val,
|
|
175
|
+
"averagePrice": avg_price,
|
|
176
|
+
"costBasis": cost_basis,
|
|
177
|
+
"marketPrice": price,
|
|
178
|
+
}
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
accounts = []
|
|
182
|
+
for (acct_id, acct_name), data in acct_data.items():
|
|
183
|
+
total_mkt = sum(p["marketValue"] for p in data["positions"]) + data["cash"]
|
|
184
|
+
# Empower exports here come from employer 401(k)/EquatePlus plans, so
|
|
185
|
+
# the subtype is inferred from the nickname (Roth vs. traditional).
|
|
186
|
+
# Surfaced as the suggested type for unconfigured accounts in
|
|
187
|
+
# `thetabook accounts totals` (see accounts.render_totals_table),
|
|
188
|
+
# which /accounts-init reads to pre-fill accounts.toml — unlike
|
|
189
|
+
# Schwab, the broker tells us the tax treatment here.
|
|
190
|
+
# Revisit if Empower starts exporting taxable or IRA accounts.
|
|
191
|
+
is_roth = "roth" in acct_name.lower()
|
|
192
|
+
account_subtype = "roth-401k" if is_roth else "traditional-401k"
|
|
193
|
+
accounts.append(
|
|
194
|
+
{
|
|
195
|
+
"accountNumber": acct_id,
|
|
196
|
+
"type": acct_name,
|
|
197
|
+
"_account_subtype": account_subtype,
|
|
198
|
+
"currentBalances": {
|
|
199
|
+
"cashBalance": data["cash"],
|
|
200
|
+
"liquidationValue": total_mkt,
|
|
201
|
+
},
|
|
202
|
+
"positions": data["positions"],
|
|
203
|
+
"_source_csv": path.name,
|
|
204
|
+
"_snapshot_date": snap_date,
|
|
205
|
+
}
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
return accounts
|