Return toolkit
Holding-period, arithmetic, geometric, harmonic, annualized, log and real returns.
- Model id
foundations.returns, version 1- Domain
- Foundations
- Evidence
- standard
- Cost class
- instant: A closed-form calculation; a hosted run may take up to 2 seconds.
Formula
Where
- Holding-period return
holding_period_return - Value at the beginning
beginning_value - Value at the end
ending_value - Income received over the period
income - Arithmetic mean return
arithmetic - Geometric mean return
geometric - Harmonic mean return
harmonic - The return in period t
returns - Number of returns
observations - The return for a year
annualized_return - The return over the whole span
period_return - Periods in a year
periods_per_year - Periods the return spans
periods - Log (continuously compounded) return
- Simple return
- Real return
real - Nominal return
nominal - Inflation over the same period
inflation
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
Holding-period return (holding_period): 4 inputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Calculationcalculationtext | text | Holding-period return | |
Beginning valuebeginning_valuemoney · (0, 1e+12] | money | (0, 1e+12] | Value at the start of the period |
Ending valueending_valuemoney · [0, 1e+12] | money | [0, 1e+12] | Value at the end of the period |
Incomeincomemoney · [0, 1e+12] | money | [0, 1e+12] | Income received during the period |
Arithmetic, geometric and harmonic means (means): 2 inputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Calculationcalculationtext | text | Arithmetic, geometric and harmonic means | |
Returnsreturnsreturn (array) · length min 1, max 10080; each [-1, 100] | return (array) | length min 1, max 10080; each [-1, 100] | Periodic returns |
Annualized (compounded) return (annualized): 4 inputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Calculationcalculationtext | text | Annualized (compounded) return | |
Period returnperiod_returnreturn · [-1, 100] | return | [-1, 100] | Return over the whole span |
Periodsperiodsperiods · (0, 100000] | periods | (0, 100000] | Number of periods the return spans |
Periods per yearperiods_per_yearperiods · (0, 100000] | periods | (0, 100000] | Periods in a year, such as 12 or 252 |
Convert between simple and log returns (log): 3 inputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Calculationcalculationtext | text | Convert between simple and log returns | |
Returnsreturnsreturn (array) · length min 1, max 10080; each [-40, 100] | return (array) | length min 1, max 10080; each [-40, 100] | Simple returns, or log returns when direction is log_to_simple |
Directiondirectiontext | text | Which way to convert |
Real rate by the exact Fisher relation (real): 3 inputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Calculationcalculationtext | text | Real rate by the exact Fisher relation | |
Nominalnominalrate · [-0.99, 10] | rate | [-0.99, 10] | Nominal rate or return |
Inflationinflationrate · [-0.5, 10] | rate | [-0.5, 10] | Inflation rate |
Outputs
Holding-period return (holding_period): 4 outputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Calculationcalculationtext | text | Holding-period return | |
Holding period returnholding_period_returnreturn · [-1, 100] | return | [-1, 100] | Return over the holding period |
Income returnincome_returnreturn · [-1, 100] | return | [-1, 100] | Part of the return from income |
Price returnprice_returnreturn · [-1, 100] | return | [-1, 100] | Part of the return from the change in value |
Arithmetic, geometric and harmonic means (means): 5 outputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Calculationcalculationtext | text | Arithmetic, geometric and harmonic means | |
Arithmeticarithmeticreturn · [-1, 100] | return | [-1, 100] | Arithmetic mean return |
Geometricgeometricreturn · [-1, 100] | return | [-1, 100] | Geometric mean return, of the gross returns |
Harmonicharmonicreturn · [-1, 100] | return | [-1, 100] | Harmonic mean return, of the gross returns |
Observationsobservationscount · [1, 10080] | count | [1, 10080] | Number of returns |
Annualized (compounded) return (annualized): 2 outputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Calculationcalculationtext | text | Annualized (compounded) return | |
Annualized returnannualized_returnreturn · [-1, 100] | return | [-1, 100] | Return compounded to one year |
Convert between simple and log returns (log): 2 outputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Calculationcalculationtext | text | Convert between simple and log returns | |
Convertedconvertedreturn (array) · length max 10080; each [-40, 100] | return (array) | length max 10080; each [-40, 100] | The converted returns, in order |
Real rate by the exact Fisher relation (real): 2 outputs
| Name | Unit | Bounds | Description |
|---|---|---|---|
Calculationcalculationtext | text | Real rate by the exact Fisher relation | |
Realrealreturn · [-1, 100] | return | [-1, 100] | Real rate: (1 + nominal) / (1 + inflation) - 1 |
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 stock_with_dividend. Inputs:
{
"beginning_value": 100,
"calculation": "holding_period",
"ending_value": 108,
"income": 2
}Outputs:
{
"calculation": "holding_period",
"holding_period_return": 0.1,
"income_return": 0.02,
"price_return": 0.08
}Assumptions
- Returns are decimals over equal periods, with income reinvested at the end of its period.
- The geometric and harmonic means are of the gross returns 1 + r, less one, so they are compound and harmonic growth rates.
- An annualized return compounds: a return over k periods becomes (1 + R)^(m / k) - 1 for m periods in a year.
Limitations
- A result above 100 (10,000%), or a holding-period return below the series bounds, raises DomainError.
- A simple return of -100% or below has no log return: DomainError.
- A total loss in a series makes its geometric and harmonic means -1, the limit as a gross return falls to zero.
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. https://openlibrary.org/isbn/9780470059289 (Chapter 2 (the mathematics of portfolio return)). ISBN 9780470059289
- Fisher, I. (1930). The Theory of Interest. Macmillan. https://www.econlib.org/library/YPDBooks/Fisher/fshToI.html (Chapter II, Money interest and real interest)
- Hardy, G. H., Littlewood, J. E. and Polya, G. (1952). Inequalities, 2nd ed. Cambridge University Press. https://openlibrary.org/isbn/9780521358804 (Chapter II, elementary mean values (the inequality of means)). ISBN 9780521358804
Changelog
- Version 1: First version.
Use it elsewhere
- Documentation
- The model's reference page
- REST API
GET or POST /v1/models/foundations.returns/run- MCP tool
foundations_returns, orrun_modelwith the model's id; both give the same result. Connect an assistant- Command line
pyeconomics models run foundations.returns --help
The worked example, from Python and from the command line:
import pyeconomics
inputs = {
"beginning_value": 100,
"calculation": "holding_period",
"ending_value": 108,
"income": 2,
}
result = pyeconomics.run("foundations.returns", inputs)
print(result.to_json())
pyeconomics models run foundations.returns --inputs - <<'JSON'
{
"beginning_value": 100,
"calculation": "holding_period",
"ending_value": 108,
"income": 2
}
JSON