Return measurement
Time-weighted, money-weighted and Modified Dietz returns of a portfolio with external cash flows, optionally annualized.
- Model id
performance.return_measurement, version 2- Domain
- Performance
- Evidence
- standard
- Cost class
- instant: A closed-form calculation; a hosted run may take up to 2 seconds.
Formula
Where
- The return of sub-period k
sub_period_returns - The value at the end of sub-period k
values - The external flow at the end of sub-period k; a contribution is positive
flows - Time-weighted return
time_weighted_return - The value at the beginning
beginning_value - The value at the end
ending_value - The money-weighted return per period
money_weighted_return - The length of the whole period
- The time of flow k
flow_times - The modified Dietz return
modified_dietz_return - The value at the end, in the modified Dietz return
ending_value - The i-th external flow
flows - The weight of flow i: the share of the period it was invested
- Calendar days in the period
- Days from the start of the period to flow i
- The return for a year
annualized_return - The return over the whole span
- Periods in a year
periods_per_year - In the annualized return, the periods the return spans; elsewhere, the index of a sub-period
periods
Each symbol's field is named beside it; the inputs and outputs, with their units and bounds, are under Variables, and the citations give each formula's source.
Variables
Rates, returns and yields are decimals: 0.05 is five percent. Bounds in brackets include their end; in parentheses they exclude it.
Inputs
Time-weighted return, linked geometrically (time_weighted): 5 inputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Calculationcalculationtext | text | Time-weighted return, linked geometrically | |
Valuesvaluesmoney (array) · length min 2, max 10081; each [0, 1e+12] | money (array) | length min 2, max 10081; each [0, 1e+12] | Portfolio values V0, V1, ..., Vn, each taken just before that date's external flow |
Flowsflowsmoney (array) · length max 10080; each [-1e+12, 1e+12] | money (array) | length max 10080; each [-1e+12, 1e+12] | External flow just after each valuation but the last (one fewer than the values); positive adds money. Omit for none |
Periodsperiodsperiods · (0, 100000] | periods | (0, 100000] | Length of the span in periods; by default one per sub-period |
Periods per yearperiods_per_yearperiods · (0, 100000] | periods | (0, 100000] | Periods in a year, such as 12, to annualize; omit not to |
Money-weighted return, an IRR (money_weighted): 10 inputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Calculationcalculationtext | text | Money-weighted return, an IRR | |
Beginning valuebeginning_valuemoney · [0, 1e+12] | money | [0, 1e+12] | Portfolio value at the start |
Ending valueending_valuemoney · [0, 1e+12] | money | [0, 1e+12] | Portfolio value at the end |
Flowsflowsmoney (array) · length max 1000; each [-1e+12, 1e+12] | money (array) | length max 1000; each [-1e+12, 1e+12] | External flows in between; positive adds money |
Periodsperiodsperiods · (0, 100000] | periods | (0, 100000] | Periodic flows: the length of the span in periods |
Flow timesflow_timesperiods (array) · length max 1000; each [0, 100000] | periods (array) | length max 1000; each [0, 100000] | Periodic flows: when each flow occurs, in periods from the start |
Start datestart_datedate | date | Dated flows: the start | |
End dateend_datedate | date | Dated flows: the end | |
Flow datesflow_datesdate (array) · length max 1000 | date (array) | length max 1000 | Dated flows: the date of each flow |
Periods per yearperiods_per_yearperiods · (0, 100000] | periods | (0, 100000] | Periods in a year, such as 12, to annualize; omit not to |
Modified Dietz return, day-weighted flows (modified_dietz): 9 inputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Calculationcalculationtext | text | Modified Dietz return, day-weighted flows | |
Beginning valuebeginning_valuemoney · [0, 1e+12] | money | [0, 1e+12] | Portfolio value at the start |
Ending valueending_valuemoney · [0, 1e+12] | money | [0, 1e+12] | Portfolio value at the end |
Start datestart_datedate | date | Start of the period | |
End dateend_datedate | date | End of the period | |
Flowsflowsmoney (array) · length max 1000; each [-1e+12, 1e+12] | money (array) | length max 1000; each [-1e+12, 1e+12] | External flows; positive adds money |
Flow datesflow_datesdate (array) · length max 1000 | date (array) | length max 1000 | The date of each flow |
Periodsperiodsperiods · (0, 100000] | periods | (0, 100000] | Length of the period in periods, for annualizing |
Periods per yearperiods_per_yearperiods · (0, 100000] | periods | (0, 100000] | Periods in a year, such as 12, to annualize; omit not to |
Outputs
Time-weighted return, linked geometrically (time_weighted): 4 outputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Calculationcalculationtext | text | Time-weighted return, linked geometrically | |
Sub period returnssub_period_returnsreturn (array) · length max 10080; each [-1, 100] | return (array) | length max 10080; each [-1, 100] | Return of each sub-period, in order |
Time weighted returntime_weighted_returnreturn · [-1, 1e+06] | return | [-1, 1e+06] | Linked return over the whole span |
Annualized returnannualized_returnreturn · [-1, 1e+06] | return | [-1, 1e+06] | Return compounded to a year; null without periods_per_year |
Money-weighted return, an IRR (money_weighted): 5 outputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Calculationcalculationtext | text | Money-weighted return, an IRR | |
Rateraterate · [-0.99, 10] | rate | [-0.99, 10] | Money-weighted rate per period, or a year for dated flows; null when no rate in [-0.99, 10] solves it |
Money weighted returnmoney_weighted_returnreturn · [-1, 1e+06] | return | [-1, 1e+06] | The rate compounded over the whole span |
Annualized returnannualized_returnreturn · [-1, 1e+06] | return | [-1, 1e+06] | Rate compounded to a year: the rate itself for dated flows; null for periodic flows without periods_per_year |
Flow countflow_countcount · [0, 1000] | count | [0, 1000] | Number of flows |
Modified Dietz return, day-weighted flows (modified_dietz): 4 outputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Calculationcalculationtext | text | Modified Dietz return, day-weighted flows | |
Modified dietz returnmodified_dietz_returnreturn · [-100, 100] | return | [-100, 100] | Gain over day-weighted capital |
Average capitalaverage_capitalmoney · (0, 1.001e+15] | money | (0, 1.001e+15] | Beginning value plus day-weighted flows: the denominator |
Annualized returnannualized_returnreturn · [-1, 1e+06] | return | [-1, 1e+06] | Return compounded to a year; null without periods_per_year |
Calculator
Run the model on your own inputs, starting from its example. Rates are decimals: 0.05 is five percent. The run goes to the pyeconomics API on this site: your values travel only in the request, and nothing is stored.
Loading the calculator…
Worked example
Example quarter_with_a_contribution. Inputs:
{
"calculation": "time_weighted",
"flows": [0, 100, 0],
"periods": null,
"periods_per_year": 12,
"values": [1000, 1050, 1180, 1250]
}Outputs:
{
"annualized_return": 0.6967032311428643,
"calculation": "time_weighted",
"sub_period_returns": [
0.050000000000000044,
0.026086956521739202,
0.05932203389830515
],
"time_weighted_return": 0.14130434782608714
}Assumptions
- External flows are positive when money is added and negative when it is withdrawn; values are market values including income.
- Time-weighted valuations are taken just before each flow; by default every sub-period is one period long, for annualizing.
- Dated money-weighted flows count years as ACT/365 Fixed, as XIRR does, so their rate is already a year's. A Modified Dietz flow on a given day is held for the rest of the period from that day.
Limitations
- A sub-period that starts with no money invested, or a Modified Dietz period with no average capital, raises DomainError; so does a return beyond its bounds.
- The money-weighted rate is null, with a warning, when no rate in [-0.99, 10] solves it; with several, the smallest is reported.
- Modified Dietz approximates the true time-weighted return; it is exact only when no flows occur. Annualizing a span shorter than a year extrapolates it.
Evidence
Status: standard. Textbook consensus, such as bond duration or the CAPM formula.
Every model declares one status: standard (textbook consensus), practitioner (a widely used convention), contested (under active debate), rejected (failed out of sample) or historical (a superseded methodology).
Syllabus
The 2027 CFA® Program's topic areas this model relates to, as factual tags. Each links to CFA Institute's page for its level; pyeconomics holds none of the curriculum's text.
Citations
- Bacon, C. R. (2008). Practical Portfolio Performance Measurement and Attribution, 2nd ed. Wiley. doi:10.1002/9781119206309.ch2 (Chapter 2, pp. 5-37: time-weighted and money-weighted returns, and the day-weighted (Modified) Dietz method). ISBN 9780470059289
- Dietz, P. O. (1966). Pension Funds: Measuring Investment Performance. Free Press. https://openlibrary.org/works/OL159516W (The return as gain over average capital invested, flows held for part of the period (LCCN 66012080))
- Microsoft. XIRR function (Excel), the dated internal rate of return. https://support.microsoft.com/en-us/office/xirr-function-de1242ec-6477-445b-b11b-a303ad9adc9d (Description and example)
Changelog
- Version 1: First version.
- Version 2: Recognize IRR roots at inclusive bracket endpoints (#85).
Use it elsewhere
- Documentation
- The model's reference page
- REST API
GET or POST /v1/models/performance.return_measurement/run- MCP tool
run_modelwith the model's id,performance.return_measurement. Connect an assistant- Command line
pyeconomics models run performance.return_measurement --help
The worked example, from Python and from the command line:
import pyeconomics
inputs = {
"calculation": "time_weighted",
"flows": [0, 100, 0],
"periods": None,
"periods_per_year": 12,
"values": [1000, 1050, 1180, 1250],
}
result = pyeconomics.run("performance.return_measurement", inputs)
print(result.to_json())
pyeconomics models run performance.return_measurement --inputs - <<'JSON'
{
"calculation": "time_weighted",
"flows": [0, 100, 0],
"periods": null,
"periods_per_year": 12,
"values": [1000, 1050, 1180, 1250]
}
JSON