L-Moments

Calculate an L-moment, or an L-moment ratio: the location, spread, asymmetry or tails of the returns of an investment portfolio or asset, robust to a few extreme returns.

L-moments (Hosking 1990) describe the location, scale and shape of a distribution as the ordinary moments do, but as linear combinations of the sorted returns rather than powers of the deviations. This makes them far less sensitive to a few extreme returns and well defined whenever the mean is: the L-skewness and L-kurtosis of a sample are bounded and nearly unbiased, where the sample skewness and kurtosis of fat-tailed returns are dominated by the largest move. The first L-moment is the mean, the second a measure of scale (half the Gini Mean Difference), and the ratios of the third and fourth to the second, the L-skewness and L-kurtosis, measure the asymmetry and the tails. For a normal distribution the L-skewness is 0 and the L-kurtosis 0.1226.

The formula is as follows:

\[\text{L-moment}\; \lambda_{k} = \Sigma_{i} w_{i} \cdot \text{Return}_{i}\] \[w_{i} = \frac{\Sigma_{j} (- 1)^{j} \cdot C(k - 1,\; j) \cdot C(i - 1,\; k - 1 - j) \cdot C(n - i,\; j)}{k \cdot C(n,\; k)}\] \[\text{L-moment ratio}\; \tau_{k} = \frac{\lambda_{k}}{\lambda_{2}} \;\text{for}\; k \geq 3\;\;\text{and}\;\; \tau_{2} = \frac{\lambda_{2}}{\lambda_{1}} \;(\text{the L-CV})\]

Where Return_(i) is the i-th lowest of the n returns, k the order, C the binomial coefficient and j runs from 0 to k - 1. These are Hosking’s unbiased sample L-moments, written as an ordered weighted average as in Cajas (2021).

Also known as: L-moments, L-scale, L-skewness, L-kurtosis, L-CV, linear moments.

Example · PFE, MRK, JNJ · 2021 to 2025

Install the Finance Toolkit with pip install financetoolkit -U, then call get_l_moment:

from financetoolkit import Toolkit

toolkit = Toolkit(
    ["PFE", "MRK", "JNJ"],
    api_key="FINANCIAL_MODELING_PREP_KEY",
    start_date="2021-01-01",
    end_date="2025-12-31",
)

toolkit.risk.get_l_moment(period="yearly", within_period=True, order=3, ratio=True)

Or, with the Finance Toolkit MCP set up, ask an AI assistant such as Claude or ChatGPT:

What was the L-skewness of the daily returns of Pfizer, Merck, Johnson & Johnson and the S&P 500 in each year from 2021 to 2025?

Which returns:

Parameters

get_l_moment accepts the following parameters.

ParameterTypeDescriptionExample
periodstrThe data frequency for returns. Options are: “daily”, “weekly”, “monthly”, “quarterly”, “yearly”. Defaults to “daily”."weekly"
orderintThe order k, an integer of 1 or higher (1 is the mean, 2 the L-scale, 3 with ratio=True the L-skewness and 4 the L-kurtosis). Defaults to 2.2
ratioboolWhether to return the L-moment ratio, which needs an order of 2 or higher. Defaults to False.False
within_periodboolWhether to calculate the L-moment within the specified period or for the entire period. Thus whether to look at the L-moment within a specific year (if period = ‘yearly’) or look at the entirety of all years. Defaults to False. Note that this requires intraday data when period = ‘daily’, since a single day only nests observations when intraday data was fetched.True
rollingintThe rolling window size to use for the calculation. If set, the L-moment is calculated over a rolling window of this many periods across the full return history instead of per period. At least 2. Defaults to None.4
roundingint | NoneThe number of decimals to round the results to. Defaults to None, which uses the rounding of the Toolkit (4 unless set otherwise).2
growthboolWhether to calculate the growth of the L-moment values over time. Defaults to False.True
lagint | list[int]The lag to use for the growth calculation. Defaults to 1.4
standardizeboolWhether to standardize (Z-Score) the result. When combined with growth=True, standardizes the growth values instead of the raw values. Defaults to False.True
show_columnsstr | list[str] | NoneThe columns to keep, a name or a list of names, matched on every column level, or the rows when no column has those names (such as the line items of a financial statement). Names that do not exist are logged, and when none exist the result is returned in full. Defaults to None, which keeps every column.None, which keeps every column

References

  • Paper Hosking, J.R.M. (1990). “L-moments: Analysis and Estimation of Distributions using Linear Combinations of Order Statistics.” Journal of the Royal Statistical Society: Series B, 52(1), 105-124.
  • Paper Cajas, D. (2021). “OWA Portfolio Optimization: A Disciplined Convex Programming Framework.” SSRN Electronic Journal.
  • Library Referenced against Riskfolio-Lib’s L_Moment
  • Library Referenced against scipy’s lmoment
  • Library Shares similar logic as Riskfolio-Lib’s owa_l_moment
Share