2  Summary Statistics

WarningEarly draft

This chapter is an early draft and I have not yet carefully reviewed it. Also the APIs used in the examples may change as I continue working on the book.

In Chapter 2, Bali et al. (2016) summarize the distribution of stock characteristics within each year, then average those statistics across years. This gives each year’s cross-section equal weight.

import numpy as np
import polars as pl
from mizani.labels import label_percent
from plotnine_polars import aes
from scipy.stats import gamma, laplace, norm

from eap_pl import build_bm, build_sizes, get_ff_factors, load_annual_betas, load_parquet

2.1 Implementation

2.1.1 Skewness and Excess Kurtosis

Skewness describes the asymmetry of a distribution. A long right tail typically gives positive skewness, and a long left tail gives negative skewness. Excess kurtosis is especially sensitive to observations far from the mean, in either tail. A distribution can be symmetric and still have high excess kurtosis.

For a given year’s cross-section, subtract the mean \(\bar{x}\) from each of the \(n\) available observations \(x_i\) and divide by the standard deviation computed with divisor \(n\). Call the resulting values \(z_i\). The unadjusted sample skewness \(g_1\) and excess kurtosis \(g_2\) are

\[ g_1 = \frac{1}{n}\sum_{i=1}^n z_i^3, \qquad g_2 = \frac{1}{n}\sum_{i=1}^n z_i^4 - 3. \]

Cubing preserves the sign of each deviation, so large deviations on opposite sides of the mean can offset one another. Taking fourth powers makes both contributions positive and gives the largest deviations even more weight. The subtraction of 3 puts excess kurtosis on a scale where a normal distribution has value zero.

In the left panel of Figure 2.1, the gamma curve extends farther to the right of its mean than to the left. In the right panel, the Laplace and normal curves are both symmetric, with skewness zero. The Laplace distribution puts more probability far out in the tails and has excess kurtosis of 3. About 0.35% of its probability lies more than four standard deviations from the mean, compared with 0.006% for the normal distribution.

Code
z = np.linspace(-5, 5, 501)
densities = pl.concat([
    pl.DataFrame({
        "panel": "Skewness",
        "z": z,
        "Normal": norm.pdf(z),
        "Gamma": gamma.pdf(z, a=4, loc=-2, scale=0.5),
    }).unpivot(index=["panel", "z"], variable_name="distribution", value_name="density"),
    pl.DataFrame({
        "panel": "Excess kurtosis",
        "z": z,
        "Normal": norm.pdf(z),
        "Laplace": laplace.pdf(z, scale=1 / np.sqrt(2)),
    }).unpivot(index=["panel", "z"], variable_name="distribution", value_name="density"),
]).with_columns(pl.col("panel").cast(pl.Enum(["Skewness", "Excess kurtosis"])))

colors = {"Normal": "#555555", "Gamma": "#15627c", "Laplace": "#9b552a"}
(
    densities
    .ggplot(aes(x="z", y="density", color="distribution", linetype="distribution"))
    .geom_line(size=0.9)
    .facet_wrap("panel", ncol=2)
    .scale_color_manual(values=colors, breaks=list(colors))
    .scale_linetype_manual(
        values={"Normal": "dashed", "Gamma": "solid", "Laplace": "solid"},
        breaks=list(colors),
    )
    .labs(x="Standard deviations from the mean", y="Density", color="", linetype="")
    .theme_minimal()
    .add_theme(figure_size=(7.5, 3.4), legend_position="bottom")
)
The left panel compares the symmetric normal density with a gamma density that has a long right tail. The right panel compares the normal density with a symmetric Laplace density that has more probability in the far tails.
Figure 2.1: Illustrative densities for skewness and excess kurtosis. All three distributions have mean zero and standard deviation one.

2.1.2 Periodic Cross-Sectional Summary Statistics

Part I of Bali et al. (2016) focuses on what they describe as the methodologies sample, which covers US common stocks at each December 31 from 1988 through 2012. I use load_annual_betas() to calculate the December value of the 12-month daily beta as shown in Section 8.1.3. It uses all available daily excess returns in the calendar year and requires at least 200 matched observations. I use the June 2014 factor vintage for beta and for the risk-free return.

vintage = "201406"
annual_beta = load_annual_betas(vintage=vintage).collect()

