Let’s run the full pipeline on a small sample cashflow file and inspect the results.
We assume the CSV / Excel file has at least these columns:
date
cashflow
valuation
# If you have a sample file in tests/fixtures, you can point to it directly:sample_path ="../tests/fixtures/sample_cashflows.csv"load_result = load_cashflows(sample_path)load_result.df.head()
/home/cs/workspaces/portfolio-performance-metrics/portfolio_performance_metrics/core.py:83: RuntimeWarning: IRR may be non-unique because there are multiple sign changes in cashflows.
warnings.warn("IRR may be non-unique because there are multiple sign changes in cashflows.", RuntimeWarning)
metric
period_return
annualized
0
TWR
0.221754
0.222427
1
MWR_XIRR
0.227029
0.227718
2
Modified_Dietz
0.226616
0.227304
nav.head()
date
valuation
shares
nav_per_share
flow
0
2025-01-01
100000.0
1.000000
100000.000000
0.0
1
2025-03-01
112000.0
1.098039
102000.000000
-10000.0
2
2025-06-01
118000.0
1.053403
112017.857143
5000.0
3
2025-09-01
125000.0
1.125431
111068.553269
-8000.0
4
2025-12-31
137500.0
1.125431
122175.408596
0.0
The summary table shows:
the period return for each metric,
the annualized return where applicable.
The nav table shows the unitization series:
date: valuation date,
valuation: post-flow portfolio value,
shares: notional share count,
nav_per_share: unit price (NAV per share),
flow: investor-view external flow on that date.
plt.plot(nav["date"], nav["nav_per_share"])plt.xlabel("Date")plt.ylabel("NAV per share")plt.title("Unitization series")plt.xticks(rotation=45);
CLI usage
The same functionality is available via a command-line interface.
From the project root:
uv run portfolio-performance-metrics tests/fixtures/sample_cashflows.csv
This will:
print a performance summary (TWR, MWR/XIRR, Modified Dietz),
print the unitization series (NAV per share over time).
To also write an Excel file:
uv run portfolio-performance-metrics tests/fixtures/sample_cashflows.csv --output output.xlsx
You can then open output.xlsx to inspect the results in a spreadsheet.
Detailed notebooks
The rest of the notebooks document the implementation in a more fine-grained, literate style:
00_core.ipynb: core domain types and math (year_fraction, Dietz, XIRR, TWR, unitization).
01_io.ipynb: input loading and cleaning logic (load_cashflows).
02_metrics.ipynb: orchestration, lenient imputation, and compute_metrics.
03_cli.ipynb: command-line interface and argument parsing.