liveBook · Manning

Logarithmic return

As explained in Investing for Programmers

A log return is the natural logarithm of the ratio between an asset's ending price and its starting price over a period.

A logarithmic return is the natural logarithm of an asset’s ending-price-to-starting-price ratio. Unlike a simple return, it measures a continuously compounded rate, making it useful for statistical analysis. section 3.4.2

Calculate returns with pandas and NumPy

For a closing-price DataFrame, calculate each period’s return with `np.log(close / close.shift())`, then remove the initial missing value with `dropna()`. Plot the resulting series as a histogram to inspect outliers. section 3.4.2

import numpy as np
log_rets = hist_prices_24["Close"].apply(lambda x: np.log(x / 
x.shift())).dropna()
log_rets

Inspect the executable calculation of logarithmic returns from historical closing prices. section 3.4.2

How Investing for Programmers covers it

How deep it goes
Defines the metric, contrasts it with simple returns, demonstrates code, and stops short of deeper return theory.
Examples
Calculates returns for Apple, Coca-Cola, and NuScale closing-price data, then visualizes their distributions.
What it assumes
Assumes closing-price data and basic previous-day comparisons while introducing simple and logarithmic return calculations.
What you can do after
Apply logarithmic returns with pandas and NumPy, plot their distribution, and inspect potential outliers.
How it connects
Connects logarithmic returns with simple returns, continuous compounding, histograms, mean, standard deviation, and variance.

Also explained in

Compare how 2 books explain logarithmic return →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Investing for Programmers. The section links point to the parts of the book it draws on.