For each year, compute the statistics across the stocks with a beta. I use the sample standard deviation and linearly interpolated percentiles. For skewness and kurtosis, bias=False applies finite-sample corrections to the moments above, and fisher=True gives excess kurtosis. The count is the number of available values in that cross-section.

def cross_section(variable):
    x = pl.col(variable)
    return [
        x.mean().alias("Mean"),
        x.std().alias("SD"),
        x.skew(bias=False).alias("Skew"),
        x.kurtosis(fisher=True, bias=False).alias("Kurt."),
        x.min().alias("Min"),
        x.quantile(.05, interpolation="linear").alias("5%"),
        x.quantile(.25, interpolation="linear").alias("25%"),
        x.median().alias("Median"),
        x.quantile(.75, interpolation="linear").alias("75%"),
        x.quantile(.95, interpolation="linear").alias("95%"),
        x.max().alias("Max"),
        x.count().alias("n"),
    ]

I apply this set of expressions to beta within each year. The same expressions will summarize the other characteristics below.

annual_stats = (
    annual_beta
    .group_by("year")
    .agg(cross_section("Beta"))
    .sort("year")
)
Code
annual_stats.rename({"year": "Year"}).eap.show_table()
Table 2.1: Annual summary statistics for market beta (BEM Table 2.1)
Year Mean SD Skew Kurt. Min 5% 25% Median 75% 95% Max n
1988 0.46 0.48 0.17 2.80 -4.29 -0.20 0.13 0.40 0.75 1.31 3.28 5690
1989 0.46 0.53 0.15 1.89 -3.51 -0.27 0.11 0.40 0.79 1.38 3.63 5519
1990 0.58 0.59 0.23 1.13 -3.15 -0.24 0.16 0.51 0.96 1.61 3.66 5410
1991 0.57 0.61 0.23 1.96 -3.27 -0.30 0.17 0.52 0.95 1.62 5.29 5303
1992 0.65 0.83 0.34 6.09 -5.20 -0.50 0.17 0.59 1.09 2.05 9.89 5390
1993 0.62 0.77 -0.10 4.29 -4.70 -0.55 0.20 0.57 1.04 1.90 7.59 5671
1994 0.70 0.71 -0.17 6.60 -6.91 -0.32 0.27 0.67 1.07 1.89 6.49 6149
1995 0.64 0.84 0.30 5.18 -6.32 -0.49 0.19 0.56 1.02 2.15 8.78 6289
1996 0.67 0.64 0.47 1.98 -4.32 -0.20 0.26 0.59 1.01 1.89 3.98 6586
1997 0.53 0.48 0.39 1.46 -2.36 -0.13 0.21 0.48 0.80 1.38 3.20 6868
1998 0.71 0.51 0.49 0.96 -1.80 0.01 0.34 0.67 1.03 1.62 3.75 6610
1999 0.41 0.50 1.39 4.82 -2.22 -0.18 0.11 0.32 0.61 1.33 3.77 6096
2000 0.70 0.72 1.27 1.33 -1.10 -0.06 0.19 0.49 1.02 2.24 3.77 5900
2001 0.76 0.73 1.29 2.13 -1.47 -0.05 0.25 0.60 1.07 2.25 4.20 5506
2002 0.67 0.55 0.71 0.69 -1.19 -0.04 0.25 0.62 0.97 1.73 2.99 5097
2003 0.72 0.56 0.41 0.49 -2.17 -0.04 0.29 0.68 1.06 1.72 3.04 4734
2004 1.03 0.70 0.43 0.24 -1.74 0.01 0.53 0.99 1.46 2.30 4.02 4571
2005 0.95 0.64 -0.00 -0.17 -1.60 -0.06 0.45 1.00 1.39 1.96 3.69 4494
2006 1.02 0.70 0.08 0.17 -3.71 -0.02 0.48 1.00 1.51 2.19 3.75 4450
2007 0.87 0.54 -0.04 -0.20 -1.50 0.01 0.45 0.91 1.26 1.72 3.06 4325
2008 0.87 0.53 0.17 0.06 -1.49 0.03 0.48 0.87 1.22 1.74 3.45 4258
2009 1.10 0.72 0.52 0.62 -1.73 0.09 0.55 1.03 1.57 2.36 5.31 3969
2010 1.04 0.54 -0.07 -0.15 -0.85 0.10 0.68 1.05 1.41 1.90 2.95 3794
2011 1.07 0.54 -0.14 -0.37 -0.62 0.14 0.70 1.13 1.45 1.93 3.03 3672
2012 1.04 0.57 0.04 0.47 -2.33 0.10 0.65 1.05 1.40 1.99 3.43 3534

