Skip to content

Foundations

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

HPR=V1−V0+DV0HPR = \frac{V_1 - V_0 + D}{V_0}rˉA=1n∑rt\bar{r}_A = \frac{1}{n}\sum r_trˉG=(∏(1+rt))1/n−1\bar{r}_G = \Big(\prod (1 + r_t)\Big)^{1/n} - 1rˉH=n∑(1+rt)−1−1\bar{r}_H = \frac{n}{\sum (1 + r_t)^{-1}} - 1rannual=(1+R)m/k−1r_{\mathrm{annual}} = (1 + R)^{m / k} - 1ℓ=ln⁡(1+r),r=eℓ−1\ell = \ln(1 + r), \quad r = e^{\ell} - 11+rreal=1+i1+π1 + r_{\mathrm{real}} = \frac{1 + i}{1 + \pi}

Where

HPRHPR
Holding-period return holding_period_return
V0V_0
Value at the beginning beginning_value
V1V_1
Value at the end ending_value
DD
Income received over the period income
rˉA\bar{r}_A
Arithmetic mean return arithmetic
rˉG\bar{r}_G
Geometric mean return geometric
rˉH\bar{r}_H
Harmonic mean return harmonic
rtr_t
The return in period t returns
nn
Number of returns observations
rannualr_{\mathrm{annual}}
The return for a year annualized_return
RR
The return over the whole span period_return
mm
Periods in a year periods_per_year
kk
Periods the return spans periods
ℓ\ell
Log (continuously compounded) return
rr
Simple return
rrealr_{\mathrm{real}}
Real return real
ii
Nominal return nominal
π\pi
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
Inputs of the calculation holding_period
NameDescription
CalculationcalculationtextHolding-period return
Beginning valuebeginning_valuemoney · (0, 1e+12]Value at the start of the period
Ending valueending_valuemoney · [0, 1e+12]Value at the end of the period
Incomeincomemoney · [0, 1e+12]Income received during the period
Arithmetic, geometric and harmonic means (means): 2 inputs
Inputs of the calculation means
NameDescription
CalculationcalculationtextArithmetic, geometric and harmonic means
Returnsreturnsreturn (array) · length min 1, max 10080; each [-1, 100]Periodic returns
Annualized (compounded) return (annualized): 4 inputs
Inputs of the calculation annualized
NameDescription
CalculationcalculationtextAnnualized (compounded) return
Period returnperiod_returnreturn · [-1, 100]Return over the whole span
Periodsperiodsperiods · (0, 100000]Number of periods the return spans
Periods per yearperiods_per_yearperiods · (0, 100000]Periods in a year, such as 12 or 252
Convert between simple and log returns (log): 3 inputs
Inputs of the calculation log
NameDescription
CalculationcalculationtextConvert between simple and log returns
Returnsreturnsreturn (array) · length min 1, max 10080; each [-40, 100]Simple returns, or log returns when direction is log_to_simple
DirectiondirectiontextWhich way to convert
Real rate by the exact Fisher relation (real): 3 inputs
Inputs of the calculation real
NameDescription
CalculationcalculationtextReal rate by the exact Fisher relation
Nominalnominalrate · [-0.99, 10]Nominal rate or return
Inflationinflationrate · [-0.5, 10]Inflation rate

Outputs

Holding-period return (holding_period): 4 outputs
Outputs of the calculation holding_period
NameDescription
CalculationcalculationtextHolding-period return
Holding period returnholding_period_returnreturn · [-1, 100]Return over the holding period
Income returnincome_returnreturn · [-1, 100]Part of the return from income
Price returnprice_returnreturn · [-1, 100]Part of the return from the change in value
Arithmetic, geometric and harmonic means (means): 5 outputs
Outputs of the calculation means
NameDescription
CalculationcalculationtextArithmetic, geometric and harmonic means
Arithmeticarithmeticreturn · [-1, 100]Arithmetic mean return
Geometricgeometricreturn · [-1, 100]Geometric mean return, of the gross returns
Harmonicharmonicreturn · [-1, 100]Harmonic mean return, of the gross returns
Observationsobservationscount · [1, 10080]Number of returns
Annualized (compounded) return (annualized): 2 outputs
Outputs of the calculation annualized
NameDescription
CalculationcalculationtextAnnualized (compounded) return
Annualized returnannualized_returnreturn · [-1, 100]Return compounded to one year
Convert between simple and log returns (log): 2 outputs
Outputs of the calculation log
NameDescription
CalculationcalculationtextConvert between simple and log returns
Convertedconvertedreturn (array) · length max 10080; each [-40, 100]The converted returns, in order
Real rate by the exact Fisher relation (real): 2 outputs
Outputs of the calculation real
NameDescription
CalculationcalculationtextReal rate by the exact Fisher relation
Realrealreturn · [-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

  1. 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
  2. Fisher, I. (1930). The Theory of Interest. Macmillan. https://www.econlib.org/library/YPDBooks/Fisher/fshToI.html (Chapter II, Money interest and real interest)
  3. 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, or run_model with 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:

Python
import pyeconomics

inputs = {
    "beginning_value": 100,
    "calculation": "holding_period",
    "ending_value": 108,
    "income": 2,
}
result = pyeconomics.run("foundations.returns", inputs)
print(result.to_json())
Command line
pyeconomics models run foundations.returns --inputs - <<'JSON'
{
  "beginning_value": 100,
  "calculation": "holding_period",
  "ending_value": 108,
  "income": 2
}
JSON