import polars as pl
from plotnine_polars import aes, element_blank
from eap_pl import (
build_annual_panel, format_fit,
get_ff_factors, hac,
)5 Portfolio Analysis
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 5, Bali et al. (2016) use portfolio sorts to study how next year’s excess return varies with beta, market capitalization, and book-to-market. I form portfolios at each December year-end from 1988 to 2012. Holding returns run from 1989 to 2012.
I use build_annual_panel() to assemble the data for BEM’s methodologies sample, as described in Section 2.2. For each stock-year with a December beta estimate, the panel includes that beta, market capitalization and its log, the signed book-to-market ratio, and the following calendar year’s excess return when available.
vintage = "201406"
annual_panel = build_annual_panel(vintage=vintage)I use get_ff_factors() to download the June 2014 releases of the monthly three-factor and momentum series from the Kenneth French Data Library.
ff3 = get_ff_factors("monthly", vintage=vintage)
momentum = get_ff_factors("momentum", vintage=vintage)I join the series by month and keep calendar years with 12 months of data for all four factors. For each factor with monthly return \(f_m\) in decimal units, the annual value in percent is \(100[\prod_{m=1}^{12}(1+f_m)-1]\). Compounding the monthly factors gives a closer match to the four-factor alphas in BEM Table 5.9.1
factor_columns = ["mktrf", "smb", "hml", "mom"]
factors = (
ff3
.join(momentum, on="date", validate="1:1")
.drop_nulls(factor_columns)
.group_by(pl.col("date").dt.year().alias("Holding year"))
.agg(((pl.col(factor_columns) + 1).product() - 1) * 100, months=pl.len())
.filter(pl.col("months") == 12)
.drop("months")
.rename({"mktrf": "MKT", "smb": "SMB", "hml": "HML", "mom": "MOM"})
.sort("Holding year")
)5.1 Univariate Portfolio Analysis
5.1.1 Breakpoints
In year \(t\), let \(\{X_t\}\) be the available values of the sort variable and \(p_k\) the probability used for breakpoint \(k\). For \(n_P\) portfolios, calculate \(n_P-1\) breakpoints.
\[ B_{k,t}=\operatorname{Pctl}_{p_k}(\{X_t\}). \tag{5.1}\]
The beta sort uses the 10th, 20th, 40th, 60th, 80th, and 90th percentiles. The first and last groups each hold about a tenth of the stocks, giving a closer look at both tails of the distribution.
Different quantile methods can give different breakpoints for the same data and percentile. For the values \(0\), \(1\), \(10\), and \(100\), R’s quantile() gives \(0.75\) for the 25th percentile under type 7 and \(0.50\) under type 2. R quantile documentation
I use quantile_method="linear", which calls Polars’ linear interpolation and corresponds to R’s default type 7. To use R’s type-2 rule, pass quantile_method="r" to breakpoints(). The "stata" option uses the same quantile definition with Stata’s arithmetic, which can give a different result when rounding affects whether the rank is treated as a whole number. The eap_pl quantile reference lists the available methods.
def breakpoints(
stocks, variable, probabilities, by, *, quantile_method="linear",
):
return stocks.group_by(by).agg(
pl.col(variable)
.eap.quantile(p, method=quantile_method)
.alias(f"{p:.0%}")
for p in probabilities
)
seven_way = [.10, .20, .40, .60, .80, .90]
beta_stocks = annual_panel.filter(pl.col("Beta").is_finite())
beta_breaks = breakpoints(beta_stocks, "Beta", seven_way, ["year"])Code
beta_breaks.sort("year").rename({"year": "Year"}).eap.show_table()| Year | 10% | 20% | 40% | 60% | 80% | 90% |
|---|---|---|---|---|---|---|
| 1988 | -0.05 | 0.07 | 0.29 | 0.51 | 0.86 | 1.11 |
| 1989 | -0.11 | 0.05 | 0.29 | 0.54 | 0.89 | 1.17 |
| 1990 | -0.06 | 0.10 | 0.37 | 0.68 | 1.07 | 1.37 |
| 1991 | -0.09 | 0.09 | 0.38 | 0.67 | 1.05 | 1.33 |
| 1992 | -0.22 | 0.08 | 0.42 | 0.77 | 1.23 | 1.66 |
| 1993 | -0.21 | 0.10 | 0.44 | 0.73 | 1.18 | 1.55 |
| 1994 | -0.05 | 0.19 | 0.52 | 0.81 | 1.19 | 1.56 |
| 1995 | -0.17 | 0.10 | 0.42 | 0.71 | 1.16 | 1.65 |
| 1996 | 0.00 | 0.19 | 0.46 | 0.73 | 1.14 | 1.52 |
| 1997 | -0.00 | 0.15 | 0.36 | 0.59 | 0.89 | 1.15 |
| 1998 | 0.13 | 0.28 | 0.54 | 0.79 | 1.13 | 1.38 |
| 1999 | -0.06 | 0.06 | 0.24 | 0.42 | 0.70 | 0.99 |
| 2000 | 0.03 | 0.14 | 0.37 | 0.63 | 1.22 | 1.80 |
| 2001 | 0.05 | 0.18 | 0.46 | 0.75 | 1.22 | 1.75 |
| 2002 | 0.04 | 0.17 | 0.48 | 0.75 | 1.06 | 1.37 |
| 2003 | 0.05 | 0.22 | 0.54 | 0.83 | 1.16 | 1.46 |
| 2004 | 0.14 | 0.40 | 0.81 | 1.16 | 1.56 | 1.97 |
| 2005 | 0.09 | 0.33 | 0.80 | 1.14 | 1.49 | 1.74 |
| 2006 | 0.10 | 0.35 | 0.82 | 1.21 | 1.64 | 1.94 |
| 2007 | 0.13 | 0.32 | 0.75 | 1.04 | 1.33 | 1.54 |
| 2008 | 0.16 | 0.38 | 0.74 | 1.02 | 1.31 | 1.54 |
| 2009 | 0.24 | 0.45 | 0.84 | 1.23 | 1.70 | 2.06 |
| 2010 | 0.28 | 0.56 | 0.93 | 1.19 | 1.49 | 1.72 |
| 2011 | 0.26 | 0.56 | 0.99 | 1.25 | 1.52 | 1.73 |
| 2012 | 0.28 | 0.54 | 0.92 | 1.19 | 1.48 | 1.75 |
The next section uses these breakpoints to form portfolios and explains how to assign stocks that land exactly on a breakpoint.
5.1.2 Portfolio Formation
With \(B_{0,t}=-\infty\) and \(B_{n_P,t}=\infty\), portfolio \(k\) contains
\[ P_{k,t}=\{i:B_{k-1,t}\le X_{i,t}\le B_{k,t}\}. \tag{5.2}\]
BEM include both endpoints because two consecutive breakpoints can coincide (2016, sec. 5.1.2). For example, if the 30th and 40th percentiles of past returns are both zero, sending stocks at the breakpoint only up or only down leaves the fourth decile empty. With inclusive endpoints, stocks with zero past returns enter the fourth decile and can also enter neighboring deciles. BEM recommend checking whether the overlapping memberships affect the conclusions.
Here I use assign_ties="both" in assign_portfolio() to follow BEM. The function defaults to assign_ties="lower".
Tidy Finance (Scheuch et al. 2024) also discusses how clustered sort values can leave portfolios empty. Its median-split example sends stocks at the median to the lower group, matching assign_ties="lower". The R package sends stocks exactly on an interior breakpoint to the higher group, matching assign_ties="upper". Book discussion and R package vignette.
The continuous single-sort code for Open Source Asset Pricing (Chen and Zimmermann 2022) assigns a stock exactly on the lowest breakpoint to the bottom portfolio. At other breakpoints, it assigns the stock to the higher portfolio. assign_ties="lower" reproduces this rule for a single breakpoint. For several breakpoints, use assign_ties="upper" and move stocks exactly on the lowest breakpoint back to the bottom portfolio. When multiple breakpoints are requested and the lowest and highest coincide, the code drops that month’s breakpoint estimates. Portfolio construction code.
Suppose we sort three stocks into three portfolios and both breakpoints equal 1. First join each stock to its formation year’s breakpoints. The many-to-one check in validate="m:1" requires at most one breakpoint row per year, so the join cannot duplicate a stock.
example = pl.DataFrame({"year": [2012] * 3, "beta": [0.5, 1.0, 1.5]})
example_breaks = pl.DataFrame({"year": [2012], "q1": [1.0], "q2": [1.0]})
with_breaks = example.join(
example_breaks, on="year", validate="m:1", maintain_order="left",
)For each stock, compare its beta with each breakpoint. Casting the comparisons to integers turns each true result into 1 and each false result into 0, so sum_horizontal() counts the breakpoints that satisfy the comparison. Adding one to the count of breakpoints strictly below beta gives the first eligible portfolio. Including breakpoints equal to beta gives the last eligible portfolio. These are the portfolio numbers used by assign_ties="lower" and assign_ties="upper", respectively.
x = pl.col("beta")
cutoffs = ["q1", "q2"]
first_portfolio = 1 + pl.sum_horizontal(
(x > pl.col(cutoff)).cast(pl.Int32) for cutoff in cutoffs
)
last_portfolio = 1 + pl.sum_horizontal(
(x >= pl.col(cutoff)).cast(pl.Int32) for cutoff in cutoffs
)
(
with_breaks
.select(
"beta",
first_portfolio=first_portfolio,
last_portfolio=last_portfolio,
)
.eap.show_table()
)| beta | first_portfolio | last_portfolio |
|---|---|---|
| 0.50 | 1 | 1 |
| 1.00 | 1 | 3 |
| 1.50 | 3 | 3 |
With assign_ties="both", keep every portfolio from the first to the last. Since pl.int_ranges() excludes its stop, add one to last_portfolio. Use .explode() to turn the list of portfolio numbers into one row per membership. The stock with a beta of 1 enters all three portfolios.
(
with_breaks
.with_columns(portfolio=pl.int_ranges(first_portfolio, last_portfolio + 1))
.explode("portfolio")
.select("beta", "portfolio")
.eap.show_table()
)| beta | portfolio |
|---|---|
| 0.50 | 1 |
| 1.00 | 1 |
| 1.00 | 2 |
| 1.00 | 3 |
| 1.50 | 3 |
The function below applies the same steps to each annual sort. The by argument lists the columns that identify the group, and the remaining columns in breaks supply the cutoffs. The function selects the expression for the requested tie rule, drops the breakpoint columns after assignment, and expands the portfolio lists when the rule is "both".2
def assign_portfolio(
stocks, variable, breaks, by, *, label="portfolio", assign_ties="lower",
):
cutoffs = [name for name in breaks.columns if name not in by]
x = pl.col(variable)
first_portfolio = 1 + pl.sum_horizontal(
(x > pl.col(cutoff)).cast(pl.Int32) for cutoff in cutoffs
)
last_portfolio = 1 + pl.sum_horizontal(
(x >= pl.col(cutoff)).cast(pl.Int32) for cutoff in cutoffs
)
assignments = {
"lower": first_portfolio,
"upper": last_portfolio,
"both": pl.int_ranges(
first_portfolio, last_portfolio + 1, dtype=pl.Int32,
),
}
members = (
stocks
.join(breaks, on=by, validate="m:1", maintain_order="left")
.with_columns(assignments[assign_ties].alias(label))
.drop(cutoffs)
)
return members.explode(label) if assign_ties == "both" else membersFor the annual beta sort, I use the breakpoints from each stock’s formation year.
beta_members = assign_portfolio(
beta_stocks, "Beta", beta_breaks, ["year"], assign_ties="both",
)Code
(
beta_members
.group_by("year", "portfolio")
.len()
.pivot(on="portfolio", index="year", values="len", sort_columns=True)
.sort("year")
.rename({"year": "Year"})
.eap.show_table()
)| Year | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|
| 1988 | 569 | 569 | 1138 | 1138 | 1138 | 569 | 569 |
| 1989 | 552 | 552 | 1104 | 1103 | 1104 | 552 | 552 |
| 1990 | 541 | 541 | 1082 | 1082 | 1082 | 541 | 541 |
| 1991 | 531 | 530 | 1060 | 1061 | 1060 | 530 | 531 |
| 1992 | 539 | 539 | 1078 | 1078 | 1078 | 539 | 539 |
| 1993 | 568 | 568 | 1135 | 1135 | 1135 | 568 | 568 |
| 1994 | 615 | 615 | 1230 | 1229 | 1230 | 615 | 615 |
| 1995 | 629 | 629 | 1258 | 1257 | 1258 | 629 | 629 |
| 1996 | 659 | 659 | 1318 | 1318 | 1318 | 659 | 659 |
| 1997 | 687 | 687 | 1373 | 1374 | 1373 | 687 | 687 |
| 1998 | 661 | 661 | 1322 | 1322 | 1322 | 661 | 661 |
| 1999 | 610 | 610 | 1220 | 1220 | 1220 | 610 | 610 |
| 2000 | 590 | 590 | 1180 | 1180 | 1180 | 590 | 590 |
| 2001 | 551 | 551 | 1102 | 1102 | 1102 | 551 | 551 |
| 2002 | 510 | 510 | 1019 | 1019 | 1019 | 510 | 510 |
| 2003 | 474 | 473 | 947 | 946 | 947 | 473 | 474 |
| 2004 | 458 | 458 | 915 | 915 | 915 | 458 | 458 |
| 2005 | 450 | 449 | 899 | 898 | 899 | 449 | 450 |
| 2006 | 445 | 445 | 890 | 890 | 890 | 445 | 445 |
| 2007 | 433 | 432 | 865 | 865 | 865 | 432 | 433 |
| 2008 | 426 | 426 | 851 | 852 | 851 | 426 | 426 |
| 2009 | 397 | 397 | 794 | 793 | 794 | 397 | 397 |
| 2010 | 380 | 379 | 759 | 758 | 759 | 379 | 380 |
| 2011 | 368 | 367 | 734 | 734 | 734 | 367 | 368 |
| 2012 | 354 | 353 | 707 | 706 | 707 | 353 | 354 |
5.1.3 Average Portfolio Values
For an available outcome \(Y\) and weight \(W\), the portfolio outcome is
\[ Y_{k,t}=\frac{\sum_{i\in P_{k,t}} W_{i,t}Y_{i,t}} {\sum_{i\in P_{k,t}} W_{i,t}}. \tag{5.3}\]
Here \(Y_{i,t}\) is the stock’s excess return in year \(t+1\). For equal weights use \(W_{i,t}=1\). For value weights use December market capitalization and calculate the numerator and denominator on the same set of stocks with available returns and weights. For each year, form the high-minus-low spread
\[ Y_{\mathrm{Diff},t}=Y_{n_P,t}-Y_{1,t}. \tag{5.4}\]
I compute equal- and value-weighted returns within each portfolio and year.
last_holding_year = 2012
r = pl.col("excess")
valid = pl.all_horizontal(r.is_finite(), pl.col("MktCap").is_finite())
w = pl.col("MktCap").filter(valid)
beta_returns = (
beta_members
.filter(pl.col("year") < last_holding_year)
.group_by("year", "portfolio")
.agg(EW=r.mean(), VW=(w * r.filter(valid)).sum() / w.sum())
.with_columns(pl.col("VW").fill_nan(None))
)Each row of beta_returns represents one formation year and beta portfolio. The columns EW and VW give the equal- and value-weighted excess returns for the following year, in percentage points. The first seven rows in year and portfolio order show all seven portfolios formed at the end of 1988.
beta_returns.sort("year", "portfolio").show(7, float_precision=2)| year | portfolio | EW | VW |
|---|---|---|---|
| i32 | i32 | f64 | f64 |
| 1988 | 1 | -0.97 | -2.98 |
| 1988 | 2 | 1.09 | 11.18 |
| 1988 | 3 | 2.12 | 9.02 |
| 1988 | 4 | 6.77 | 16.31 |
| 1988 | 5 | 3.20 | 20.24 |
| 1988 | 6 | 9.04 | 29.16 |
| 1988 | 7 | 8.95 | 18.21 |
In Figure 5.1, points below the dashed line have higher equal-weighted returns.
Code
(
beta_returns
.with_columns(pl.col("portfolio").cast(pl.String))
.ggplot(aes(x="EW", y="VW", color="portfolio"))
.geom_abline(slope=1, intercept=0, color="gray", linetype="dashed")
.geom_point(alpha=0.8)
.coord_fixed()
.scale_color_brewer(type="qual", palette="Dark2")
.labs(
x="Equal-weighted excess return (%)",
y="Value-weighted excess return (%)",
color="Beta portfolio",
)
.theme_minimal()
)
In the lowest-beta portfolio, the equal-weighted return exceeds the value-weighted return in 19 of 24 holding years, more often than in any other portfolio. The gap for that portfolio averages about 16 percentage points.
Each return table shows the seven portfolio returns and the 7–1 spread, with columns for formation and holding years.3
Code
portfolio_columns = [str(group) for group in range(1, 8)]
univariate_columns = [*portfolio_columns, "7–1"]
def univariate_series(cells, outcome):
"""Pivot the outcome to formation-year rows and portfolio columns.
Add the 7–1 spread by subtracting portfolio 1 from portfolio 7
within each year.
"""
return (
cells
.pivot(on="portfolio", index="year", values=outcome)
.sort("year")
.select(
"year",
*portfolio_columns,
(pl.col("7") - pl.col("1")).alias("7–1"),
)
)
def show_holding_year(returns):
"""Display annual outcomes with separate formation and holding years.
Use `year` as the formation year and add one for the holding year.
"""
(
returns
.select(pl.col("year").alias("Formation year"),
pl.col("year").add(1).alias("Holding year"),
pl.exclude("year"))
.eap.show_table()
)
show_holding_year(univariate_series(beta_returns, "EW"))| Formation year | Holding year | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 7–1 |
|---|---|---|---|---|---|---|---|---|---|
| 1988 | 1989 | -0.97 | 1.09 | 2.12 | 6.77 | 3.20 | 9.04 | 8.95 | 9.92 |
| 1989 | 1990 | -30.18 | -29.13 | -28.84 | -29.72 | -27.93 | -26.69 | -25.75 | 4.43 |
| 1990 | 1991 | 57.00 | 28.92 | 36.22 | 39.15 | 55.84 | 64.26 | 67.00 | 10.01 |
| 1991 | 1992 | 55.25 | 30.98 | 29.36 | 21.95 | 19.23 | 15.90 | 20.14 | -35.11 |
| 1992 | 1993 | 36.03 | 27.68 | 22.98 | 23.98 | 19.82 | 15.44 | 7.77 | -28.26 |
| 1993 | 1994 | -4.53 | -3.86 | -5.59 | -4.19 | -5.81 | -10.38 | -4.61 | -0.08 |
| 1994 | 1995 | 28.38 | 21.80 | 24.90 | 29.56 | 27.06 | 23.78 | 37.47 | 9.10 |
| 1995 | 1996 | 21.11 | 16.30 | 18.32 | 14.22 | 12.28 | 11.73 | 9.19 | -11.92 |
| 1996 | 1997 | 22.76 | 39.50 | 28.21 | 20.34 | 17.93 | 6.17 | -7.58 | -30.35 |
| 1997 | 1998 | -6.64 | -9.11 | -7.00 | -10.33 | -6.64 | -6.57 | 0.13 | 6.77 |
| 1998 | 1999 | 14.82 | 10.11 | 19.56 | 23.28 | 38.03 | 61.77 | 93.44 | 78.62 |
| 1999 | 2000 | -11.18 | -4.68 | -0.78 | -1.27 | -3.52 | -10.25 | -31.33 | -20.16 |
| 2000 | 2001 | 37.73 | 28.73 | 27.12 | 28.54 | 22.45 | -1.76 | -22.05 | -59.79 |
| 2001 | 2002 | 11.77 | 10.85 | -0.18 | -8.09 | -22.64 | -36.03 | -53.83 | -65.60 |
| 2002 | 2003 | 76.86 | 68.47 | 85.73 | 64.90 | 63.60 | 76.56 | 86.90 | 10.04 |
| 2003 | 2004 | 27.96 | 20.65 | 25.78 | 21.39 | 15.69 | 12.92 | -0.10 | -28.06 |
| 2004 | 2005 | 6.07 | 5.54 | 2.97 | 3.52 | 2.92 | -3.31 | -10.24 | -16.32 |
| 2005 | 2006 | 9.00 | 17.03 | 12.90 | 10.76 | 6.89 | 12.99 | 12.24 | 3.25 |
| 2006 | 2007 | -13.51 | -13.08 | -6.95 | -7.64 | -6.55 | -2.51 | -4.24 | 9.27 |
| 2007 | 2008 | -42.51 | -42.10 | -41.41 | -39.03 | -40.62 | -45.24 | -44.32 | -1.81 |
| 2008 | 2009 | 57.04 | 64.84 | 65.21 | 59.10 | 55.01 | 60.14 | 73.85 | 16.81 |
| 2009 | 2010 | 20.40 | 19.34 | 22.99 | 22.95 | 33.29 | 30.08 | 36.84 | 16.44 |
| 2010 | 2011 | -3.82 | -5.75 | -1.08 | -4.32 | -6.95 | -14.33 | -16.38 | -12.56 |
| 2011 | 2012 | 28.00 | 27.27 | 16.22 | 20.23 | 16.24 | 17.85 | 18.15 | -9.85 |
Code
show_holding_year(univariate_series(beta_returns, "VW"))| Formation year | Holding year | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 7–1 |
|---|---|---|---|---|---|---|---|---|---|
| 1988 | 1989 | -2.98 | 11.18 | 9.02 | 16.31 | 20.24 | 29.16 | 18.21 | 21.19 |
| 1989 | 1990 | -28.46 | -34.03 | -18.94 | -19.08 | -16.17 | -11.50 | -11.88 | 16.58 |
| 1990 | 1991 | 0.72 | 16.79 | 12.28 | 17.80 | 22.24 | 31.05 | 51.61 | 50.90 |
| 1991 | 1992 | -1.11 | 22.60 | 14.17 | 8.48 | 5.45 | 0.41 | 12.48 | 13.58 |
| 1992 | 1993 | 21.14 | 18.87 | 14.44 | 9.43 | 7.35 | 5.71 | 3.12 | -18.02 |
| 1993 | 1994 | -14.72 | -7.06 | -3.15 | -4.08 | -2.83 | -9.33 | 1.53 | 16.25 |
| 1994 | 1995 | 17.44 | 21.80 | 25.19 | 32.57 | 31.73 | 28.45 | 29.03 | 11.59 |
| 1995 | 1996 | 5.28 | 17.82 | 18.30 | 14.56 | 13.66 | 18.02 | 29.62 | 24.34 |
| 1996 | 1997 | 3.37 | 34.49 | 26.16 | 20.95 | 27.79 | 27.53 | 22.22 | 18.85 |
| 1997 | 1998 | -7.42 | -6.10 | -0.94 | -0.64 | 12.18 | 16.52 | 31.82 | 39.24 |
| 1998 | 1999 | -17.47 | -17.53 | -9.53 | 1.26 | 0.19 | 31.34 | 57.98 | 75.44 |
| 1999 | 2000 | -23.96 | -1.26 | 8.71 | 14.61 | 5.01 | 0.04 | -26.47 | -2.51 |
| 2000 | 2001 | -10.98 | 3.45 | -14.38 | -9.48 | -5.43 | -2.80 | -52.09 | -41.11 |
| 2001 | 2002 | -3.06 | -14.16 | -14.69 | -13.38 | -18.92 | -31.37 | -46.51 | -43.46 |
| 2002 | 2003 | 61.38 | 41.50 | 22.05 | 23.17 | 23.98 | 28.01 | 55.03 | -6.36 |
| 2003 | 2004 | 10.18 | 26.46 | 18.84 | 16.90 | 9.59 | 8.40 | -4.05 | -14.24 |
| 2004 | 2005 | 6.57 | 0.73 | 2.75 | 2.67 | 3.22 | 3.20 | 1.44 | -5.13 |
| 2005 | 2006 | 4.89 | 15.65 | 13.42 | 9.54 | 7.86 | 10.79 | 11.09 | 6.20 |
| 2006 | 2007 | -13.26 | 13.00 | -1.86 | -1.67 | 7.57 | 7.69 | 1.48 | 14.74 |
| 2007 | 2008 | -36.48 | -22.37 | -24.69 | -35.23 | -40.08 | -52.33 | -60.43 | -23.96 |
| 2008 | 2009 | 11.08 | 29.28 | 12.72 | 35.15 | 26.50 | 40.12 | 36.01 | 24.93 |
| 2009 | 2010 | 8.65 | 9.64 | 12.56 | 17.21 | 24.08 | 25.00 | 19.58 | 10.93 |
| 2010 | 2011 | 3.57 | 14.68 | 7.29 | 4.59 | -8.00 | -20.49 | -20.49 | -24.05 |
| 2011 | 2012 | 26.84 | 8.12 | 15.06 | 18.60 | 19.19 | 15.97 | 35.94 | 9.09 |
The 2012 formation cohort appears in the membership tables. The last holding year in the return tables is 2012.
5.1.4 Summarizing the Results
Average the portfolio outcomes and the spreads across the \(T\) available holding years.
\[ \bar{Y}_k=\frac{1}{T}\sum_{t=1}^T Y_{k,t}. \tag{5.5}\]
\[ \bar{Y}_{\mathrm{Diff}}=\frac{1}{T}\sum_{t=1}^T Y_{\mathrm{Diff},t}. \tag{5.6}\]
An intercept-only regression gives the same time-series mean. I use StatsPAI and six Newey–West lags for inference, as specified by BEM. The same function estimates factor-adjusted returns by matching portfolios formed in year \(t\) to factors in year \(t+1\). For the univariate sorts, I fit each portfolio’s annual series directly and match portfolios 7 and 1 by year to calculate the spread.
Code
factor_models = {
"Excess return": [],
"CAPM": ["MKT"],
"FF": ["MKT", "SMB", "HML"],
"FFC": ["MKT", "SMB", "HML", "MOM"],
}
def fit_portfolios(returns, columns, model="Excess return"):
"""Fit the chosen model to each outcome column in an annual table.
Supply one row per formation year, with each series in its own column.
The factor regressions match each formation year to the following
holding year.
Return the fits keyed by outcome column.
"""
terms = factor_models[model]
sample = returns.sort("year")
if terms:
sample = (
sample
.with_columns(pl.col("year").add(1).alias("Holding year"))
.join(
factors.select("Holding year", *terms),
on="Holding year",
how="left",
validate="1:1",
maintain_order="left",
)
)
rhs = " + ".join(terms) or "1"
return {
column: hac(
f"outcome ~ {rhs}",
sample.select(pl.col(column).alias("outcome"), *terms),
)
for column in columns
}
def fit_univariate_portfolios(returns, outcome, model="Excess return"):
"""Fit the outcome for seven portfolios and their 7–1 spread.
Supply one row per formation year and portfolio.
Match portfolios 7 and 1 by year before subtracting their outcomes.
Return the fits keyed by portfolio label and `7–1`.
"""
groups = returns.partition_by("portfolio", as_dict=True)
high = groups[(7,)].select("year", outcome)
low = groups[(1,)].select("year", low=pl.col(outcome))
spread = (
high.join(low, on="year", validate="1:1")
.select("year", (pl.col(outcome) - pl.col("low")).alias(outcome))
)
series = {
str(portfolio): groups[(portfolio,)] for portfolio in range(1, 8)
}
series["7–1"] = spread
return {
label: fit_portfolios(sample, [outcome], model)[outcome]
for label, sample in series.items()
}beta_means = fit_univariate_portfolios(beta_returns, outcome="EW")Code
rows = {"Statistic": ["Average", "Standard error", "t-statistic", "p-value"]}
for column, fit in beta_means.items():
rows[column] = [
fit.params["Intercept"], fit.std_errors["Intercept"],
fit.tvalues["Intercept"], fit.pvalues["Intercept"],
]
pl.DataFrame(rows).eap.show_table()| Statistic | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 7–1 |
|---|---|---|---|---|---|---|---|---|
| Average | 16.53 | 13.81 | 14.53 | 12.75 | 12.03 | 10.90 | 10.48 | -6.05 |
| Standard error | 3.67 | 2.82 | 2.91 | 2.34 | 2.32 | 2.38 | 3.59 | 4.41 |
| t-statistic | 4.51 | 4.89 | 4.99 | 5.45 | 5.18 | 4.59 | 2.92 | -1.37 |
| p-value | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.01 | 0.18 |
5.1.5 Interpreting the Results
In Table 5.8, the high-minus-low spread is negative for beta and market capitalization and positive for book-to-market.
5.1.6 Presenting the Results
Code
pl.DataFrame({
column: [format_fit(fit, "Intercept")]
for column, fit in beta_means.items()
}).eap.show_table()| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 7–1 |
|---|---|---|---|---|---|---|---|
| 16.53 (4.51) |
13.81 (4.89) |
14.53 (4.99) |
12.75 (5.45) |
12.03 (5.18) |
10.90 (4.59) |
10.48 (2.92) |
-6.05 (-1.37) |
Formation-year characteristics can also serve as outcomes. BEM reports the portfolio means and tests the spread. For market capitalization the units are millions of dollars.
Code
variable_labels = {
"Beta": "Beta", "MktCap": "Market cap", "BM": "Book-to-market",
}
characteristics = ["Beta", "MktCap", "BM"]
beta_characteristics = (
beta_members
.group_by("year", "portfolio")
.agg(pl.col(characteristics).mean())
)
rows = []
for variable in characteristics:
series = univariate_series(beta_characteristics, variable)
spread_fit = fit_portfolios(series, ["7–1"])["7–1"]
rows.append([
variable_labels[variable],
*series.select(pl.exclude("year").mean()).row(0),
spread_fit.tvalues["Intercept"],
])
pl.DataFrame(
rows,
schema=["Outcome", *univariate_columns, "7–1 t-statistic"],
orient="row",
).eap.show_table()| Outcome | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 7–1 | 7–1 t-statistic |
|---|---|---|---|---|---|---|---|---|---|
| Beta | -0.22 | 0.14 | 0.41 | 0.71 | 1.03 | 1.37 | 1.94 | 2.16 | 24.79 |
| Market cap | 153.61 | 1076.18 | 2305.59 | 2572.72 | 2533.20 | 2520.40 | 2520.93 | 2367.31 | 3.96 |
| Book-to-market | 0.98 | 1.02 | 0.83 | 0.76 | 0.67 | 0.53 | 0.53 | -0.45 | -3.61 |
Figure 5.2 compares stock sizes across the seven beta portfolios formed in December 2012. I use log market capitalization, as in Section 2.2. Each box spans the 25th to the 75th percentile, and the line inside marks the median. The whiskers reach the farthest observations within 1.5 interquartile ranges of the box, and points mark observations farther out. The two lowest-beta portfolios have the lowest median sizes, but their size distributions overlap with those of the other portfolios.
Code
(
beta_members
.filter(pl.col("year") == 2012, pl.col("Size").is_finite())
.select(pl.col("portfolio").cast(pl.String), log_cap="Size")
.ggplot(aes(x="portfolio", y="log_cap"))
.geom_boxplot(
fill="#c8e1e8", color="#15627c", outlier_size=1.4, outlier_alpha=0.55,
)
.labs(x="Beta portfolio (low to high)", y="Log market capitalization")
.theme_minimal()
.add_theme(figure_size=(7.5, 4.0), panel_grid_major_x=element_blank())
)
The same percentile cutoffs can be applied to other sort variables. Recompute the breakpoints with the available observations for each variable. Use the signed book-to-market ratio from Section 2.2.
def univariate_sort(variable):
stocks = annual_panel.filter(pl.col(variable).is_finite())
breaks = breakpoints(stocks, variable, seven_way, ["year"])
return assign_portfolio(
stocks, variable, breaks, ["year"], assign_ties="both",
)
univariate_means = {"Beta": beta_means}
for variable in ["MktCap", "BM"]:
members = univariate_sort(variable)
returns = (
members
.filter(pl.col("year") < last_holding_year)
.group_by("year", "portfolio")
.agg(pl.col("excess").mean())
)
univariate_means[variable] = fit_univariate_portfolios(
returns, outcome="excess",
)Code
pl.DataFrame(
[
[
variable_labels[variable],
*[format_fit(fit, "Intercept") for fit in fits.values()],
]
for variable, fits in univariate_means.items()
],
schema=["Sort variable", *univariate_columns],
orient="row",
).eap.show_table()| Sort variable | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 7–1 |
|---|---|---|---|---|---|---|---|---|
| Beta | 16.53 (4.51) |
13.81 (4.89) |
14.53 (4.99) |
12.75 (5.45) |
12.03 (5.18) |
10.90 (4.59) |
10.48 (2.92) |
-6.05 (-1.37) |
| Market cap | 29.10 (6.45) |
16.88 (4.62) |
12.15 (3.78) |
10.13 (4.23) |
8.49 (4.69) |
9.20 (4.97) |
8.18 (3.91) |
-20.92 (-5.01) |
| Book-to-market | 7.60 (2.58) |
6.85 (3.19) |
11.05 (4.99) |
13.41 (5.92) |
13.86 (5.57) |
18.60 (6.33) |
23.85 (7.01) |
16.26 (5.86) |
The companion plot in Figure 5.3 compares the return profiles. The size sort has its highest average return in the smallest-stock portfolio. Book-to-market has its highest return in the highest-ratio portfolio.
Code
portfolio_returns = pl.DataFrame({
"portfolio": range(1, 8),
**{
name: [
univariate_means[variable][p].params["Intercept"]
for p in portfolio_columns
]
for variable, name in variable_labels.items()
},
})
(
portfolio_returns
.unpivot(
index="portfolio",
variable_name="characteristic",
value_name="excess",
)
.with_columns(
pl.col("characteristic").cast(pl.Enum(list(variable_labels.values())))
)
.ggplot(aes(x="portfolio", y="excess", color="characteristic"))
.geom_line()
.geom_point(aes(shape="characteristic"))
.scale_x_continuous(breaks=range(1, 8))
.scale_color_brewer(type="qual", palette="Dark2")
.scale_shape_manual(values=["o", "s", "^"])
.labs(
x="Portfolio (low to high)",
y="Average annual excess return (%)",
color="",
shape="",
)
.theme_minimal()
.add_theme(figure_size=(8, 3.8), legend_position="top")
)
5.1.7 Analyzing Returns
Regress each annual portfolio return on factors from the same holding year.
The market model, Fama–French three-factor model, and Carhart four-factor model are
\[ r_{p,t}=\alpha+\beta_{\mathrm{MKT}}\mathrm{MKT}_t+\epsilon_t, \tag{5.7}\]
\[ r_{p,t}=\alpha+\beta_{\mathrm{MKT}}\mathrm{MKT}_t+ \beta_{\mathrm{SMB}}\mathrm{SMB}_t+\beta_{\mathrm{HML}}\mathrm{HML}_t+\epsilon_t, \tag{5.8}\]
\[ r_{p,t}=\alpha+\beta_{\mathrm{MKT}}\mathrm{MKT}_t+ \beta_{\mathrm{SMB}}\mathrm{SMB}_t+\beta_{\mathrm{HML}}\mathrm{HML}_t+ \beta_{\mathrm{MOM}}\mathrm{MOM}_t+\epsilon_t. \tag{5.9}\]
The intercept is the portfolio’s alpha under the chosen model. For a zero-cost spread, the outcome is the difference between the two legs’ excess returns.
Code
from great_tables import md
rows = []
for model, terms in factor_models.items():
fits = (
beta_means if model == "Excess return"
else fit_univariate_portfolios(beta_returns, outcome="EW", model=model)
)
intercept_label = "Mean" if model == "Excess return" else "Alpha"
for term in ["Intercept", *terms]:
label = intercept_label if term == "Intercept" else f"`{term.lower()}`"
rows.append([
model, label, *[format_fit(fit, term) for fit in fits.values()],
])
(
pl.DataFrame(
rows,
schema=["Model", "Coefficient", *univariate_columns],
orient="row",
)
.style
.tab_stub(rowname_col="Coefficient", groupname_col="Model")
.tab_stubhead("Model and coefficient")
.tab_spanner("Beta-sorted portfolios", columns=portfolio_columns)
.cols_align("right", columns=univariate_columns)
.fmt_markdown(columns="Coefficient")
.fmt_passthrough(columns=univariate_columns, escape=False)
.tab_source_note(md("Parentheses report *t*-statistics."))
.tab_options(
row_group_as_column=True,
table_width="100%",
table_font_names="inherit",
table_font_size="0.875rem",
column_labels_font_weight="bold",
stub_border_style="none",
data_row_padding="0.25rem",
)
)| Model and coefficient | Beta-sorted portfolios | 7–1 | |||||||
|---|---|---|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | |||
| Excess return | Mean | 16.53 (4.51) |
13.81 (4.89) |
14.53 (4.99) |
12.75 (5.45) |
12.03 (5.18) |
10.90 (4.59) |
10.48 (2.92) |
-6.05 (-1.37) |
| CAPM | Alpha | 8.95 (1.81) |
6.73 (1.44) |
6.73 (1.48) |
5.34 (1.39) |
3.61 (1.17) |
0.46 (0.20) |
-2.44 (-1.08) |
-11.39 (-1.85) |
mkt |
1.02 (3.45) |
0.95 (3.29) |
1.05 (4.02) |
1.00 (4.06) |
1.14 (5.57) |
1.41 (7.76) |
1.74 (8.42) |
0.72 (1.93) |
|
| FF | Alpha | 3.48 (1.30) |
1.50 (0.95) |
2.15 (1.72) |
1.42 (1.25) |
0.86 (0.63) |
-0.82 (-0.49) |
-1.34 (-0.60) |
-4.82 (-1.54) |
mkt |
1.12 (7.74) |
1.08 (6.28) |
1.13 (8.09) |
1.06 (8.65) |
1.12 (11.65) |
1.31 (10.93) |
1.51 (10.10) |
0.38 (1.76) |
|
smb |
1.53 (7.96) |
1.15 (6.82) |
1.35 (6.63) |
1.24 (9.28) |
1.37 (21.98) |
1.46 (9.72) |
1.64 (7.75) |
0.11 (0.32) |
|
hml |
0.71 (6.38) |
0.77 (10.57) |
0.57 (5.90) |
0.46 (5.94) |
0.18 (1.41) |
-0.16 (-1.09) |
-0.72 (-4.23) |
-1.42 (-6.38) |
|
| FFC | Alpha | 5.51 (2.04) |
6.02 (4.11) |
6.47 (4.35) |
4.49 (3.81) |
2.29 (1.83) |
-0.10 (-0.06) |
-0.10 (-0.03) |
-5.62 (-1.11) |
mkt |
1.06 (7.59) |
0.96 (8.26) |
1.00 (11.24) |
0.97 (11.14) |
1.08 (15.19) |
1.29 (13.58) |
1.47 (9.65) |
0.41 (1.53) |
|
smb |
1.42 (5.74) |
0.91 (4.00) |
1.12 (4.75) |
1.08 (6.04) |
1.29 (12.59) |
1.42 (6.82) |
1.58 (5.99) |
0.16 (0.41) |
|
hml |
0.66 (4.73) |
0.66 (8.01) |
0.47 (7.03) |
0.39 (7.48) |
0.14 (1.22) |
-0.18 (-1.13) |
-0.75 (-4.38) |
-1.40 (-5.92) |
|
mom |
-0.16 (-1.48) |
-0.35 (-3.05) |
-0.34 (-4.42) |
-0.24 (-2.77) |
-0.11 (-1.71) |
-0.06 (-0.39) |
-0.10 (-0.40) |
0.06 (0.23) |
|
| Parentheses report t-statistics. | |||||||||
5.2 Bivariate Independent-Sort Analysis
5.2.1 Breakpoints
To study returns across market-cap groups while controlling for beta, keep stocks with both characteristics. For an independent sort, calculate both sets of breakpoints across this same cross-section. Let \(j\) index the \(n_1\) groups of \(X_1\) and \(k\) index the \(n_2\) groups of \(X_2\).
\[ B_{1j,t}=\operatorname{Pctl}_{p_{1j}}(\{X_{1t}\}). \tag{5.10}\]
\[ B_{2k,t}=\operatorname{Pctl}_{p_{2k}}(\{X_{2t}\}). \tag{5.11}\]
I use the 30th and 70th percentiles for beta and the 25th, 50th, and 75th percentiles for market capitalization.
Use the same percentile and membership functions as in the univariate sort. The second set of breakpoints is grouped only by year here. The dependent sort uses the same pipeline with an additional grouping key for the first portfolio.
control_ports = ["1", "2", "3"]
def bivariate_sort(first, second, *, dependent=False):
stocks = annual_panel.filter(
pl.all_horizontal(pl.col(first, second).is_finite())
)
first_breaks = breakpoints(stocks, first, [.30, .70], ["year"])
first_groups = assign_portfolio(
stocks, first, first_breaks, ["year"],
label="control", assign_ties="both",
)
by = ["year", "control"] if dependent else ["year"]
breakpoint_sample = first_groups if dependent else stocks
second_breaks = breakpoints(breakpoint_sample, second, [.25, .50, .75], by)
members = assign_portfolio(
first_groups, second, second_breaks, by,
label="target", assign_ties="both",
)
return members, first_breaks, second_breaks
independent, first_breaks, second_breaks = bivariate_sort("Beta", "MktCap")Code
(
first_breaks
.join(second_breaks, on="year", validate="1:1")
.sort("year")
.rename({
"year": "Year",
"30%": "Beta 30%",
"70%": "Beta 70%",
"25%": "Market cap 25%",
"50%": "Market cap 50%",
"75%": "Market cap 75%",
})
.eap.show_table()
)| Year | Beta 30% | Beta 70% | Market cap 25% | Market cap 50% | Market cap 75% |
|---|---|---|---|---|---|
| 1988 | 0.18 | 0.66 | 9.65 | 34.83 | 159.51 |
| 1989 | 0.17 | 0.70 | 9.77 | 37.08 | 184.04 |
| 1990 | 0.23 | 0.86 | 6.53 | 25.94 | 149.23 |
| 1991 | 0.24 | 0.85 | 9.71 | 41.56 | 223.52 |
| 1992 | 0.26 | 0.97 | 16.17 | 62.88 | 284.57 |
| 1993 | 0.29 | 0.92 | 22.47 | 78.32 | 345.36 |
| 1994 | 0.36 | 0.97 | 20.73 | 72.30 | 304.26 |
| 1995 | 0.27 | 0.90 | 26.04 | 91.39 | 382.99 |
| 1996 | 0.32 | 0.90 | 28.54 | 102.21 | 439.26 |
| 1997 | 0.26 | 0.72 | 32.65 | 119.62 | 521.35 |
| 1998 | 0.41 | 0.94 | 28.78 | 106.66 | 509.68 |
| 1999 | 0.15 | 0.53 | 33.75 | 128.07 | 622.49 |
| 2000 | 0.26 | 0.85 | 24.26 | 102.16 | 610.02 |
| 2001 | 0.31 | 0.95 | 34.13 | 142.70 | 717.10 |
| 2002 | 0.33 | 0.89 | 33.09 | 130.27 | 634.38 |
| 2003 | 0.38 | 0.97 | 70.18 | 271.02 | 1054.80 |
| 2004 | 0.63 | 1.36 | 91.07 | 335.53 | 1310.39 |
| 2005 | 0.60 | 1.30 | 96.85 | 349.11 | 1410.58 |
| 2006 | 0.61 | 1.40 | 108.65 | 406.97 | 1593.21 |
| 2007 | 0.56 | 1.18 | 93.16 | 354.23 | 1519.79 |
| 2008 | 0.57 | 1.14 | 38.00 | 196.86 | 880.52 |
| 2009 | 0.65 | 1.45 | 68.59 | 307.92 | 1350.83 |
| 2010 | 0.76 | 1.33 | 95.23 | 419.72 | 1844.49 |
| 2011 | 0.82 | 1.39 | 80.66 | 392.63 | 1774.84 |
| 2012 | 0.76 | 1.32 | 106.19 | 485.38 | 2041.60 |
5.2.2 Portfolio Formation
A portfolio is the intersection of a beta group and a market-cap group.
\[ P_{j,k,t}= \{i:B_{1,j-1,t}\le X_{1i,t}\le B_{1j,t}\} \cap \{i:B_{2,k-1,t}\le X_{2i,t}\le B_{2k,t}\}. \tag{5.12}\]
Pivot the portfolio cells so that the beta groups are columns and the market-cap groups are rows within each year.
def control_grid(cells, value):
return (
cells
.pivot(on="control", index=["year", "target"], values=value)
.sort("year", "target")
.select("year", "target", *control_ports)
)Code
independent_counts = independent.group_by("year", "control", "target").len()
control_grid(independent_counts, "len").eap.show_grid("Beta", "Market cap")| Year | Portfolio | Beta portfolios | ||
|---|---|---|---|---|
| 1 | 2 | 3 | ||
| 1988 | Market cap 1 | 736 | 467 | 219 |
| Market cap 2 | 539 | 584 | 298 | |
| Market cap 3 | 336 | 683 | 402 | |
| Market cap 4 | 95 | 540 | 787 | |
| 1989 | Market cap 1 | 737 | 419 | 224 |
| Market cap 2 | 536 | 574 | 269 | |
| Market cap 3 | 298 | 664 | 417 | |
| Market cap 4 | 85 | 549 | 746 | |
| 1990 | Market cap 1 | 726 | 440 | 186 |
| Market cap 2 | 507 | 576 | 268 | |
| Market cap 3 | 287 | 604 | 460 | |
| Market cap 4 | 102 | 542 | 708 | |
| 1991 | Market cap 1 | 762 | 395 | 169 |
| Market cap 2 | 509 | 569 | 247 | |
| Market cap 3 | 255 | 606 | 464 | |
| Market cap 4 | 65 | 550 | 711 | |
| 1992 | Market cap 1 | 681 | 428 | 238 |
| Market cap 2 | 507 | 531 | 309 | |
| Market cap 3 | 308 | 561 | 478 | |
| Market cap 4 | 121 | 634 | 592 | |
| 1993 | Market cap 1 | 741 | 407 | 270 |
| Market cap 2 | 531 | 579 | 308 | |
| Market cap 3 | 329 | 615 | 475 | |
| Market cap 4 | 102 | 667 | 649 | |
| 1994 | Market cap 1 | 768 | 436 | 333 |
| Market cap 2 | 593 | 595 | 349 | |
| Market cap 3 | 354 | 683 | 500 | |
| Market cap 4 | 130 | 744 | 663 | |
| 1995 | Market cap 1 | 785 | 430 | 357 |
| Market cap 2 | 584 | 594 | 394 | |
| Market cap 3 | 373 | 699 | 500 | |
| Market cap 4 | 145 | 791 | 636 | |
| 1996 | Market cap 1 | 791 | 518 | 337 |
| Market cap 2 | 623 | 581 | 442 | |
| Market cap 3 | 422 | 676 | 548 | |
| Market cap 4 | 139 | 858 | 649 | |
| 1997 | Market cap 1 | 867 | 571 | 279 |
| Market cap 2 | 688 | 654 | 375 | |
| Market cap 3 | 415 | 781 | 521 | |
| Market cap 4 | 91 | 740 | 886 | |
| 1998 | Market cap 1 | 842 | 557 | 253 |
| Market cap 2 | 624 | 667 | 361 | |
| Market cap 3 | 369 | 709 | 574 | |
| Market cap 4 | 149 | 709 | 794 | |
| 1999 | Market cap 1 | 784 | 485 | 254 |
| Market cap 2 | 635 | 609 | 278 | |
| Market cap 3 | 339 | 729 | 454 | |
| Market cap 4 | 69 | 613 | 841 | |
| 2000 | Market cap 1 | 609 | 522 | 343 |
| Market cap 2 | 664 | 456 | 353 | |
| Market cap 3 | 291 | 639 | 543 | |
| Market cap 4 | 204 | 741 | 529 | |
| 2001 | Market cap 1 | 687 | 464 | 225 |
| Market cap 2 | 613 | 458 | 305 | |
| Market cap 3 | 189 | 648 | 539 | |
| Market cap 4 | 163 | 631 | 582 | |
| 2002 | Market cap 1 | 760 | 386 | 127 |
| Market cap 2 | 649 | 399 | 224 | |
| Market cap 3 | 93 | 641 | 538 | |
| Market cap 4 | 25 | 610 | 638 | |
| 2003 | Market cap 1 | 835 | 276 | 72 |
| Market cap 2 | 487 | 454 | 242 | |
| Market cap 3 | 52 | 586 | 546 | |
| Market cap 4 | 46 | 578 | 560 | |
| 2004 | Market cap 1 | 771 | 264 | 107 |
| Market cap 2 | 405 | 390 | 347 | |
| Market cap 3 | 56 | 484 | 602 | |
| Market cap 4 | 139 | 688 | 315 | |
| 2005 | Market cap 1 | 833 | 231 | 60 |
| Market cap 2 | 401 | 433 | 290 | |
| Market cap 3 | 33 | 431 | 660 | |
| Market cap 4 | 82 | 703 | 339 | |
| 2006 | Market cap 1 | 816 | 251 | 46 |
| Market cap 2 | 357 | 426 | 330 | |
| Market cap 3 | 19 | 467 | 627 | |
| Market cap 4 | 143 | 636 | 334 | |
| 2007 | Market cap 1 | 808 | 235 | 39 |
| Market cap 2 | 389 | 350 | 343 | |
| Market cap 3 | 28 | 453 | 601 | |
| Market cap 4 | 74 | 693 | 315 | |
| 2008 | Market cap 1 | 742 | 245 | 77 |
| Market cap 2 | 429 | 289 | 346 | |
| Market cap 3 | 42 | 548 | 474 | |
| Market cap 4 | 64 | 619 | 381 | |
| 2009 | Market cap 1 | 689 | 218 | 85 |
| Market cap 2 | 264 | 322 | 406 | |
| Market cap 3 | 75 | 508 | 409 | |
| Market cap 4 | 163 | 538 | 291 | |
| 2010 | Market cap 1 | 714 | 183 | 52 |
| Market cap 2 | 157 | 395 | 396 | |
| Market cap 3 | 69 | 469 | 410 | |
| Market cap 4 | 198 | 471 | 280 | |
| 2011 | Market cap 1 | 718 | 152 | 48 |
| Market cap 2 | 155 | 334 | 429 | |
| Market cap 3 | 48 | 460 | 410 | |
| Market cap 4 | 180 | 523 | 215 | |
| 2012 | Market cap 1 | 660 | 149 | 74 |
| Market cap 2 | 134 | 394 | 355 | |
| Market cap 3 | 84 | 445 | 354 | |
| Market cap 4 | 182 | 424 | 277 | |
5.2.3 Average Portfolio Values
Within each of the 12 portfolios, compute the outcome using the univariate weighting rule. The example uses equal weights.
\[ Y_{j,k,t}=\frac{\sum_{i\in P_{j,k,t}}W_{i,t}Y_{i,t}} {\sum_{i\in P_{j,k,t}}W_{i,t}}. \tag{5.13}\]
A high-minus-low spread along market capitalization holds the beta group fixed. A spread along beta holds the market-cap group fixed.
\[ Y_{j,\mathrm{Diff},t}=Y_{j,n_2,t}-Y_{j,1,t}. \tag{5.14}\]
\[ Y_{\mathrm{Diff},k,t}=Y_{n_1,k,t}-Y_{1,k,t}. \tag{5.15}\]
The results can also be averaged across either set of portfolios. Each group receives equal weight, even when stock counts differ.
\[ Y_{\mathrm{Avg},k,t}=\frac{1}{n_1}\sum_{j=1}^{n_1}Y_{j,k,t}. \tag{5.16}\]
\[ Y_{j,\mathrm{Avg},t}=\frac{1}{n_2}\sum_{k=1}^{n_2}Y_{j,k,t}. \tag{5.17}\]
\[ Y_{\mathrm{Avg},\mathrm{Avg},t} =\frac{1}{n_1}\sum_jY_{j,\mathrm{Avg},t} =\frac{1}{n_2}\sum_kY_{\mathrm{Avg},k,t} =\frac{1}{n_1n_2}\sum_j\sum_kY_{j,k,t}. \tag{5.18}\]
The difference in differences compares the market-cap spread in the highest-beta group with the spread in the lowest-beta group. The same result comes from comparing beta spreads across market-cap groups.
\[ \begin{aligned} Y_{\mathrm{Diff},\mathrm{Diff},t} &=Y_{n_1,n_2,t}-Y_{n_1,1,t}-Y_{1,n_2,t}+Y_{1,1,t}\\ &=Y_{\mathrm{Diff},n_2,t}-Y_{\mathrm{Diff},1,t}\\ &=Y_{n_1,\mathrm{Diff},t}-Y_{1,\mathrm{Diff},t}. \end{aligned} \tag{5.19}\]
Code
pl.DataFrame({
"Second sort": ["Low", "High", "High minus low"],
"First sort low": ["$A$", "$C$", "$C-A$"],
"First sort high": ["$B$", "$D$", "$D-B$"],
"First sort high minus low": [
"$B-A$", "$D-C$", "$(D-C)-(B-A)=(D-B)-(C-A)$",
],
}).eap.show_table()| Second sort | First sort low | First sort high | First sort high minus low |
|---|---|---|---|
| Low | \(A\) | \(B\) | \(B-A\) |
| High | \(C\) | \(D\) | \(D-C\) |
| High minus low | \(C-A\) | \(D-B\) | \((D-C)-(B-A)=(D-B)-(C-A)\) |
Compute the spreads and averages within each holding year before fitting their time-series means or alphas. This preserves the covariance between the portfolio legs in the reported standard errors.
def bivariate_returns(members, *, dependent=False):
cells = (
members
.filter(pl.col("year") < last_holding_year)
.group_by("year", "control", "target")
.agg(pl.col("excess").mean())
)
grid = control_grid(cells, "excess")
control_returns = pl.col(control_ports)
spread = (
grid
.group_by("year")
.agg(
control_returns.filter(pl.col("target") == 4).first()
- control_returns.filter(pl.col("target") == 1).first()
)
.with_columns(target=pl.lit(5))
)
rows = [grid, spread.select(grid.columns)]
if not dependent:
average = (
grid
.group_by("year")
.agg(pl.col(control_ports).mean())
.with_columns(target=pl.lit(6))
)
rows.append(average.select(grid.columns))
return (
pl.concat(rows)
.sort("year", "target")
.with_columns(
Diff=pl.col("3") - pl.col("1"),
Avg=pl.mean_horizontal(control_ports, ignore_nulls=False),
)
)
independent_returns = bivariate_returns(independent)Code
independent_returns.eap.show_grid("Beta", "Market cap", holding=True)| Formation year | Holding year | Portfolio | Beta portfolios | ||||
|---|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 3–1 | Average | |||
| 1988 | 1989 | Market cap 1 | 1.13 | −0.96 | 1.58 | 0.45 | 0.58 |
| Market cap 2 | −2.02 | −1.54 | −9.91 | −7.89 | −4.49 | ||
| Market cap 3 | 4.56 | 3.57 | 5.47 | 0.91 | 4.53 | ||
| Market cap 4 | 9.92 | 14.48 | 17.03 | 7.11 | 13.81 | ||
| Market cap 4–1 | 8.80 | 15.45 | 15.45 | 6.65 | 13.23 | ||
| Market cap average | 3.40 | 3.89 | 3.54 | 0.14 | 3.61 | ||
| 1989 | 1990 | Market cap 1 | −27.16 | −32.26 | −14.18 | 12.97 | −24.54 |
| Market cap 2 | −32.20 | −37.25 | −39.78 | −7.59 | −36.41 | ||
| Market cap 3 | −27.71 | −31.91 | −32.91 | −5.21 | −30.84 | ||
| Market cap 4 | −24.51 | −20.05 | −19.70 | 4.81 | −21.42 | ||
| Market cap 4–1 | 2.65 | 12.22 | −5.51 | −8.16 | 3.12 | ||
| Market cap average | −27.89 | −30.37 | −26.64 | 1.25 | −28.30 | ||
| 1990 | 1991 | Market cap 1 | 54.26 | 64.98 | 106.35 | 52.09 | 75.20 |
| Market cap 2 | 38.00 | 43.96 | 74.34 | 36.33 | 52.10 | ||
| Market cap 3 | 23.22 | 41.36 | 54.21 | 30.99 | 39.60 | ||
| Market cap 4 | 15.71 | 28.71 | 47.61 | 31.90 | 30.67 | ||
| Market cap 4–1 | −38.55 | −36.28 | −58.74 | −20.19 | −44.52 | ||
| Market cap average | 32.80 | 44.75 | 70.63 | 37.83 | 49.39 | ||
| 1991 | 1992 | Market cap 1 | 56.59 | 41.61 | 64.00 | 7.41 | 54.07 |
| Market cap 2 | 24.64 | 25.01 | 18.36 | −6.27 | 22.67 | ||
| Market cap 3 | 24.30 | 18.93 | 10.91 | −13.39 | 18.05 | ||
| Market cap 4 | 16.09 | 14.20 | 9.57 | −6.52 | 13.29 | ||
| Market cap 4–1 | −40.50 | −27.42 | −54.44 | −13.94 | −40.78 | ||
| Market cap average | 30.40 | 24.94 | 25.71 | −4.69 | 27.02 | ||
| 1992 | 1993 | Market cap 1 | 42.29 | 46.68 | 37.23 | −5.06 | 42.07 |
| Market cap 2 | 20.77 | 25.45 | 13.77 | −7.01 | 20.00 | ||
| Market cap 3 | 18.16 | 15.27 | 5.55 | −12.62 | 12.99 | ||
| Market cap 4 | 15.94 | 11.82 | 11.90 | −4.03 | 13.22 | ||
| Market cap 4–1 | −26.36 | −34.86 | −25.33 | 1.03 | −28.85 | ||
| Market cap average | 24.29 | 24.81 | 17.11 | −7.18 | 22.07 | ||
| 1993 | 1994 | Market cap 1 | −1.88 | 0.19 | −7.44 | −5.56 | −3.05 |
| Market cap 2 | −8.68 | −5.09 | −8.16 | 0.52 | −7.31 | ||
| Market cap 3 | −5.81 | −4.21 | −10.38 | −4.57 | −6.80 | ||
| Market cap 4 | −4.92 | −6.14 | −5.93 | −1.00 | −5.66 | ||
| Market cap 4–1 | −3.04 | −6.33 | 1.52 | 4.56 | −2.62 | ||
| Market cap average | −5.32 | −3.81 | −7.98 | −2.65 | −5.70 | ||
| 1994 | 1995 | Market cap 1 | 28.12 | 30.14 | 26.68 | −1.44 | 28.31 |
| Market cap 2 | 25.27 | 34.27 | 35.48 | 10.21 | 31.67 | ||
| Market cap 3 | 22.55 | 26.71 | 29.35 | 6.80 | 26.21 | ||
| Market cap 4 | 19.72 | 23.68 | 24.47 | 4.75 | 22.62 | ||
| Market cap 4–1 | −8.40 | −6.46 | −2.21 | 6.19 | −5.69 | ||
| Market cap average | 23.92 | 28.70 | 29.00 | 5.08 | 27.20 | ||
| 1995 | 1996 | Market cap 1 | 24.71 | 15.18 | 16.05 | −8.66 | 18.65 |
| Market cap 2 | 13.64 | 12.29 | 8.16 | −5.48 | 11.36 | ||
| Market cap 3 | 19.81 | 16.19 | 7.68 | −12.13 | 14.56 | ||
| Market cap 4 | 15.45 | 15.49 | 9.42 | −6.03 | 13.45 | ||
| Market cap 4–1 | −9.26 | 0.31 | −6.63 | 2.63 | −5.20 | ||
| Market cap average | 18.40 | 14.79 | 10.33 | −8.07 | 14.51 | ||
| 1996 | 1997 | Market cap 1 | 27.50 | 14.82 | 1.03 | −26.47 | 14.45 |
| Market cap 2 | 34.26 | 21.36 | 0.19 | −34.07 | 18.60 | ||
| Market cap 3 | 33.25 | 24.15 | −0.15 | −33.40 | 19.08 | ||
| Market cap 4 | 24.78 | 24.28 | 14.41 | −10.37 | 21.16 | ||
| Market cap 4–1 | −2.72 | 9.47 | 13.38 | 16.10 | 6.71 | ||
| Market cap average | 29.95 | 21.15 | 3.87 | −26.08 | 18.32 | ||
| 1997 | 1998 | Market cap 1 | −6.24 | −7.08 | −9.22 | −2.98 | −7.51 |
| Market cap 2 | −12.45 | −13.40 | −18.89 | −6.43 | −14.92 | ||
| Market cap 3 | −5.25 | −9.13 | −9.97 | −4.72 | −8.12 | ||
| Market cap 4 | −2.89 | −2.48 | 5.50 | 8.38 | 0.04 | ||
| Market cap 4–1 | 3.35 | 4.59 | 14.71 | 11.36 | 7.55 | ||
| Market cap average | −6.71 | −8.02 | −8.15 | −1.44 | −7.62 | ||
| 1998 | 1999 | Market cap 1 | 32.65 | 66.72 | 114.11 | 81.45 | 71.16 |
| Market cap 2 | 9.64 | 38.20 | 79.21 | 69.57 | 42.35 | ||
| Market cap 3 | −8.62 | 17.84 | 56.12 | 64.74 | 21.78 | ||
| Market cap 4 | −14.57 | −4.55 | 46.49 | 61.06 | 9.12 | ||
| Market cap 4–1 | −47.22 | −71.27 | −67.62 | −20.40 | −62.04 | ||
| Market cap average | 4.78 | 29.55 | 73.98 | 69.20 | 36.10 | ||
| 1999 | 2000 | Market cap 1 | −6.80 | −14.13 | −33.29 | −26.49 | −18.07 |
| Market cap 2 | −8.73 | −10.63 | −26.45 | −17.72 | −15.27 | ||
| Market cap 3 | −0.25 | 4.16 | −13.22 | −12.96 | −3.10 | ||
| Market cap 4 | 7.68 | 13.11 | −8.73 | −16.41 | 4.02 | ||
| Market cap 4–1 | 14.48 | 27.23 | 24.56 | 10.08 | 22.09 | ||
| Market cap average | −2.02 | −1.87 | −20.42 | −18.40 | −8.11 | ||
| 2000 | 2001 | Market cap 1 | 44.20 | 52.76 | 20.97 | −23.23 | 39.31 |
| Market cap 2 | 29.77 | 43.91 | 0.50 | −29.27 | 24.73 | ||
| Market cap 3 | 31.80 | 22.57 | 0.55 | −31.25 | 18.31 | ||
| Market cap 4 | −2.33 | 4.45 | −20.42 | −18.08 | −6.10 | ||
| Market cap 4–1 | −46.54 | −48.31 | −41.39 | 5.15 | −45.41 | ||
| Market cap average | 25.86 | 30.92 | 0.40 | −25.46 | 19.06 | ||
| 2001 | 2002 | Market cap 1 | 7.30 | −6.21 | −31.57 | −38.87 | −10.16 |
| Market cap 2 | 14.51 | −8.99 | −41.64 | −56.15 | −12.04 | ||
| Market cap 3 | 3.15 | −10.10 | −42.59 | −45.74 | −16.52 | ||
| Market cap 4 | −7.97 | −8.65 | −38.66 | −30.69 | −18.43 | ||
| Market cap 4–1 | −15.28 | −2.44 | −7.09 | 8.19 | −8.27 | ||
| Market cap average | 4.25 | −8.49 | −38.62 | −42.86 | −14.29 | ||
| 2002 | 2003 | Market cap 1 | 105.60 | 131.01 | 184.52 | 78.91 | 140.38 |
| Market cap 2 | 56.26 | 99.75 | 109.02 | 52.76 | 88.35 | ||
| Market cap 3 | 37.15 | 45.27 | 71.56 | 34.41 | 51.33 | ||
| Market cap 4 | 23.00 | 30.98 | 49.36 | 26.36 | 34.45 | ||
| Market cap 4–1 | −82.60 | −100.02 | −135.16 | −52.56 | −105.93 | ||
| Market cap average | 55.50 | 76.75 | 103.61 | 48.11 | 78.62 | ||
| 2003 | 2004 | Market cap 1 | 28.58 | 24.03 | 21.81 | −6.77 | 24.81 |
| Market cap 2 | 20.46 | 17.24 | 7.89 | −12.57 | 15.20 | ||
| Market cap 3 | 23.38 | 22.22 | 6.82 | −16.56 | 17.47 | ||
| Market cap 4 | 27.28 | 19.83 | 10.90 | −16.38 | 19.34 | ||
| Market cap 4–1 | −1.30 | −4.20 | −10.91 | −9.61 | −5.47 | ||
| Market cap average | 24.93 | 20.83 | 11.85 | −13.07 | 19.20 | ||
| 2004 | 2005 | Market cap 1 | 2.77 | 2.71 | −28.97 | −31.74 | −7.83 |
| Market cap 2 | 4.64 | −2.03 | −7.32 | −11.96 | −1.57 | ||
| Market cap 3 | 14.31 | 4.14 | −0.48 | −14.80 | 5.99 | ||
| Market cap 4 | 3.08 | 7.56 | 4.59 | 1.51 | 5.08 | ||
| Market cap 4–1 | 0.31 | 4.86 | 33.56 | 33.25 | 12.91 | ||
| Market cap average | 6.20 | 3.10 | −8.04 | −14.25 | 0.42 | ||
| 2005 | 2006 | Market cap 1 | 12.78 | 13.75 | −5.60 | −18.38 | 6.98 |
| Market cap 2 | 14.24 | 13.78 | 10.88 | −3.36 | 12.97 | ||
| Market cap 3 | 11.97 | 9.45 | 11.60 | −0.37 | 11.01 | ||
| Market cap 4 | 9.12 | 9.26 | 8.06 | −1.06 | 8.81 | ||
| Market cap 4–1 | −3.66 | −4.50 | 13.65 | 17.32 | 1.83 | ||
| Market cap average | 12.03 | 11.56 | 6.24 | −5.79 | 9.94 | ||
| 2006 | 2007 | Market cap 1 | −12.84 | −10.51 | −28.89 | −16.05 | −17.41 |
| Market cap 2 | −11.47 | −12.16 | −11.12 | 0.35 | −11.58 | ||
| Market cap 3 | −12.44 | −9.85 | −5.84 | 6.60 | −9.37 | ||
| Market cap 4 | 0.09 | −1.10 | 8.37 | 8.29 | 2.46 | ||
| Market cap 4–1 | 12.93 | 9.41 | 37.26 | 24.33 | 19.87 | ||
| Market cap average | −9.16 | −8.40 | −9.37 | −0.20 | −8.98 | ||
| 2007 | 2008 | Market cap 1 | −46.52 | −49.11 | −56.53 | −10.02 | −50.72 |
| Market cap 2 | −38.74 | −48.02 | −45.21 | −6.48 | −43.99 | ||
| Market cap 3 | −37.68 | −34.21 | −37.19 | 0.50 | −36.36 | ||
| Market cap 4 | −32.03 | −34.74 | −50.97 | −18.94 | −39.25 | ||
| Market cap 4–1 | 14.49 | 14.37 | 5.56 | −8.93 | 11.47 | ||
| Market cap average | −38.74 | −41.52 | −47.48 | −8.74 | −42.58 | ||
| 2008 | 2009 | Market cap 1 | 95.49 | 155.48 | 150.77 | 55.28 | 133.91 |
| Market cap 2 | 29.02 | 49.59 | 86.76 | 57.74 | 55.13 | ||
| Market cap 3 | 11.18 | 37.43 | 51.16 | 39.98 | 33.26 | ||
| Market cap 4 | 15.69 | 32.88 | 47.94 | 32.25 | 32.17 | ||
| Market cap 4–1 | −79.80 | −122.60 | −102.83 | −23.03 | −101.74 | ||
| Market cap average | 37.85 | 68.84 | 84.16 | 46.31 | 63.62 | ||
| 2009 | 2010 | Market cap 1 | 21.42 | 34.28 | 30.44 | 9.03 | 28.71 |
| Market cap 2 | 20.59 | 25.62 | 37.26 | 16.66 | 27.82 | ||
| Market cap 3 | 13.02 | 24.94 | 34.22 | 21.20 | 24.06 | ||
| Market cap 4 | 17.25 | 23.55 | 29.32 | 12.07 | 23.37 | ||
| Market cap 4–1 | −4.17 | −10.73 | −1.12 | 3.04 | −5.34 | ||
| Market cap average | 18.07 | 27.10 | 32.81 | 14.74 | 25.99 | ||
| 2010 | 2011 | Market cap 1 | −8.38 | −19.22 | −39.11 | −30.72 | −22.24 |
| Market cap 2 | −5.63 | −8.06 | −15.27 | −9.63 | −9.65 | ||
| Market cap 3 | 4.75 | −0.14 | −7.85 | −12.60 | −1.08 | ||
| Market cap 4 | 10.50 | 1.52 | −10.52 | −21.02 | 0.50 | ||
| Market cap 4–1 | 18.88 | 20.74 | 28.59 | 9.71 | 22.74 | ||
| Market cap average | 0.31 | −6.48 | −18.19 | −18.49 | −8.12 | ||
| 2011 | 2012 | Market cap 1 | 27.94 | 9.70 | −9.06 | −37.00 | 9.53 |
| Market cap 2 | 28.44 | 19.94 | 18.80 | −9.65 | 22.39 | ||
| Market cap 3 | 10.19 | 17.00 | 20.49 | 10.30 | 15.90 | ||
| Market cap 4 | 12.35 | 17.71 | 16.92 | 4.57 | 15.66 | ||
| Market cap 4–1 | −15.59 | 8.02 | 25.98 | 41.57 | 6.13 | ||
| Market cap average | 19.73 | 16.09 | 11.79 | −7.95 | 15.87 | ||
5.2.4 Summarizing the Results
The full return grid reports both excess returns and four-factor alphas. For each market-cap group, fit the models to the portfolios in that row and to the spread and average across beta groups.
def grid_fits(returns):
columns = [*control_ports, "Diff", "Avg"]
return {
(group, model): fit_portfolios(
returns.filter(pl.col("target") == group), columns, model,
)
for group in sorted(returns["target"].unique())
for model in ["Excess return", "FFC"]
}
independent_fits = grid_fits(independent_returns)Code
def target_label(variable, group):
"""Label a target portfolio, spread, or average for the table."""
return (
f"{variable_labels[variable]} "
+ {5: "4–1", 6: "average"}.get(group, str(group))
)
def show_grid_fits(fits, *, dependent=False):
"""Display mean returns and four-factor alphas for a bivariate sort."""
columns = (
[*control_ports, "Avg"] if dependent
else [*control_ports, "Diff", "Avg"]
)
headers = [f"Beta {column}" for column in columns]
rows = [
[
target_label("MktCap", group),
label,
*[
format_fit(fits[group, model][column], "Intercept")
for column in columns
],
]
for group in range(1, 6 if dependent else 7)
for model, label in [
("Excess return", "Excess return"), ("FFC", "FFC alpha"),
]
]
pl.DataFrame(
rows, schema=["Portfolio", "Statistic", *headers], orient="row",
).eap.show_table()
show_grid_fits(independent_fits)| Portfolio | Statistic | Beta 1 | Beta 2 | Beta 3 | Beta Diff | Beta Avg |
|---|---|---|---|---|---|---|
| Market cap 1 | Excess return | 20.98 (5.51) |
23.52 (5.46) |
21.32 (3.35) |
0.34 (0.08) |
21.94 (4.95) |
| Market cap 1 | FFC alpha | 11.98 (4.22) |
18.33 (5.19) |
9.83 (1.25) |
-2.14 (-0.35) |
13.38 (3.17) |
| Market cap 2 | Excess return | 11.01 (3.72) |
13.47 (3.54) |
11.54 (3.61) |
0.53 (0.16) |
12.00 (4.16) |
| Market cap 2 | FFC alpha | -0.02 (-0.01) |
1.42 (0.42) |
0.83 (0.31) |
0.84 (0.18) |
0.74 (0.50) |
| Market cap 3 | Excess return | 8.71 (2.88) |
10.49 (4.72) |
8.55 (3.76) |
-0.16 (-0.04) |
9.25 (4.52) |
| Market cap 3 | FFC alpha | -0.95 (-0.28) |
1.33 (1.19) |
-1.23 (-0.85) |
-0.28 (-0.06) |
-0.29 (-0.27) |
| Market cap 4 | Excess return | 6.43 (3.87) |
8.99 (5.92) |
8.62 (3.40) |
2.19 (1.02) |
8.02 (4.74) |
| Market cap 4 | FFC alpha | -0.96 (-0.72) |
1.78 (2.41) |
-1.48 (-0.81) |
-0.53 (-0.21) |
-0.22 (-0.27) |
| Market cap 4–1 | Excess return | -14.55 (-4.51) |
-14.53 (-3.70) |
-12.70 (-2.26) |
1.85 (0.64) |
-13.92 (-3.50) |
| Market cap 4–1 | FFC alpha | -12.93 (-3.44) |
-16.56 (-4.70) |
-11.32 (-1.55) |
1.62 (0.40) |
-13.60 (-3.05) |
| Market cap average | Excess return | 11.78 (4.50) |
14.12 (5.37) |
12.51 (4.11) |
0.72 (0.27) |
12.80 (5.14) |
| Market cap average | FFC alpha | 2.51 (1.36) |
5.71 (4.02) |
1.99 (0.68) |
-0.53 (-0.14) |
3.40 (2.46) |
5.2.5 Interpreting the Results
5.2.6 Presenting the Results
Code
rows = []
for group in range(1, 7):
fits = independent_fits[group, "FFC"]
row = [
format_fit(fits[c], "Intercept") if c in ["Diff", "Avg"] or group > 4
else f"{fits[c].params['Intercept']:.2f}"
for c in [*control_ports, "Diff", "Avg"]
]
if group == 6:
row[-1] = None
rows.append([target_label("MktCap", group), *row])
pl.DataFrame(
rows,
schema=[
"Portfolio", "Beta 1", "Beta 2", "Beta 3", "Beta 3–1", "Beta average",
],
orient="row",
).eap.show_table()| Portfolio | Beta 1 | Beta 2 | Beta 3 | Beta 3–1 | Beta average |
|---|---|---|---|---|---|
| Market cap 1 | 11.98 | 18.33 | 9.83 | -2.14 (-0.35) |
13.38 (3.17) |
| Market cap 2 | -0.02 | 1.42 | 0.83 | 0.84 (0.18) |
0.74 (0.50) |
| Market cap 3 | -0.95 | 1.33 | -1.23 | -0.28 (-0.06) |
-0.29 (-0.27) |
| Market cap 4 | -0.96 | 1.78 | -1.48 | -0.53 (-0.21) |
-0.22 (-0.27) |
| Market cap 4–1 | -12.93 (-3.44) |
-16.56 (-4.70) |
-11.32 (-1.55) |
1.62 (0.40) |
-13.60 (-3.05) |
| Market cap average | 2.51 (1.36) |
5.71 (4.02) |
1.99 (0.68) |
-0.53 (-0.14) |
To check the size effect with a different control, group on book-to-market first and market capitalization second. Both sets of breakpoints still use the entire cross-section of eligible stocks.
independent_bm_cap, _, _ = bivariate_sort("BM", "MktCap")
bm_cap_fits = grid_fits(bivariate_returns(independent_bm_cap))
cap_controls = {"Beta": independent_fits, "BM": bm_cap_fits}First report the market-cap spread within each control group, along with its average and the difference between the extreme control groups.
Code
def show_spreads(results, label):
"""Display target spreads by control group.
Include the average and high-minus-low difference across groups.
"""
columns = [*control_ports, "Avg", "Diff"]
rows = [
[
variable_labels[variable],
statistic,
*[
format_fit(fits[5, model][column], "Intercept")
for column in columns
],
]
for variable, fits in results.items()
for model, statistic in [
("Excess return", "Excess return"), ("FFC", "FFC alpha"),
]
]
pl.DataFrame(
rows,
schema=[label, "Statistic", "1", "2", "3", "Average", "3–1"],
orient="row",
).eap.show_table()
show_spreads(cap_controls, "Control")| Control | Statistic | 1 | 2 | 3 | Average | 3–1 |
|---|---|---|---|---|---|---|
| Beta | Excess return | -14.55 (-4.51) |
-14.53 (-3.70) |
-12.70 (-2.26) |
-13.92 (-3.50) |
1.85 (0.64) |
| Beta | FFC alpha | -12.93 (-3.44) |
-16.56 (-4.70) |
-11.32 (-1.55) |
-13.60 (-3.05) |
1.62 (0.40) |
| Book-to-market | Excess return | -8.04 (-1.97) |
-12.99 (-3.42) |
-18.37 (-5.42) |
-13.13 (-3.67) |
-10.33 (-5.62) |
| Book-to-market | FFC alpha | -5.95 (-1.59) |
-11.12 (-2.63) |
-22.60 (-7.96) |
-13.23 (-4.07) |
-16.65 (-6.14) |
Then show how returns vary across market-cap portfolios after averaging across the control groups.
Code
def show_average_portfolios(results, label):
"""Display fits to target returns averaged across control portfolios."""
rows = [
[
variable_labels[variable],
statistic,
*[
format_fit(fits[group, model]["Avg"], "Intercept")
for group in range(1, 6)
],
]
for variable, fits in results.items()
for model, statistic in [
("Excess return", "Excess return"), ("FFC", "FFC alpha"),
]
]
pl.DataFrame(
rows,
schema=[label, "Statistic", "1", "2", "3", "4", "4–1"],
orient="row",
).eap.show_table()
show_average_portfolios(cap_controls, "Control")| Control | Statistic | 1 | 2 | 3 | 4 | 4–1 |
|---|---|---|---|---|---|---|
| Beta | Excess return | 21.94 (4.95) |
12.00 (4.16) |
9.25 (4.52) |
8.02 (4.74) |
-13.92 (-3.50) |
| Beta | FFC alpha | 13.38 (3.17) |
0.74 (0.50) |
-0.29 (-0.27) |
-0.22 (-0.27) |
-13.60 (-3.05) |
| Book-to-market | Excess return | 22.06 (5.49) |
11.68 (4.29) |
9.31 (4.99) |
8.93 (5.55) |
-13.13 (-3.67) |
| Book-to-market | FFC alpha | 14.02 (4.20) |
1.46 (0.93) |
0.47 (0.74) |
0.79 (0.91) |
-13.23 (-4.07) |
Another comparison holds the control variable fixed and changes the characteristic of interest. Here beta is the control in both sorts, and I compare the results for market capitalization and book-to-market.
independent_beta_bm, _, _ = bivariate_sort("Beta", "BM")
beta_bm_fits = grid_fits(bivariate_returns(independent_beta_bm))
beta_controls = {"MktCap": independent_fits, "BM": beta_bm_fits}Code
show_spreads(beta_controls, "Sort variable")| Sort variable | Statistic | 1 | 2 | 3 | Average | 3–1 |
|---|---|---|---|---|---|---|
| Market cap | Excess return | -14.55 (-4.51) |
-14.53 (-3.70) |
-12.70 (-2.26) |
-13.92 (-3.50) |
1.85 (0.64) |
| Market cap | FFC alpha | -12.93 (-3.44) |
-16.56 (-4.70) |
-11.32 (-1.55) |
-13.60 (-3.05) |
1.62 (0.40) |
| Book-to-market | Excess return | 9.93 (3.27) |
10.62 (4.27) |
12.09 (4.35) |
10.88 (5.51) |
2.16 (0.65) |
| Book-to-market | FFC alpha | 8.66 (2.67) |
9.84 (3.05) |
7.19 (2.37) |
8.56 (3.47) |
-1.47 (-0.36) |
Code
show_average_portfolios(beta_controls, "Sort variable")| Sort variable | Statistic | 1 | 2 | 3 | 4 | 4–1 |
|---|---|---|---|---|---|---|
| Market cap | Excess return | 21.94 (4.95) |
12.00 (4.16) |
9.25 (4.52) |
8.02 (4.74) |
-13.92 (-3.50) |
| Market cap | FFC alpha | 13.38 (3.17) |
0.74 (0.50) |
-0.29 (-0.27) |
-0.22 (-0.27) |
-13.60 (-3.05) |
| Book-to-market | Excess return | 8.95 (3.52) |
12.69 (5.79) |
12.90 (5.27) |
19.83 (6.76) |
10.88 (5.51) |
| Book-to-market | FFC alpha | 1.43 (0.77) |
4.28 (3.22) |
4.15 (1.96) |
9.99 (4.84) |
8.56 (3.47) |
5.3 Bivariate Dependent-Sort Analysis
5.3.1 Breakpoints
Start with the same beta groups. For each year and each beta group, calculate the market-cap quartiles within the group. If \(P^{(1)}_{j,t}\) is the set of stocks in beta group \(j\), its market-cap breakpoint \(k\) is
\[ B_{2j,k,t}=\operatorname{Pctl}_{p_{2k}}(\{X_{2i,t}:i\in P^{(1)}_{j,t}\}). \tag{5.20}\]
dependent, beta_cutoffs, conditional_cutoffs = bivariate_sort(
"Beta", "MktCap", dependent=True,
)Code
(
conditional_cutoffs
.join(beta_cutoffs, on="year", validate="m:1")
.sort("year", "control")
.select("year", "control", "30%", "70%", "25%", "50%", "75%")
.rename({
"year": "Year",
"control": "Beta group",
"30%": "Beta 30%",
"70%": "Beta 70%",
"25%": "Market cap 25%",
"50%": "Market cap 50%",
"75%": "Market cap 75%",
})
.eap.show_table()
)| Year | Beta group | Beta 30% | Beta 70% | Market cap 25% | Market cap 50% | Market cap 75% |
|---|---|---|---|---|---|---|
| 1988 | 1 | 0.18 | 0.66 | 4.57 | 12.38 | 35.56 |
| 1988 | 2 | 0.18 | 0.66 | 12.56 | 39.83 | 143.79 |
| 1988 | 3 | 0.18 | 0.66 | 25.18 | 126.48 | 795.60 |
| 1989 | 1 | 0.17 | 0.70 | 4.30 | 12.05 | 33.99 |
| 1989 | 2 | 0.17 | 0.70 | 14.05 | 46.15 | 182.93 |
| 1989 | 3 | 0.17 | 0.70 | 26.62 | 133.92 | 927.77 |
| 1990 | 1 | 0.23 | 0.86 | 2.74 | 8.39 | 24.47 |
| 1990 | 2 | 0.23 | 0.86 | 8.62 | 30.82 | 149.72 |
| 1990 | 3 | 0.23 | 0.86 | 21.80 | 99.65 | 582.18 |
| 1991 | 1 | 0.24 | 0.85 | 3.76 | 10.67 | 31.63 |
| 1991 | 2 | 0.24 | 0.85 | 14.25 | 55.32 | 242.06 |
| 1991 | 3 | 0.24 | 0.85 | 38.96 | 169.83 | 904.91 |
| 1992 | 1 | 0.26 | 0.97 | 8.14 | 22.05 | 68.32 |
| 1992 | 2 | 0.26 | 0.97 | 23.03 | 79.50 | 384.02 |
| 1992 | 3 | 0.26 | 0.97 | 38.15 | 140.75 | 679.20 |
| 1993 | 1 | 0.29 | 0.92 | 10.95 | 28.77 | 78.93 |
| 1993 | 2 | 0.29 | 0.92 | 34.24 | 103.22 | 479.68 |
| 1993 | 3 | 0.29 | 0.92 | 42.97 | 180.90 | 788.81 |
| 1994 | 1 | 0.36 | 0.97 | 11.60 | 26.86 | 76.35 |
| 1994 | 2 | 0.36 | 0.97 | 30.29 | 105.06 | 439.81 |
| 1994 | 3 | 0.36 | 0.97 | 35.30 | 144.17 | 695.14 |
| 1995 | 1 | 0.27 | 0.90 | 13.58 | 34.46 | 105.73 |
| 1995 | 2 | 0.27 | 0.90 | 41.60 | 145.20 | 611.37 |
| 1995 | 3 | 0.27 | 0.90 | 38.51 | 152.62 | 739.00 |
| 1996 | 1 | 0.32 | 0.90 | 15.00 | 41.68 | 120.22 |
| 1996 | 2 | 0.32 | 0.90 | 40.73 | 163.17 | 693.78 |
| 1996 | 3 | 0.32 | 0.90 | 49.79 | 177.91 | 769.25 |
| 1997 | 1 | 0.26 | 0.72 | 15.50 | 44.13 | 116.39 |
| 1997 | 2 | 0.26 | 0.72 | 42.58 | 155.84 | 603.10 |
| 1997 | 3 | 0.26 | 0.72 | 80.74 | 346.73 | 1527.99 |
| 1998 | 1 | 0.41 | 0.94 | 14.04 | 38.51 | 109.92 |
| 1998 | 2 | 0.41 | 0.94 | 37.38 | 126.92 | 568.94 |
| 1998 | 3 | 0.41 | 0.94 | 73.88 | 323.09 | 1174.79 |
| 1999 | 1 | 0.15 | 0.53 | 17.39 | 43.43 | 109.88 |
| 1999 | 2 | 0.15 | 0.53 | 47.97 | 165.22 | 625.87 |
| 1999 | 3 | 0.15 | 0.53 | 95.04 | 477.36 | 2278.61 |
| 2000 | 1 | 0.26 | 0.85 | 15.71 | 42.52 | 117.47 |
| 2000 | 2 | 0.26 | 0.85 | 29.90 | 204.28 | 918.49 |
| 2000 | 3 | 0.26 | 0.85 | 39.64 | 192.62 | 904.09 |
| 2001 | 1 | 0.31 | 0.95 | 16.71 | 44.56 | 113.05 |
| 2001 | 2 | 0.31 | 0.95 | 46.07 | 233.31 | 886.29 |
| 2001 | 3 | 0.31 | 0.95 | 91.00 | 350.97 | 1162.14 |
| 2002 | 1 | 0.33 | 0.89 | 12.81 | 33.30 | 69.24 |
| 2002 | 2 | 0.33 | 0.89 | 56.25 | 233.43 | 850.35 |
| 2002 | 3 | 0.33 | 0.89 | 140.67 | 414.71 | 1454.93 |
| 2003 | 1 | 0.38 | 0.97 | 26.39 | 57.59 | 110.13 |
| 2003 | 2 | 0.38 | 0.97 | 151.58 | 416.73 | 1481.91 |
| 2003 | 3 | 0.38 | 0.97 | 302.73 | 714.14 | 2089.29 |
| 2004 | 1 | 0.63 | 1.36 | 34.43 | 75.45 | 150.96 |
| 2004 | 2 | 0.63 | 1.36 | 203.75 | 704.38 | 2531.88 |
| 2004 | 3 | 0.63 | 1.36 | 251.06 | 562.55 | 1214.40 |
| 2005 | 1 | 0.60 | 1.30 | 34.59 | 72.35 | 135.52 |
| 2005 | 2 | 0.60 | 1.30 | 211.76 | 748.77 | 3271.05 |
| 2005 | 3 | 0.60 | 1.30 | 342.52 | 679.24 | 1414.81 |
| 2006 | 1 | 0.61 | 1.40 | 37.82 | 82.26 | 160.52 |
| 2006 | 2 | 0.61 | 1.40 | 226.82 | 781.56 | 2906.04 |
| 2006 | 3 | 0.61 | 1.40 | 381.78 | 736.53 | 1590.07 |
| 2007 | 1 | 0.56 | 1.18 | 33.16 | 67.62 | 126.87 |
| 2007 | 2 | 0.56 | 1.18 | 210.37 | 855.87 | 3295.33 |
| 2007 | 3 | 0.56 | 1.18 | 317.21 | 607.85 | 1477.17 |
| 2008 | 1 | 0.57 | 1.14 | 12.30 | 30.69 | 63.28 |
| 2008 | 2 | 0.57 | 1.14 | 136.72 | 477.26 | 1610.08 |
| 2008 | 3 | 0.57 | 1.14 | 137.94 | 356.81 | 1124.92 |
| 2009 | 1 | 0.65 | 1.45 | 22.47 | 54.22 | 148.54 |
| 2009 | 2 | 0.65 | 1.45 | 180.54 | 635.26 | 2222.24 |
| 2009 | 3 | 0.65 | 1.45 | 186.22 | 428.88 | 1311.27 |
| 2010 | 1 | 0.76 | 1.33 | 27.01 | 61.05 | 259.51 |
| 2010 | 2 | 0.76 | 1.33 | 222.37 | 726.95 | 2494.72 |
| 2010 | 3 | 0.76 | 1.33 | 262.33 | 606.15 | 1778.21 |
| 2011 | 1 | 0.82 | 1.39 | 22.28 | 49.40 | 122.79 |
| 2011 | 2 | 0.82 | 1.39 | 246.95 | 894.69 | 3050.58 |
| 2011 | 3 | 0.82 | 1.39 | 215.12 | 512.98 | 1269.05 |
| 2012 | 1 | 0.76 | 1.32 | 28.70 | 64.87 | 500.39 |
| 2012 | 2 | 0.76 | 1.32 | 255.85 | 803.41 | 2783.69 |
| 2012 | 3 | 0.76 | 1.32 | 247.85 | 677.93 | 2152.23 |
5.3.2 Portfolio Formation
The portfolios now use those group-specific market-cap breakpoints.
\[ P_{j,k,t}= \{i:B_{1,j-1,t}\le X_{1i,t}\le B_{1j,t}\} \cap \{i:B_{2j,k-1,t}\le X_{2i,t}\le B_{2j,k,t}\}. \tag{5.21}\]
BEM’s printed equation (5.21) leaves the upper endpoint open. The discussion of Table 5.21 assigns a stock on a breakpoint to both adjacent portfolios, so I use inclusive endpoints here as well.
Code
dependent_counts = dependent.group_by("year", "control", "target").len()
control_grid(dependent_counts, "len").eap.show_grid("Beta", "Market cap")| Year | Portfolio | Beta portfolios | ||
|---|---|---|---|---|
| 1 | 2 | 3 | ||
| 1988 | Market cap 1 | 427 | 569 | 427 |
| Market cap 2 | 426 | 568 | 426 | |
| Market cap 3 | 426 | 568 | 426 | |
| Market cap 4 | 427 | 569 | 427 | |
| 1989 | Market cap 1 | 414 | 552 | 414 |
| Market cap 2 | 414 | 551 | 414 | |
| Market cap 3 | 414 | 551 | 414 | |
| Market cap 4 | 414 | 552 | 414 | |
| 1990 | Market cap 1 | 406 | 541 | 406 |
| Market cap 2 | 405 | 540 | 405 | |
| Market cap 3 | 405 | 540 | 405 | |
| Market cap 4 | 406 | 541 | 406 | |
| 1991 | Market cap 1 | 398 | 530 | 398 |
| Market cap 2 | 398 | 530 | 398 | |
| Market cap 3 | 398 | 530 | 398 | |
| Market cap 4 | 398 | 530 | 398 | |
| 1992 | Market cap 1 | 405 | 539 | 405 |
| Market cap 2 | 405 | 538 | 405 | |
| Market cap 3 | 405 | 538 | 405 | |
| Market cap 4 | 405 | 539 | 405 | |
| 1993 | Market cap 1 | 426 | 567 | 426 |
| Market cap 2 | 425 | 567 | 425 | |
| Market cap 3 | 425 | 567 | 425 | |
| Market cap 4 | 426 | 567 | 426 | |
| 1994 | Market cap 1 | 462 | 615 | 462 |
| Market cap 2 | 462 | 614 | 462 | |
| Market cap 3 | 462 | 614 | 462 | |
| Market cap 4 | 462 | 615 | 462 | |
| 1995 | Market cap 1 | 472 | 629 | 472 |
| Market cap 2 | 472 | 628 | 472 | |
| Market cap 3 | 472 | 628 | 472 | |
| Market cap 4 | 472 | 629 | 472 | |
| 1996 | Market cap 1 | 494 | 659 | 494 |
| Market cap 2 | 494 | 659 | 494 | |
| Market cap 3 | 494 | 659 | 494 | |
| Market cap 4 | 494 | 659 | 494 | |
| 1997 | Market cap 1 | 515 | 687 | 515 |
| Market cap 2 | 515 | 687 | 515 | |
| Market cap 3 | 515 | 687 | 515 | |
| Market cap 4 | 515 | 687 | 515 | |
| 1998 | Market cap 1 | 496 | 661 | 496 |
| Market cap 2 | 495 | 661 | 495 | |
| Market cap 3 | 495 | 661 | 495 | |
| Market cap 4 | 496 | 661 | 496 | |
| 1999 | Market cap 1 | 457 | 609 | 457 |
| Market cap 2 | 457 | 609 | 457 | |
| Market cap 3 | 457 | 609 | 457 | |
| Market cap 4 | 457 | 609 | 457 | |
| 2000 | Market cap 1 | 442 | 590 | 442 |
| Market cap 2 | 442 | 589 | 442 | |
| Market cap 3 | 442 | 589 | 442 | |
| Market cap 4 | 442 | 590 | 442 | |
| 2001 | Market cap 1 | 413 | 551 | 413 |
| Market cap 2 | 413 | 551 | 413 | |
| Market cap 3 | 413 | 551 | 413 | |
| Market cap 4 | 413 | 551 | 413 | |
| 2002 | Market cap 1 | 382 | 509 | 382 |
| Market cap 2 | 382 | 509 | 382 | |
| Market cap 3 | 382 | 509 | 382 | |
| Market cap 4 | 382 | 509 | 382 | |
| 2003 | Market cap 1 | 355 | 474 | 355 |
| Market cap 2 | 355 | 474 | 355 | |
| Market cap 3 | 355 | 474 | 355 | |
| Market cap 4 | 355 | 474 | 355 | |
| 2004 | Market cap 1 | 343 | 457 | 343 |
| Market cap 2 | 343 | 456 | 343 | |
| Market cap 3 | 343 | 456 | 343 | |
| Market cap 4 | 343 | 457 | 343 | |
| 2005 | Market cap 1 | 337 | 450 | 337 |
| Market cap 2 | 337 | 450 | 337 | |
| Market cap 3 | 337 | 450 | 337 | |
| Market cap 4 | 337 | 450 | 337 | |
| 2006 | Market cap 1 | 334 | 445 | 334 |
| Market cap 2 | 334 | 445 | 334 | |
| Market cap 3 | 334 | 445 | 334 | |
| Market cap 4 | 334 | 445 | 334 | |
| 2007 | Market cap 1 | 325 | 433 | 325 |
| Market cap 2 | 324 | 433 | 324 | |
| Market cap 3 | 324 | 433 | 324 | |
| Market cap 4 | 325 | 433 | 325 | |
| 2008 | Market cap 1 | 320 | 426 | 320 |
| Market cap 2 | 320 | 426 | 320 | |
| Market cap 3 | 320 | 426 | 320 | |
| Market cap 4 | 320 | 426 | 320 | |
| 2009 | Market cap 1 | 298 | 397 | 298 |
| Market cap 2 | 298 | 396 | 298 | |
| Market cap 3 | 298 | 396 | 298 | |
| Market cap 4 | 298 | 397 | 298 | |
| 2010 | Market cap 1 | 285 | 380 | 285 |
| Market cap 2 | 284 | 379 | 284 | |
| Market cap 3 | 284 | 379 | 284 | |
| Market cap 4 | 285 | 380 | 285 | |
| 2011 | Market cap 1 | 276 | 367 | 276 |
| Market cap 2 | 276 | 367 | 276 | |
| Market cap 3 | 276 | 367 | 276 | |
| Market cap 4 | 276 | 367 | 276 | |
| 2012 | Market cap 1 | 265 | 353 | 265 |
| Market cap 2 | 265 | 353 | 265 | |
| Market cap 3 | 265 | 353 | 265 | |
| Market cap 4 | 265 | 353 | 265 | |
Conditional quartiles tend to distribute stocks evenly within each beta group. In the independent sort, the largest stocks are much more common in the high-beta group than in the low-beta group. Figure 5.4 compares average stock counts across the two sorts.
Code
sort_methods = ["Independent", "Dependent"]
average_counts = pl.concat(
counts
.group_by("control", "target")
.agg(count=pl.col("len").mean())
.with_columns(method=pl.lit(method, dtype=pl.Enum(sort_methods)))
for method, counts in zip(
sort_methods, [independent_counts, dependent_counts], strict=True,
)
)
max_count = average_counts["count"].max()
(
average_counts
.with_columns(
label=pl.col("count").round().cast(pl.Int64),
label_color=(
pl.when(pl.col("count") > 0.58 * max_count)
.then(pl.lit("white"))
.otherwise(pl.lit("#172b4d"))
),
)
.ggplot(aes(x="control", y="target", fill="count"))
.geom_tile()
.geom_text(aes(label="label", color="label_color"))
.facet_wrap("method", nrow=1)
.scale_fill_gradient(
low="#f7fbff", high="#08306b", limits=(0, max_count), guide=None,
)
.scale_color_identity()
.scale_x_continuous(breaks=range(1, 4), expand=(0, 0))
.scale_y_reverse(breaks=range(1, 5), expand=(0, 0))
.labs(x="Beta group", y="Market-cap quartile")
.theme_minimal()
.add_theme(figure_size=(8, 4), panel_grid=element_blank())
)
5.3.3 Average Portfolio Values
Calculate returns and high-minus-low spreads within each beta group, then average the three groups.
dependent_returns = bivariate_returns(dependent, dependent=True)Code
(
dependent_returns
.drop("Diff")
.eap.show_grid("Beta", "Market cap", holding=True)
)| Formation year | Holding year | Portfolio | Beta portfolios | |||
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | Average | |||
| 1988 | 1989 | Market cap 1 | −3.12 | −0.35 | −3.29 | −2.25 |
| Market cap 2 | 3.23 | −1.59 | 1.65 | 1.09 | ||
| Market cap 3 | −0.81 | 3.88 | 12.05 | 5.04 | ||
| Market cap 4 | 5.82 | 13.73 | 19.98 | 13.18 | ||
| Market cap 4–1 | 8.94 | 14.08 | 23.27 | 15.43 | ||
| 1989 | 1990 | Market cap 1 | −20.67 | −32.92 | −26.74 | −26.78 |
| Market cap 2 | −34.96 | −37.98 | −33.94 | −35.63 | ||
| Market cap 3 | −31.55 | −30.87 | −25.63 | −29.35 | ||
| Market cap 4 | −27.73 | −19.89 | −15.97 | −21.20 | ||
| Market cap 4–1 | −7.06 | 13.03 | 10.77 | 5.58 | ||
| 1990 | 1991 | Market cap 1 | 75.91 | 57.15 | 86.61 | 73.22 |
| Market cap 2 | 32.58 | 46.59 | 63.62 | 47.60 | ||
| Market cap 3 | 35.93 | 42.19 | 52.22 | 43.45 | ||
| Market cap 4 | 21.06 | 28.72 | 39.84 | 29.87 | ||
| Market cap 4–1 | −54.84 | −28.43 | −46.77 | −43.35 | ||
| 1991 | 1992 | Market cap 1 | 78.25 | 38.15 | 37.76 | 51.39 |
| Market cap 2 | 30.70 | 23.24 | 10.63 | 21.52 | ||
| Market cap 3 | 24.19 | 18.52 | 11.05 | 17.92 | ||
| Market cap 4 | 25.15 | 14.28 | 8.67 | 16.04 | ||
| Market cap 4–1 | −53.10 | −23.87 | −29.09 | −35.35 | ||
| 1992 | 1993 | Market cap 1 | 45.75 | 41.93 | 27.04 | 38.24 |
| Market cap 2 | 31.36 | 23.63 | 7.33 | 20.78 | ||
| Market cap 3 | 20.48 | 15.05 | 9.89 | 15.14 | ||
| Market cap 4 | 18.14 | 11.34 | 12.10 | 13.86 | ||
| Market cap 4–1 | −27.61 | −30.59 | −14.95 | −24.38 | ||
| 1993 | 1994 | Market cap 1 | 1.68 | −1.66 | −7.88 | −2.62 |
| Market cap 2 | −6.62 | −4.55 | −10.07 | −7.08 | ||
| Market cap 3 | −9.39 | −4.55 | −7.66 | −7.20 | ||
| Market cap 4 | −5.35 | −6.09 | −5.65 | −5.70 | ||
| Market cap 4–1 | −7.03 | −4.44 | 2.23 | −3.08 | ||
| 1994 | 1995 | Market cap 1 | 28.23 | 27.47 | 30.06 | 28.59 |
| Market cap 2 | 27.43 | 36.02 | 33.72 | 32.39 | ||
| Market cap 3 | 24.81 | 24.12 | 22.12 | 23.68 | ||
| Market cap 4 | 21.72 | 25.31 | 27.29 | 24.78 | ||
| Market cap 4–1 | −6.51 | −2.16 | −2.77 | −3.81 | ||
| 1995 | 1996 | Market cap 1 | 33.98 | 13.59 | 14.46 | 20.68 |
| Market cap 2 | 13.19 | 13.09 | 10.21 | 12.17 | ||
| Market cap 3 | 11.21 | 18.17 | 2.21 | 10.53 | ||
| Market cap 4 | 19.89 | 14.64 | 12.97 | 15.83 | ||
| Market cap 4–1 | −14.09 | 1.04 | −1.48 | −4.84 | ||
| 1996 | 1997 | Market cap 1 | 26.79 | 16.53 | 3.11 | 15.47 |
| Market cap 2 | 31.47 | 21.67 | −2.23 | 16.97 | ||
| Market cap 3 | 34.10 | 25.90 | 1.50 | 20.50 | ||
| Market cap 4 | 30.37 | 22.86 | 17.31 | 23.51 | ||
| Market cap 4–1 | 3.58 | 6.33 | 14.21 | 8.04 | ||
| 1997 | 1998 | Market cap 1 | −2.22 | −8.19 | −16.55 | −8.99 |
| Market cap 2 | −12.88 | −13.88 | −6.88 | −11.22 | ||
| Market cap 3 | −11.78 | −6.87 | −10.65 | −9.76 | ||
| Market cap 4 | −4.85 | −2.80 | 14.63 | 2.33 | ||
| Market cap 4–1 | −2.63 | 5.39 | 31.18 | 11.31 | ||
| 1998 | 1999 | Market cap 1 | 43.58 | 59.35 | 93.72 | 65.55 |
| Market cap 2 | 18.90 | 44.50 | 70.87 | 44.76 | ||
| Market cap 3 | 4.97 | 11.42 | 52.96 | 23.12 | ||
| Market cap 4 | −10.60 | −4.71 | 37.73 | 7.47 | ||
| Market cap 4–1 | −54.18 | −64.06 | −55.99 | −58.08 | ||
| 1999 | 2000 | Market cap 1 | −4.21 | −13.40 | −31.15 | −16.25 |
| Market cap 2 | −7.70 | −9.10 | −13.83 | −10.21 | ||
| Market cap 3 | −10.77 | 5.21 | −10.31 | −5.29 | ||
| Market cap 4 | −0.04 | 13.59 | −8.62 | 1.64 | ||
| Market cap 4–1 | 4.17 | 27.00 | 22.53 | 17.90 | ||
| 2000 | 2001 | Market cap 1 | 42.59 | 49.51 | 17.07 | 36.39 |
| Market cap 2 | 35.82 | 45.49 | −3.62 | 25.90 | ||
| Market cap 3 | 31.80 | 13.07 | 3.36 | 16.08 | ||
| Market cap 4 | 15.16 | 2.63 | −23.99 | −2.07 | ||
| Market cap 4–1 | −27.43 | −46.88 | −41.06 | −38.46 | ||
| 2001 | 2002 | Market cap 1 | 7.99 | −6.87 | −34.32 | −11.07 |
| Market cap 2 | 7.58 | −9.08 | −44.29 | −15.26 | ||
| Market cap 3 | 16.96 | −9.66 | −42.34 | −11.68 | ||
| Market cap 4 | −0.43 | −8.74 | −37.27 | −15.48 | ||
| Market cap 4–1 | −8.42 | −1.87 | −2.95 | −4.42 | ||
| 2002 | 2003 | Market cap 1 | 125.94 | 125.16 | 130.19 | 127.10 |
| Market cap 2 | 85.22 | 77.38 | 76.58 | 79.73 | ||
| Market cap 3 | 61.36 | 38.74 | 56.79 | 52.29 | ||
| Market cap 4 | 44.95 | 30.37 | 44.05 | 39.79 | ||
| Market cap 4–1 | −80.99 | −94.80 | −86.13 | −87.31 | ||
| 2003 | 2004 | Market cap 1 | 35.19 | 21.62 | 10.52 | 22.44 |
| Market cap 2 | 25.11 | 17.03 | 7.77 | 16.64 | ||
| Market cap 3 | 22.11 | 24.55 | 8.65 | 18.44 | ||
| Market cap 4 | 19.99 | 19.25 | 10.48 | 16.57 | ||
| Market cap 4–1 | −15.19 | −2.37 | −0.05 | −5.87 | ||
| 2004 | 2005 | Market cap 1 | 3.31 | 0.21 | −15.76 | −4.08 |
| Market cap 2 | 1.85 | 1.19 | −1.03 | 0.67 | ||
| Market cap 3 | 4.96 | 5.81 | 0.12 | 3.63 | ||
| Market cap 4 | 5.27 | 8.38 | 3.67 | 5.77 | ||
| Market cap 4–1 | 1.96 | 8.17 | 19.43 | 9.85 | ||
| 2005 | 2006 | Market cap 1 | 16.48 | 14.61 | 8.40 | 13.16 |
| Market cap 2 | 11.27 | 8.34 | 13.02 | 10.88 | ||
| Market cap 3 | 7.29 | 12.02 | 9.80 | 9.70 | ||
| Market cap 4 | 16.98 | 8.79 | 8.21 | 11.33 | ||
| Market cap 4–1 | 0.50 | −5.82 | −0.19 | −1.84 | ||
| 2006 | 2007 | Market cap 1 | −11.56 | −11.32 | −13.00 | −11.96 |
| Market cap 2 | −12.42 | −13.24 | −9.95 | −11.87 | ||
| Market cap 3 | −15.31 | −4.31 | −2.81 | −7.48 | ||
| Market cap 4 | −5.14 | −0.32 | 8.37 | 0.97 | ||
| Market cap 4–1 | 6.42 | 10.99 | 21.38 | 12.93 | ||
| 2007 | 2008 | Market cap 1 | −45.44 | −51.18 | −46.78 | −47.80 |
| Market cap 2 | −46.85 | −37.34 | −37.28 | −40.49 | ||
| Market cap 3 | −45.81 | −33.32 | −38.42 | −39.18 | ||
| Market cap 4 | −34.74 | −35.01 | −50.37 | −40.04 | ||
| Market cap 4–1 | 10.70 | 16.17 | −3.59 | 7.76 | ||
| 2008 | 2009 | Market cap 1 | 145.35 | 114.39 | 113.31 | 124.35 |
| Market cap 2 | 65.88 | 39.89 | 52.53 | 52.77 | ||
| Market cap 3 | 37.66 | 33.54 | 48.99 | 40.06 | ||
| Market cap 4 | 17.99 | 31.60 | 48.99 | 32.86 | ||
| Market cap 4–1 | −127.36 | −82.79 | −64.32 | −91.49 | ||
| 2009 | 2010 | Market cap 1 | 21.29 | 31.24 | 38.41 | 30.31 |
| Market cap 2 | 21.85 | 24.79 | 31.64 | 26.09 | ||
| Market cap 3 | 20.63 | 25.56 | 36.00 | 27.40 | ||
| Market cap 4 | 16.64 | 21.92 | 28.80 | 22.45 | ||
| Market cap 4–1 | −4.65 | −9.32 | −9.61 | −7.86 | ||
| 2010 | 2011 | Market cap 1 | −10.19 | −14.21 | −19.39 | −14.60 |
| Market cap 2 | −7.70 | −4.19 | −12.25 | −8.04 | ||
| Market cap 3 | −6.14 | 0.18 | −7.82 | −4.59 | ||
| Market cap 4 | 8.32 | 2.33 | −10.63 | 0.01 | ||
| Market cap 4–1 | 18.52 | 16.54 | 8.76 | 14.60 | ||
| 2011 | 2012 | Market cap 1 | 32.84 | 18.56 | 14.54 | 21.98 |
| Market cap 2 | 23.76 | 13.79 | 19.46 | 19.00 | ||
| Market cap 3 | 29.26 | 17.49 | 20.10 | 22.28 | ||
| Market cap 4 | 13.38 | 19.07 | 18.24 | 16.90 | ||
| Market cap 4–1 | −19.45 | 0.51 | 3.70 | −5.08 | ||
5.3.4 Summarizing the Results
dependent_fits = grid_fits(dependent_returns)Code
show_grid_fits(dependent_fits, dependent=True)| Portfolio | Statistic | Beta 1 | Beta 2 | Beta 3 | Beta Avg |
|---|---|---|---|---|---|
| Market cap 1 | Excess return | 27.82 (6.63) |
20.39 (5.07) |
17.10 (4.57) |
21.77 (5.80) |
| Market cap 1 | FFC alpha | 22.05 (6.50) |
12.03 (4.33) |
7.03 (1.84) |
13.70 (4.46) |
| Market cap 2 | Excess return | 14.09 (4.20) |
12.74 (3.54) |
9.32 (3.76) |
12.05 (4.33) |
| Market cap 2 | FFC alpha | 4.33 (2.19) |
0.70 (0.26) |
-2.00 (-1.26) |
1.01 (0.85) |
| Market cap 3 | Excess return | 10.67 (3.38) |
10.24 (5.29) |
8.42 (3.68) |
9.78 (4.96) |
| Market cap 3 | FFC alpha | 0.18 (0.06) |
1.11 (1.60) |
-0.65 (-0.39) |
0.22 (0.23) |
| Market cap 4 | Excess return | 8.83 (4.04) |
8.80 (5.73) |
8.70 (3.10) |
8.78 (4.99) |
| Market cap 4 | FFC alpha | 0.14 (0.08) |
1.53 (1.83) |
-0.43 (-0.26) |
0.41 (0.93) |
| Market cap 4–1 | Excess return | -18.99 (-6.05) |
-11.59 (-3.20) |
-8.40 (-2.57) |
-12.99 (-4.17) |
| Market cap 4–1 | FFC alpha | -21.91 (-5.18) |
-10.50 (-3.55) |
-7.45 (-2.60) |
-13.29 (-4.38) |
5.3.5 Interpreting the Results
The high-minus-low differences across beta groups in the spread tables compare market-cap spreads. They show whether the size effect varies with beta.
5.3.6 Presenting the Results
Code
columns = [*control_ports, "Avg"]
rows = [
[
target_label("MktCap", group),
*[
format(
dependent_fits[group, "Excess return"][column]
.params["Intercept"],
".2f",
)
for column in columns
],
]
for group in range(1, 5)
]
rows += [
[
label,
*[
format_fit(dependent_fits[5, model][column], "Intercept")
for column in columns
],
]
for label, model in [
("Market cap 4–1", "Excess return"), ("FFC alpha", "FFC"),
]
]
pl.DataFrame(
rows,
schema=["Portfolio", "Beta 1", "Beta 2", "Beta 3", "Beta average"],
orient="row",
).eap.show_table()| Portfolio | Beta 1 | Beta 2 | Beta 3 | Beta average |
|---|---|---|---|---|
| Market cap 1 | 27.82 | 20.39 | 17.10 | 21.77 |
| Market cap 2 | 14.09 | 12.74 | 9.32 | 12.05 |
| Market cap 3 | 10.67 | 10.24 | 8.42 | 9.78 |
| Market cap 4 | 8.83 | 8.80 | 8.70 | 8.78 |
| Market cap 4–1 | -18.99 (-6.05) |
-11.59 (-3.20) |
-8.40 (-2.57) |
-12.99 (-4.17) |
| FFC alpha | -21.91 (-5.18) |
-10.50 (-3.55) |
-7.45 (-2.60) |
-13.29 (-4.38) |
The same dependent sort can use book-to-market as the first variable or the second variable. The following tables keep the sort order explicit.
dependent_bm_cap, _, _ = bivariate_sort("BM", "MktCap", dependent=True)
dependent_beta_bm, _, _ = bivariate_sort("Beta", "BM", dependent=True)
dependent_cap_controls = {
"Beta": dependent_fits,
"BM": grid_fits(bivariate_returns(dependent_bm_cap, dependent=True)),
}
dependent_beta_controls = {
"MktCap": dependent_fits,
"BM": grid_fits(bivariate_returns(dependent_beta_bm, dependent=True)),
}Code
show_spreads(dependent_cap_controls, "Control")| Control | Statistic | 1 | 2 | 3 | Average | 3–1 |
|---|---|---|---|---|---|---|
| Beta | Excess return | -18.99 (-6.05) |
-11.59 (-3.20) |
-8.40 (-2.57) |
-12.99 (-4.17) |
10.59 (5.69) |
| Beta | FFC alpha | -21.91 (-5.18) |
-10.50 (-3.55) |
-7.45 (-2.60) |
-13.29 (-4.38) |
14.46 (5.85) |
| Book-to-market | Excess return | -7.05 (-1.85) |
-10.24 (-3.09) |
-22.25 (-5.96) |
-13.18 (-3.90) |
-15.20 (-6.65) |
| Book-to-market | FFC alpha | -3.94 (-1.08) |
-9.14 (-2.48) |
-28.79 (-6.98) |
-13.95 (-4.83) |
-24.85 (-6.13) |
Code
show_average_portfolios(dependent_cap_controls, "Control")| Control | Statistic | 1 | 2 | 3 | 4 | 4–1 |
|---|---|---|---|---|---|---|
| Beta | Excess return | 21.77 (5.80) |
12.05 (4.33) |
9.78 (4.96) |
8.78 (4.99) |
-12.99 (-4.17) |
| Beta | FFC alpha | 13.70 (4.46) |
1.01 (0.85) |
0.22 (0.23) |
0.41 (0.93) |
-13.29 (-4.38) |
| Book-to-market | Excess return | 22.17 (5.72) |
12.61 (4.68) |
10.09 (5.20) |
8.99 (5.61) |
-13.18 (-3.90) |
| Book-to-market | FFC alpha | 14.76 (4.67) |
3.21 (2.02) |
0.53 (0.92) |
0.81 (1.41) |
-13.95 (-4.83) |
Code
show_spreads(dependent_beta_controls, "Sort variable")| Sort variable | Statistic | 1 | 2 | 3 | Average | 3–1 |
|---|---|---|---|---|---|---|
| Market cap | Excess return | -18.99 (-6.05) |
-11.59 (-3.20) |
-8.40 (-2.57) |
-12.99 (-4.17) |
10.59 (5.69) |
| Market cap | FFC alpha | -21.91 (-5.18) |
-10.50 (-3.55) |
-7.45 (-2.60) |
-13.29 (-4.38) |
14.46 (5.85) |
| Book-to-market | Excess return | 12.13 (4.45) |
9.22 (3.56) |
10.01 (3.98) |
10.45 (5.38) |
-2.11 (-0.82) |
| Book-to-market | FFC alpha | 12.70 (4.43) |
7.26 (2.23) |
7.38 (2.07) |
9.11 (3.37) |
-5.32 (-1.36) |
In Table 5.27, the four-factor alpha of the book-to-market spread is smaller in the highest-beta group than in the lowest-beta group.4
Code
show_average_portfolios(dependent_beta_controls, "Sort variable")| Sort variable | Statistic | 1 | 2 | 3 | 4 | 4–1 |
|---|---|---|---|---|---|---|
| Market cap | Excess return | 21.77 (5.80) |
12.05 (4.33) |
9.78 (4.96) |
8.78 (4.99) |
-12.99 (-4.17) |
| Market cap | FFC alpha | 13.70 (4.46) |
1.01 (0.85) |
0.22 (0.23) |
0.41 (0.93) |
-13.29 (-4.38) |
| Book-to-market | Excess return | 8.71 (3.59) |
11.78 (5.60) |
13.84 (6.31) |
19.16 (6.58) |
10.45 (5.38) |
| Book-to-market | FFC alpha | 0.98 (0.54) |
3.65 (2.70) |
4.37 (3.57) |
10.09 (5.00) |
9.11 (3.37) |
5.4 Independent Versus Dependent Sort
Average market capitalization makes the difference between the two methods concrete. An independent sort applies the same market-cap cutoffs across beta groups. A dependent sort can classify a stock as large among low-beta stocks even if its capitalization would place it in a lower quartile among high-beta stocks.
def average_capitalization(members):
return (
members
.group_by("year", "control", "target")
.agg(pl.col("MktCap").mean())
.group_by("control", "target")
.agg(pl.col("MktCap").mean())
.pivot(on="control", index="target", values="MktCap")
.sort("target")
.select("target", *control_ports)
)
independent_caps = average_capitalization(independent)
dependent_caps = average_capitalization(dependent)Code
(
independent_caps
.with_columns(pl.col(control_ports).round().cast(pl.Int64))
.eap.show_grid("Beta", "Market cap")
)| Portfolio | Beta portfolios | ||
|---|---|---|---|
| 1 | 2 | 3 | |
| Market cap 1 | 21 | 22 | 25 |
| Market cap 2 | 85 | 110 | 117 |
| Market cap 3 | 421 | 432 | 421 |
| Market cap 4 | 8,779 | 7,424 | 6,993 |
Code
(
dependent_caps
.with_columns(pl.col(control_ports).round().cast(pl.Int64))
.eap.show_grid("Beta", "Market cap")
)| Portfolio | Beta portfolios | ||
|---|---|---|---|
| 1 | 2 | 3 | |
| Market cap 1 | 10 | 44 | 76 |
| Market cap 2 | 29 | 203 | 237 |
| Market cap 3 | 68 | 728 | 688 |
| Market cap 4 | 3,976 | 9,529 | 9,010 |
Figure 5.5 plots the same means on a log scale.
Code
capitalization = pl.concat(
caps
.unpivot(index="target", variable_name="group", value_name="cap")
.with_columns(method=pl.lit(method, dtype=pl.Enum(sort_methods)))
for method, caps in zip(
sort_methods, [independent_caps, dependent_caps], strict=True,
)
)
(
capitalization
.ggplot(aes(x="target", y="cap", color="group"))
.geom_line()
.geom_point(aes(shape="group"))
.facet_wrap("method", nrow=1)
.scale_x_continuous(breaks=range(1, 5))
.scale_y_log10(labels=lambda values: [f"{value:,.0f}" for value in values])
.scale_color_brewer(type="qual", palette="Dark2")
.scale_shape_manual(values=["o", "s", "^"])
.labs(
x="Market-cap quartile",
y="Average market cap ($ millions, log scale)",
color="Beta group",
shape="Beta group",
)
.theme_minimal()
.add_theme(figure_size=(8, 3.7), legend_position="top")
)
5.5 Trivariate-Sort Analysis
A third sort variable can be added by forming another unconditional group or by calculating its breakpoints within the existing intersected groups. With three variables the number of portfolios grows quickly, so check the stock counts before interpreting portfolio spreads.
Using the annual portfolio returns printed in BEM Table 5.3, the June 2014 compounded factors give a spread alpha of \(-5.65\%\) per year, compared with \(-5.66\%\) in BEM Table 5.9. Across all eight alphas, the mean absolute error is \(0.05\) percentage points, compared with \(0.35\) percentage points using the published annual factors from July 2016 for the three factors and December 2024 for momentum.↩︎
The chapter version expects complete sort values and precomputed breakpoints, with cutoff columns named separately from the stock columns. The package version,
eap_pl.assign_portfolio(), is used elsewhere in the book. It can also calculate evenly spaced percentile breakpoints using all stocks or only NYSE stocks, and it gives a null assignment when sort values or breakpoints are missing.↩︎Holding the annual excess returns fixed, the June 2014 daily beta inputs reduce the mean absolute difference from BEM Table 5.3 to 0.12 percentage points across the seven portfolios, compared with 0.19 using the WRDS factors. The mean absolute gap in the 7–1 spread falls from 0.19 to 0.10 percentage points.↩︎
The difference is statistically significant here (\(t=-3.55\)). BEM Table 5.27 reports \(t=-1.46\) for the same comparison.↩︎