2.1.3 Average Cross-Sectional Summary Statistics

To describe the typical cross-section, take the mean of each column in Table 2.1. For example, if \(n_t\) stocks have valid betas in year \(t\), their mean is \(\bar{\beta}_t = \sum_{i=1}^{n_t}\widehat{\beta}_{i,t}/n_t\). The table reports \(T^{-1}\sum_{t=1}^{T}\bar{\beta}_t\). A pooled mean would instead give years with more observations more weight. The same two-step procedure applies to the median and other statistics.

average_stats = annual_stats.select(pl.exclude("year").mean())
Code
(
    average_stats
    .with_columns(pl.col("n").round().cast(pl.Int64))
    .eap.show_table()
)
Table 2.2: Average cross-sectional summary statistics for market beta (BEM Table 2.2)
Mean SD Skew Kurt. Min 5% 25% Median 75% 95% Max n
0.75 0.62 0.34 1.78 -2.78 -0.13 0.33 0.71 1.12 1.85 4.40 5195

The annual table also shows that mean beta increased from 0.46 in 1988 to 1.04 in 2012. The time-series average hides that change.

2.2 Presentation and Interpretation

I also summarize year-end market capitalization in millions of dollars, its natural logarithm (size), book-to-market, and the following calendar year’s excess return.

The December beta observations already calculated for Table 2.1 define the stock-years in the panel. I use permno and year as the join keys, with year denoting the formation year.

start_year, end_year = 1988, 2012
keys = ["permno", "year"]
betas = annual_beta.filter(pl.col("year").is_between(start_year, end_year))

build_sizes() provides monthly market capitalization and its log, as described in Chapter 9. I keep the December observations and use their calendar year as the formation year.

sizes = build_sizes()
capitalizations = (
    sizes
    .filter(pl.col("month").dt.month() == 12)
    .select("permno", year=pl.col("month").dt.year(), MktCap="cap", Size="log_cap")
    .filter(pl.col("year").is_between(start_year, end_year))
)

build_bm() supplies the ratio of prior-year fiscal book equity to prior December market capitalization, as described in Chapter 10. I keep the signed ratio for December, consistent with the negative observations in BEM Table 2.3.

book_to_market = (
    build_bm(sizes)
    .filter(pl.col("month").dt.month() == 12)
    .select("permno", year=pl.col("month").dt.year(), BM="bm_raw")
    .filter(pl.col("year").is_between(start_year, end_year))
)

It appears that BEM compound the available unadjusted monthly CRSP returns for each stock and holding year in the methodologies sample.1 I follow that approach here. However, in Section 7.2 I follow BEM’s convention of adjusting monthly holding returns for delistings.

stock_returns = (
    load_parquet("msf", "crsp")
    .filter(
        pl.col("date").is_between(pl.date(start_year + 1, 1, 1),
                                  pl.date(end_year, 12, 31)),
        pl.col("ret").is_finite(),
    )
    .with_columns(year=pl.col("date").dt.year())
    .group_by(keys)
    .agg(gross_stock=(1 + pl.col("ret")).product())
)

I compound the monthly risk-free returns separately, requiring 12 observations for the year.

risk_free = (
    get_ff_factors("monthly", vintage=vintage).lazy()
    .with_columns(year=pl.col("date").dt.year())
    .filter(pl.col("year").is_between(start_year + 1, end_year))
    .group_by("year")
    .agg(gross_rf=(1 + pl.col("rf")).product(), n=pl.col("rf").count())
    .filter(pl.col("n") == 12)
)

Subtract the annual risk-free return from the stock return and express the difference in percentage points. Subtracting one from the holding year aligns the return with the characteristics measured the preceding December. For example, the return earned in 1989 is joined to the stock’s 1988 characteristics.

next_year = (
    stock_returns
    .join(risk_free, on="year", validate="m:1")
    .select(
        "permno",
        year=pl.col("year") - 1,
        excess=100 * (pl.col("gross_stock") - pl.col("gross_rf")),
    )
)

The left joins keep each stock-year in the beta sample even when a characteristic or return is missing. end_year is both the last formation year and the last calendar year included in the return calculations. In the default sample, this leaves the 2012 formation rows with missing next-year returns. The final .collect() gives us the assembled panel as a Polars DataFrame.

