# HW #6: Portfolio Sorts and Long-Horizon Return Inference

In anomalies papers, the core empirical workflow is:

1) Choose a **signal** (a number you can compute for each stock today that might predict future returns). Examples of signals might include past returns (momentum), valuation ratios (price to earnings P/E), firm characteristics (market size; dividend yield), trading activity (recent volume or volatilty), etc.
2) Sort stocks into groups based on that signal.
3) Form **portfolios** and track their returns.
4) Compute a **winner-minus-loser** ("long-short") strategy.
5) Summarize the strategy's performance with an average and a t-stat.

This assignment practices that workflow with small, friendly calculations.

## 1) A signal and a sort

A **signal** is a number we compute for each stock at the start of a period. A classic example is **past 12-month return** ("momentum" style), but signals could be many things.

You have 10 stocks with the following signal values:

```{r, message = F}
library(tidyverse)

data <- tibble(
  stock = letters[1:10],
  signal = c(-.08, 0.04, 0.01, 0.12, -0.02, 0.20, 0.06, -0.10, 0.15, 0.09)
  ) # %>%
  # arrange(___) %>%
  # mutate(grp = if_else(___, ___, ___))

data
```

Sort into **2 groups:**

- **Losers** = bottom 5 signal values  
- **Winners** = top 5 signal values  

Use `mutate` to edit the variable definition of `data` to add a new variable `grp` which takes on "winner" or "loser". You may want to arrange first.

## 2) Equal-weight portfolio return

An **equal-weight portfolio** gives each stock the same weight. So if there are 5 stocks, each gets weight \(1/5\). A portfolio return is just the weighted average of its component returns.

Suppose next month the **returns** of the Winner group stocks are given by `returns`. Compute the **equal-weight Winner portfolio return and the equal-weight Loser portfolio return**.

```{r}
data %>%
  mutate(returns = c(.02, .01, .04, -.01, .03,
                     -.02, .00, .01, -.03, .02)) # %>%
  # ___
```

Anomalies papers often report a **long-short portfolio**, which means: $r_{LS} = r_{\text{Winners}} - r_{\text{Losers}}$
This helps cancel out market-wide effects that hit all stocks: if the market as a whole is up 5%, winners might be up 7% and losers might be 4%, which yields a long-short return of 3%. The effect of the market being up is largely cancelled out.

## 3) Holding periods

A **holding period** is how long you keep a portfolio after formation. If you hold for multiple months, your total return compounds. This is different from re-forming the portfolio every month.

Suppose you form a portfolio and then hold it for 3 months. The monthly returns are:

- Month 1: \(0.01\)  
- Month 2: \(-0.02\)  
- Month 3: \(0.03\)

Compute the **3-month buy-and-hold total return**: $(1+r_1)(1+r_2)(1+r_3)-1$.

```{r}

```

## 4) Event-time vs calendar-time

In event-time portfolios, you track performance relative to when the strategy was formed (like "Month 1 after formation," "Month 2 after formation," etc.). In calendar-time portfolios, you create a strategy return series month-by-month (January return, February return, March return, ...). Long-horizon strategies often create **overlapping** portfolios, where multiple formation cohorts are active at the same time.

You form a 2-month holding strategy **every month**:
- You form Cohort 1 in January (holds Jan and Feb)
- You form Cohort 2 in February (holds Feb and Mar)
- You form Cohort 3 in March (holds Mar and Apr)

In **February**, how many cohorts are active at the same time?

## 5) Why overlapping creates dependence

Overlapping portfolios reuse some of the same months of returns. For example, both Cohort 1 and Cohort 2 include February. That means the strategy returns you compute across months are not perfectly independent over time. This matters for standard errors and t-stats.

True or False:
If a strategy uses overlapping holding periods, then the strategy's monthly returns are more likely to be **correlated over time** than if it used non-overlapping periods.

## 6) Measuring abnormal performance

Before we do CAPM, we can still benchmark performance in simple ways.

- **Excess return:** $r - r_f$
- **Market-adjusted return:** $r - r_m$
- **Long-short spread:** winners minus losers (already benchmark-like)

This month:
- Long-short strategy return: $r_{LS} = 0.015$
- Risk-free rate: $r_f = 0.002$  
- Market return: $r_m = 0.010$

Compute:
1) Excess long-short return: \(r_{LS} - r_f\)  
2) Market-adjusted long-short return: \(r_{LS} - r_m\)

## 7) Mean return and a simple t-stat

A strategy's average return is its typical performance. The t-stat compares the average return to its standard error:

$$t = \frac{\bar{r}}{SE(\bar{r})}$$

A large magnitude t-stat means the average return is far from zero relative to uncertainty.

Suppose a strategy has:

- Average monthly return: $\bar{r} = 0.004$ 
- Standard error: $SE(\bar{r}) = 0.0016$

Compute the t-stat.

## 8) Time-series dependence and Newey-West intuition

The usual t-stat formula assumes observations are independent over time. But many finance strategies (especially long-horizon and overlapping ones) have time-series dependence, so the usual standard errors can be too small. Newey-West is a common tool that adjusts standard errors to be more realistic when returns are autocorrelated, without changing the average return.

If you ignore time-series dependence in an overlapping strategy, your t-stat is most likely to look:

**Too big / Too small**

## Download this assignment

Here's a <a href="HW6-portfolio-sorts.qmd" download>link</a> to download this assignment.

## Autograder

Here's a [link to the autograder](graders/hw6-grader.html).
