liveBook · Manning

Mean

As explained in Build a Robo-Advisor with Python (From Scratch)

An arithmetic average return is the sum of periodic investment returns divided by the number of periods.

The arithmetic mean return adds periodic returns and divides by their count: A = (1/N) Σrᵢ. It summarizes average periodic performance, but does not directly describe compounded wealth. section 5.2

For historical stock analysis, compute percentage price changes first, then apply pandas mean(). Multiplying a daily mean by 252 produces an annualized estimate. Missing first-period returns are ignored by mean(), although later calculations may require dropna(). section 3.1.1

Use the mean with these distinctions in mind:

  • Compare it with the geometric average: arithmetic averaging treats returns additively, while compounded wealth depends on multiplying 1 + r for each period. section 5.2
  • Account for volatility: a higher return variance increases the gap between arithmetic and geometric averages, approximately as G = A − ½σ². section 5.2
  • Use arithmetic averages as inputs to return simulations, rather than substituting them directly into a compounded future-value calculation. section 5.13 section 5.2
  • Treat historical means cautiously: optimization weights can be highly sensitive to expected returns, and the chosen historical period can materially change the estimate. section 3.1.1

Annualizing daily stock returns

For AAPL, FE, and WMT, calculate adjusted-close percentage changes and run stock_returns.mean()*252. The resulting historical annualized means are 30.7%, 10.0%, and 8.1%, respectively. section 3.1.1

Listing 5.3 Computing arithmetic and geometric average returns
import yfinance as yf

SP500 = yf.download('^GSPC', start='1971-12-31', end='2021-12-31')  #1
SP500 = SP500.resample('Y').last()  #2
SP500['ret'] = SP500['Close'].pct_change()  #3
print('Arithmetic Average: ', SP500['ret'].mean())
print('Standard Deviation: ', SP500['ret'].std())

print('Geometric Average: ', (SP500['Close'].iloc[-1]/SP500['Close']
 .iloc[0])**(1/(len(SP500)-1))-1)
print('Geometric Average Approximation: ', SP500['ret'].mean() 
      - 0.5 * (SP500['ret'].std())**2)

Compare arithmetic and geometric averages, standard deviation, and the volatility-based approximation using annualized S&P 500 data. section 5.2

How Build a Robo-Advisor with Python (From Scratch) covers it

How deep it goes
Defines the formula, implements it with pandas, contrasts compounding, and derives a volatility approximation without assuming normality.
Examples
Computes annualized means for AAPL, FE, and WMT and compares S&P 500 arithmetic and geometric averages.
What it assumes
Assumes periodic returns and basic pandas operations while defining arithmetic and geometric averages explicitly.
What you can do after
Apply it via pandas to calculate periodic and annualized returns, then select arithmetic inputs for simulations.
How it connects
Connects arithmetic averages to geometric averages, volatility, expected returns, and Monte Carlo simulations.

Also explained in

Compare how 29 books explain mean →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Robo-Advisor with Python (From Scratch). The section links point to the parts of the book it draws on.