annual_panel = (
    betas.lazy()
    .join(capitalizations, on=keys, how="left", validate="1:1")
    .join(book_to_market, on=keys, how="left", validate="1:1")
    .join(next_year, on=keys, how="left", validate="1:1")
    .collect()
)

I have put these steps into the function build_annual_panel() in the eap_pl package so that later chapters can use the same data for BEM’s methodologies sample. The function defaults to 1988 through 2012 and can reuse the betas we already calculated.

from eap_pl import build_annual_panel

annual_panel = build_annual_panel(annual_betas=annual_beta, vintage=vintage)

Apply the same summary to each variable separately. This keeps stocks with a beta but no book-to-market ratio in the beta row. The observation count reflects the available data for each variable.

variables = ["Beta", "MktCap", "Size", "BM", "excess"]
all_stats = (
    annual_panel
    .unpivot(on=variables, index="year", variable_name="Measure")
    .group_by("year", "Measure")
    .agg(cross_section("value"))
    .group_by("Measure")
    .agg(pl.exclude("year", "Measure").mean())
)
Code
table_2_3 = (
    pl.DataFrame({"Measure": variables})
    .join(all_stats, on="Measure", maintain_order="left")
    .with_columns(
        pl.col("n").round().cast(pl.Int64),
        pl.col("Measure").replace({
            "MktCap": "Market cap",
            "BM": "Book-to-market",
            "excess": "Next-year excess return (%)",
        }),
    )
)
table_2_3.eap.show_table()
Table 2.3: Average annual summary statistics for stock characteristics and next-year returns (BEM Table 2.3)
Measure Mean SD Skew Kurt. Min 5% 25% Median 75% 95% Max n
Beta 0.75 0.62 0.34 1.78 -2.78 -0.13 0.33 0.71 1.12 1.85 4.40 5195
Market cap 2031.97 10238.24 14.20 282.92 0.44 8.95 47.73 188.44 802.39 7526.89 286996.50 5549
Size 5.04 2.07 0.31 -0.07 -1.19 1.89 3.56 4.91 6.39 8.70 12.33 5549
Book-to-market 0.74 3.05 -5.89 1105.03 -124.31 0.05 0.29 0.57 0.98 2.22 51.65 4336
Next-year excess return (%) 12.40 80.84 5.95 125.40 -101.93 -67.47 -26.86 0.90 31.83 124.58 1918.16 5379

Market capitalization has a long right tail, like the gamma curve in Figure 2.1. In Table 2.3, the mean is about $2 billion while the median is about $188 million. Taking logs compresses the largest market capitalizations and reduces both skewness and excess kurtosis. Next-year excess returns have positive skewness and high excess kurtosis on average, with a few very large gains stretching the right tail. The annual mean excess return averages 12.40%, and the annual median averages about 0.90%.

2.2.1 Distribution Shapes in the Methodologies Sample

To compare shapes across variables, I express each observation in standard deviations from its own year’s mean, using the same standardization as in the chapter’s opening example. As in Table 2.3, each available year gets equal weight.

Code
shape_labels = {
    "MktCap": "Market capitalization",
    "Size": "Log market capitalization",
    "BM": "Book-to-market",
    "excess": "Next-year excess return",
}
cross_section_keys = ["year", "measure"]
x = pl.col("value")
shape_data = (
    annual_panel
    .unpivot(on=list(shape_labels), index="year", variable_name="measure")
    .filter(x.is_finite())
    .with_columns(
        z=(x - x.mean().over(cross_section_keys)) / x.std(ddof=0).over(cross_section_keys),
        weight=1 / pl.len().over(cross_section_keys) / pl.col("year").n_unique().over("measure"),
        measure=pl.col("measure").replace_strict(shape_labels).cast(pl.Enum(list(shape_labels.values()))),
    )
)

For the histograms, I keep the two capitalization measures. Summing the weights within a bin averages its share of stocks across years. In Figure 2.2, most raw market capitalizations cluster just below the mean, which a few very large stocks pull to the right. The distribution of log market capitalization is much more symmetric, which helps explain why BEM use it as a measure of size (Bali et al. 2016, sec. 2.2).

