Converts Fidelity “Positions” CSV exports into LLM-ready markdown for portfolio analysis.
The intended workflow: export your account positions from Fidelity → run the script → provide the markdown output to Claude, ChatGPT, or another LLM for analysis (allocation review, tax lot examination, drift detection, etc.). The script preserves all values as strings — no numeric coercion — so the LLM sees exactly what Fidelity shows.
fidelity_csv_to_markdown.pyConverts Fidelity “Positions” CSV exports into markdown format. Supports single-file and batch (directory) mode. Each output file is named {account_name}__{account_number}.md.
Note that exporting the “All Accounts” positions CSV will not work. Ensure there is only one Fidelity account per export file.
./setup_env.sh
Creates a .venv virtual environment and installs dependencies from requirements.txt.
To activate in subsequent sessions:
source activate_env.sh
usage: fidelity_csv_to_markdown.py (--csv FILE | --csvdir DIR) --contract FILE [--outdir DIR] [--dry-run] [--verbose] [--quiet]
Single file:
python fidelity_csv_to_markdown.py \
--csv path/to/positions.csv \
--contract fidelity_csv_to_markdown.yaml
Batch (all CSVs in a directory):
python fidelity_csv_to_markdown.py \
--csvdir path/to/exports/ \
--contract fidelity_csv_to_markdown.yaml
Arguments:
| Argument | Required | Description |
|---|---|---|
--csv |
Yes (or --csvdir) |
Single Fidelity positions CSV |
--csvdir |
Yes (or --csv) |
Directory of CSVs to process |
--contract |
Yes | Path to the YAML contract file |
--outdir |
No | Output directory (default: alongside each input file) |
--dry-run |
No | Validate without writing output |
--verbose |
No | Detailed block output per file instead of one-line summary |
--quiet |
No | Suppress all output except errors |
The script is contract-driven — it works with whatever columns are present — but the column set below is optimized for LLM portfolio analysis. Configure My View in the Fidelity positions page before exporting to include these columns. An LLM given this data can reason about allocation, cost basis, embedded gains, income, fund costs, and sector exposure in a single pass.
Account & position identity
Sizing & cost
Performance
Pricing
Income & distributions
Fund metadata
Equity classification
Fidelity appends a duplicate summary block at the end of each row repeating cost basis, gain/loss, last price, and change (
Change $appears twice). These duplicate columns are preserved as-is alongside the primary columns.
Each script is paired with a YAML contract file that externalizes cleanup rules, footer/disclaimer detection markers, output policy, and validation constraints. Contracts are not shared between scripts.
| Contract | Used by |
|---|---|
fidelity_csv_to_markdown.yaml |
fidelity_csv_to_markdown.py |
To adapt the pipeline to a different CSV layout or add cleanup rules, update the contract — the script logic should not need to change.
Fidelity exports contain account numbers and position details. Do not commit CSV exports or generated markdown to version control. Both *.csv and *.md output files are gitignored by default (README.md and CLAUDE.md are excluded from that rule).