Code
(
    shape_data
    .filter(pl.col("measure").is_in([shape_labels["MktCap"], shape_labels["Size"]]))
    .ggplot(aes(x="z", weight="weight"))
    .geom_histogram(binwidth=0.25, boundary=0, fill="#15627c")
    .facet_wrap("measure", ncol=2, scales="free_y")
    .scale_x_continuous(breaks=[-4, -2, 0, 2, 4], expand=(0, 0))
    .scale_y_continuous(labels=label_percent())
    .coord_cartesian(xlim=(-4, 4))
    .labs(x="Standard deviations from the annual mean", y="Average share of stocks per bin")
    .theme_minimal()
    .add_theme(figure_size=(7.5, 3.4))
)
Market capitalization is concentrated in one bin just below the mean. Log market capitalization is spread across a roughly bell-shaped range.
Figure 2.2: Distributions of market capitalization and its logarithm. Bars show the average annual share of stocks in each bin. The figure shows the range from −4 to 4 standard deviations and uses separate vertical scales.

For each tail, I accumulate the weights from the most distant observation toward the mean to find the share of stocks at least that far from the mean. For the normal benchmark, I use the probability of a deviation at least that far into one tail.

Code
# Accumulate the observation weights from farthest to nearest within each tail.
tail_rates = (
    shape_data
    .with_columns(
        distance=pl.col("z").abs(),
        tail=pl.when(pl.col("z") < 0).then(pl.lit("Left tail")).otherwise(pl.lit("Right tail")),
    )
    .filter(pl.col("distance") >= 1)
    .group_by("measure", "tail", "distance")
    .agg(probability=pl.col("weight").sum())
    .sort("distance", descending=True)
    .with_columns(pl.col("probability").cum_sum().over("measure", "tail"))
)

distance = np.linspace(1, 4.4, 121)
normal_tail = pl.DataFrame({
    "distance": distance,
    "probability": norm.sf(distance),
    "tail": "Normal",
})

I plot the empirical tail frequencies as steps and overlay the corresponding one-sided normal probabilities. In Figure 2.3 the two tails of log market capitalization stay relatively close to the normal benchmark. For raw market capitalization and next-year excess returns, large positive deviations reach much farther from the mean than negative ones. There is no left-tail curve for raw market capitalization because no stock lies a full standard deviation below its year’s mean. Book-to-market has extreme observations on both sides. Its farthest observations are negative, even though large positive deviations are more frequent at some distances. Cubing gives those farthest observations a large weight in skewness, and taking fourth powers gives them an even larger weight in kurtosis.

Code
tail_colors = {"Left tail": "#9b552a", "Right tail": "#15627c", "Normal": "#555555"}
(
    tail_rates
    .ggplot(aes(x="distance", y="probability", color="tail", linetype="tail"))
    .geom_step(direction="vh", size=0.85)
    .geom_line(data=normal_tail, size=0.75)
    .facet_wrap("measure", ncol=2)
    .scale_color_manual(values=tail_colors, breaks=list(tail_colors))
    .scale_linetype_manual(
        values={"Left tail": "dashdot", "Right tail": "solid", "Normal": "dashed"},
        breaks=list(tail_colors),
    )
    .scale_x_continuous(
        trans="log2", breaks=[1, 2, 4, 8, 16, 32, 64], minor_breaks=None,
        labels=lambda values: [f"{value:g}" for value in values],
    )
    .scale_y_log10(
        breaks=[0.1, 0.01, 0.001, 0.0001, 0.00001], minor_breaks=None,
        labels=lambda values: [f"{100 * value:g}%" for value in values],
    )
    .labs(
        x="Distance from the annual mean (standard deviations)", y="Average share of stocks",
        color="", linetype="",
    )
    .theme_minimal()
    .add_theme(figure_size=(7.5, 5), legend_position="bottom")
)
Raw market capitalization and next-year excess returns have far-reaching right tails. Log market capitalization has shorter and more nearly symmetric tails. Book-to-market extends far on both sides and reaches farthest on the left.
Figure 2.3: Average annual tail frequencies in the methodologies sample. The normal benchmark gives the same probability for either tail. Both axes are logarithmic, and each empirical curve ends at its most distant observation.

  1. Using unadjusted monthly returns, I obtain an average annual cross-sectional mean and fifth percentile of 12.40% and −67.47%, close to 12.40% and −67.46% in BEM Table 2.3. Applying BEM’s monthly delisting rule (Bali et al. 2016, sec. 7.2) before compounding, with the same formation sample and risk-free returns, gives 11.75% and −69.62%.↩︎