HW7: Rolling FF3 Alpha / FF3_exp Top-10 Portfolios vs. 0050 (Taiwan, TEJ)

Author

Your Name (Student ID)

Published

November 23, 2026

Code
# load tidyverse LAST so that dplyr's filter()/lag()/first()/last() win over xts/zoo
library(quantmod)             # xts, Delt()
library(PerformanceAnalytics) # return, risk, tracking error, information ratio
library(knitr)
library(DT)
library(tidyverse)            # dplyr, tidyr, ggplot2, readr, stringr, purrr
library(lubridate)
library(scales)

0. How to plug in your TEJ data

  1. Put this .qmd in your project folder and create a sub-folder raw/.
  2. Export three files from TEJ as CSV (or tab-delimited txt), and save them with these names (or change the names in the settings chunk):
File Columns, in this order Notes
raw/tej_monthly.csv stock id, month, adjusted close, market cap (million NTD) Nov 2017 to Dec 2025, all stocks
raw/ff_factors_monthly.csv month, rf, MKT_RF, SMB, HML Nov 2017 to Dec 2025. Extra FF5 columns (RMW, CMA) are ignored. In percent or decimals: detected automatically
raw/etf0050_monthly.csv stock id (0050), month, adjusted close Dec 2020 to Dec 2025
  1. Month can be 202012, 2020/12, 2020-12 or 2020-12-31. A stock id such as 2330 台積電 is cut to 2330.
  2. If raw/ is missing, the file runs on dummy data (with a warning banner) so you can test everything. With write_sim_csv <- TRUE the dummy files are also saved in raw_sim/ so you can see the exact layout.
  3. If the numbers look wrong, check has_header, file_encoding (use "BIG5" for some TEJ files) and the column order.
Code
# ---- files ----
f_stock  <- "raw/tej_monthly.csv"
f_factor <- "raw/ff_factors_monthly.csv"
f_etf    <- "raw/etf0050_monthly.csv"
f_rolling_saved <- "output/rolling_ff3.rds"   # optional: from Assignment 1, task A3

has_header        <- TRUE      # do the raw files have a header row?
file_encoding     <- "UTF-8"   # or "BIG5"
use_saved_rolling <- TRUE      # use output/rolling_ff3.rds if it exists
write_sim_csv     <- TRUE      # when dummy data is used, also save it to raw_sim/

# ---- design (from the assignment) ----
window_m   <- 36                  # rolling window in months
min_valid  <- 30                  # minimum valid months per regression
top_n_univ <- 50                  # universe: 50 largest stocks
top_n      <- 10                  # stocks per portfolio
data_start <- ymd("2017-11-01")
first_form <- ymd("2020-12-01")   # first formation month (window: Jan 2018 - Dec 2020)
last_data  <- ymd("2025-12-01")
last_form  <- ymd("2025-11-01")   # last formation month for portfolios (held in Dec 2025)
Code
parse_ym <- function(x) {
  if (inherits(x, "Date")) return(floor_date(x, "month"))
  x  <- str_trim(as.character(x))
  i6 <- str_detect(x, "^[0-9]{6}$") %in% TRUE
  i8 <- str_detect(x, "^[0-9]{8}$") %in% TRUE
  out <- as.Date(rep(NA_character_, length(x)))
  if (any(i6)) out[i6] <- ymd(paste0(x[i6], "01"))
  if (any(i8)) out[i8] <- ymd(x[i8])
  rest <- is.na(out) & !is.na(x)
  if (any(rest))
    out[rest] <- as.Date(parse_date_time(x[rest],
                  orders = c("Ymd", "Ym", "Y/m/d", "Y/m", "Y-m-d", "Y-m"), quiet = TRUE))
  floor_date(out, "month")
}
num <- function(x) suppressWarnings(as.numeric(str_replace_all(x, ",", "")))

guess_delim <- function(path) {
  l <- readLines(path, n = 1, warn = FALSE)
  if (grepl("\t", l, fixed = TRUE, useBytes = TRUE)) "\t" else ","
}
read_all <- function(path) {
  read_delim(path, delim = guess_delim(path), col_names = has_header,
             col_types = cols(.default = col_character()),
             locale = locale(encoding = file_encoding),
             trim_ws = TRUE, show_col_types = FALSE)
}
read_raw <- function(path, k, nm) read_all(path)[seq_len(k)] |> set_names(nm)

# monthly return from adjusted prices; NA (never 0) if the previous month is missing
add_ret <- function(d) d |>
  arrange(ticker, ym) |>
  group_by(ticker) |>
  mutate(ret = if_else(ym == lag(ym) %m+% months(1),
                       adj_price / lag(adj_price) - 1, NA_real_)) |>
  ungroup()

dt <- function(d, n = 12) datatable(d, rownames = FALSE, options = list(scrollX = TRUE, pageLength = n))

1. Read and clean the data

Code
months_all <- seq(data_start, last_data, by = "month")
use_sim <- !all(file.exists(f_stock, f_factor, f_etf))

if (!use_sim) {
  stock_raw <- read_raw(f_stock, 4, c("id", "ym", "adj_price", "mktcap")) |>
    mutate(ticker = str_extract(str_trim(id), "^[0-9A-Za-z]+"),
           ym = parse_ym(ym), adj_price = num(adj_price), mktcap = num(mktcap)) |>
    select(ticker, ym, adj_price, mktcap)

  # factors: use the column names if they are there, otherwise the column order
  fd <- read_all(f_factor); nmf <- tolower(names(fd))
  if (has_header && all(c("rf", "mkt_rf", "smb", "hml") %in% nmf)) {
    fac_raw <- tibble(ym = fd[[1]], rf = fd[[match("rf", nmf)]], mkt_rf = fd[[match("mkt_rf", nmf)]],
                      smb = fd[[match("smb", nmf)]], hml = fd[[match("hml", nmf)]])
  } else {
    fac_raw <- fd[1:5] |> set_names(c("ym", "rf", "mkt_rf", "smb", "hml"))
  }
  fac_raw <- fac_raw |> mutate(ym = parse_ym(ym), across(-ym, num))

  etf <- read_raw(f_etf, 3, c("id", "ym", "adj_price")) |>
    mutate(ym = parse_ym(ym), adj_price = num(adj_price)) |>
    select(ym, adj_price)
} else {
  # ---------- DUMMY DATA (fake numbers, for testing only) ----------
  set.seed(2026)
  n <- length(months_all)
  fac_raw <- tibble(ym = months_all, rf = 0.0005, mkt_rf = rnorm(n, 0.006, 0.04),
                    smb = rnorm(n, 0, 0.02), hml = rnorm(n, 0, 0.02))
  stock_raw <- map_dfr(as.character(1101:1180), function(tk) {
    b <- c(rnorm(1, 1, 0.3), rnorm(1, -0.2, 0.3), rnorm(1, 0, 0.3))
    r <- fac_raw$rf + b[1] * fac_raw$mkt_rf + b[2] * fac_raw$smb + b[3] * fac_raw$hml +
         rnorm(n, 0.002, 0.05)
    g <- cumprod(1 + r)
    tibble(ticker = tk, ym = months_all, adj_price = 100 * g,
           mktcap = exp(rnorm(1, 10, 1)) * g * 1000)
  })
  r0  <- fac_raw$rf + fac_raw$mkt_rf + rnorm(n, 0, 0.005)
  etf <- tibble(ym = months_all, adj_price = 100 * cumprod(1 + r0)) |> filter(ym >= first_form)

  if (write_sim_csv) {
    dir.create("raw_sim", showWarnings = FALSE)
    stock_raw |> transmute(id = ticker, month = format(ym, "%Y%m"), adj_close = adj_price, mktcap) |>
      write_csv("raw_sim/tej_monthly.csv")
    fac_raw |> transmute(month = format(ym, "%Y%m"), rf, MKT_RF = mkt_rf, SMB = smb, HML = hml) |>
      write_csv("raw_sim/ff_factors_monthly.csv")
    etf |> transmute(id = "0050", month = format(ym, "%Y%m"), adj_close = adj_price) |>
      write_csv("raw_sim/etf0050_monthly.csv")
  }
}
Warning

Dummy data. The raw files were not found, so every number below is fake. Do not interpret or submit it.

Code
# keep 4-digit ordinary stocks (no leading 0 = no ETFs; 91xx = TDRs)
n_before <- n_distinct(stock_raw$ticker)
stock_raw <- stock_raw |>
  filter(str_detect(ticker, "^[1-9][0-9]{3}$"), !str_detect(ticker, "^91"))
cat("Tickers removed by the ordinary-stock filter:", n_before - n_distinct(stock_raw$ticker), "\n")
Tickers removed by the ordinary-stock filter: 0 
Code
# factors to decimals
pct <- max(abs(fac_raw$mkt_rf), na.rm = TRUE) > 1
fac <- if (pct) fac_raw |> mutate(across(-ym, ~ .x / 100)) else fac_raw
cat("Factors were in percent and were divided by 100:", pct, "\n")
Factors were in percent and were divided by 100: FALSE 
Code
stock <- stock_raw |> add_ret() |>
  left_join(fac |> select(ym, rf), by = "ym") |>
  mutate(ex_ret = ret - rf)

tibble(table = c("stock", "factors", "0050"),
       rows  = c(nrow(stock), nrow(fac), nrow(etf)),
       from  = c(min(stock$ym), min(fac$ym), min(etf$ym)),
       to    = c(max(stock$ym), max(fac$ym), max(etf$ym))) |> kable()
table rows from to
stock 7840 2017-11-01 2025-12-01
factors 98 2017-11-01 2025-12-01
0050 61 2020-12-01 2025-12-01
Code
stopifnot(!any(duplicated(stock[c("ticker", "ym")])),
          all(stock$adj_price > 0, na.rm = TRUE),
          !any(duplicated(fac$ym)),
          all(months_all %in% fac$ym))

2. Top-50 universe and rolling FF3 estimation

Each month from December 2020 the 50 largest stocks by market cap are the universe. For each of them, excess returns are regressed on MKT_RF, SMB and HML over the last 36 months up to and including the formation month (no look-ahead).

Code
top50 <- stock |>
  filter(ym >= first_form, ym <= last_data, !is.na(mktcap), mktcap > 0, !is.na(adj_price)) |>
  group_by(ym) |>
  slice_max(mktcap, n = top_n_univ, with_ties = FALSE) |>
  mutate(rank = row_number()) |>
  ungroup() |>
  select(ticker, ym, rank, mktcap)
cat("top50 rows:", nrow(top50), "(expected 3,050)\n")
top50 rows: 3050 (expected 3,050)

2.1 First window: the top 50 of December 2020 (January 2018 to December 2020)

Code
w0  <- first_form %m-% months(window_m - 1)       # January 2018
tk0 <- top50 |> filter(ym == first_form) |> arrange(rank)

win <- stock |>
  filter(ticker %in% tk0$ticker, ym >= w0, ym <= first_form) |>
  select(ticker, ym, ret) |>
  pivot_wider(names_from = ticker, values_from = ret) |>
  arrange(ym) |>
  left_join(fac |> select(ym, rf, mkt_rf, smb, hml), by = "ym") |>
  select(ym, rf, mkt_rf, smb, hml, any_of(tk0$ticker))

stopifnot(nrow(win) == window_m)
cat("Window:", format(min(win$ym), "%Y-%m"), "to", format(max(win$ym), "%Y-%m"),
    "|", nrow(win), "months |", sum(names(win) %in% tk0$ticker), "stocks\n")
Window: 2018-01 to 2020-12 | 36 months | 50 stocks

Table 1. Monthly returns (decimals) of the 50 largest stocks of December 2020 (columns ordered by market-cap rank) and the three Fama-French factors for the first 36-month window.

Code
win |> mutate(ym = format(ym, "%Y-%m"), across(where(is.numeric), ~ round(.x, 4))) |> dt(12)
Code
lam <- map_dfr(seq(first_form, last_data, by = "month"), function(f) {
  w <- fac |> filter(ym >= f %m-% months(window_m - 1), ym <= f)
  tibble(form_ym = f, n_fac = nrow(w),
         lam_mkt = mean(w$mkt_rf), lam_smb = mean(w$smb), lam_hml = mean(w$hml))
})
stopifnot(all(lam$n_fac == window_m))

if (use_saved_rolling && file.exists(f_rolling_saved)) {
  rolling_ff3 <- read_rds(f_rolling_saved) |> mutate(form_ym = parse_ym(form_ym))
  cat("Loaded", f_rolling_saved, "\n")
} else {
  panel <- stock |> select(ticker, ym, ex_ret) |>
    inner_join(fac |> select(ym, mkt_rf, smb, hml), by = "ym")

  roll_one <- function(f) {
    w0 <- f %m-% months(window_m - 1)
    tk <- top50 |> filter(ym == f) |> select(ticker, rank)
    d  <- panel |> filter(ym >= w0, ym <= f, ticker %in% tk$ticker, !is.na(ex_ret))
    est <- d |>
      group_by(ticker) |>
      filter(n() >= min_valid) |>
      group_modify(~ {
        s  <- summary(lm(ex_ret ~ mkt_rf + smb + hml, data = .x))
        co <- s$coefficients
        tibble(alpha = co[1, 1], t_alpha = co[1, 3],
               b_mkt = co[2, 1], b_smb = co[3, 1], b_hml = co[4, 1],
               adj_r2 = s$adj.r.squared, n_obs = nrow(.x))
      }) |>
      ungroup()
    tk |> left_join(est, by = "ticker") |> mutate(form_ym = f, .before = 1)
  }
  rolling_ff3 <- map_dfr(seq(first_form, last_data, by = "month"), roll_one)
  dir.create("output", showWarnings = FALSE)
  write_rds(rolling_ff3, f_rolling_saved)
}
Loaded output/rolling_ff3.rds 
Code
tibble(stock_months = nrow(rolling_ff3),
       estimated = sum(!is.na(rolling_ff3$alpha)),
       not_estimated = sum(is.na(rolling_ff3$alpha))) |> kable()
stock_months estimated not_estimated
3050 3050 0

Table 2. FF3 regression results for the first window (formation month December 2020).

Code
rolling_ff3 |> filter(form_ym == first_form) |> arrange(rank) |>
  select(rank, ticker, alpha, t_alpha, b_mkt, b_smb, b_hml, adj_r2, n_obs) |>
  mutate(across(where(is.numeric), ~ round(.x, 4))) |> dt(10)

3. Signals: alpha and FF3_exp

For every stock and formation month

\[\text{FF3\_exp}=\beta_{mkt}\,\lambda_{mkt}+\beta_{smb}\,\lambda_{smb}+\beta_{hml}\,\lambda_{hml}\]

where the lambdas are the averages of MKT_RF, SMB, HML over the same 36 months. Alpha is not part of FF3_exp.

Code
sig <- rolling_ff3 |>
  filter(!is.na(alpha)) |>
  left_join(lam, by = "form_ym") |>
  mutate(exp_ret = b_mkt * lam_mkt + b_smb * lam_smb + b_hml * lam_hml) |>
  filter(form_ym <= last_form)

sig |> count(year = year(form_ym), name = "stocks with a signal") |> kable()
year stocks with a signal
2020 50
2021 600
2022 600
2023 600
2024 600
2025 550

4. Top-10 stocks by each signal

Code
pick <- function(d, var, name) {
  d |> group_by(form_ym) |>
    slice_max(.data[[var]], n = top_n, with_ties = FALSE) |>
    ungroup() |>
    transmute(signal = name, form_ym, ticker, rank, value = .data[[var]])
}
holdings <- bind_rows(pick(sig, "alpha", "alpha"), pick(sig, "exp_ret", "exp"))

overlap <- holdings |>
  group_by(form_ym) |>
  summarise(common = length(intersect(ticker[signal == "alpha"], ticker[signal == "exp"])))
overlap |> group_by(year = year(form_ym)) |>
  summarise(`avg. stocks in common (of 10)` = mean(common)) |> kable(digits = 2)
year avg. stocks in common (of 10)
2020 1.00
2021 0.75
2022 0.58
2023 0.92
2024 1.83
2025 1.55
Code
turn <- holdings |>
  group_by(signal, form_ym) |>
  summarise(tk = list(ticker), .groups = "drop") |>
  arrange(signal, form_ym) |>
  group_by(signal) |>
  mutate(prev = lag(tk),
         turnover = map2_dbl(tk, prev, ~ if (length(.y) != top_n) NA_real_
                                         else 1 - length(intersect(.x, .y)) / top_n)) |>
  ungroup()
turn |> group_by(signal) |>
  summarise(`avg. monthly turnover` = percent(mean(turnover, na.rm = TRUE), 0.1)) |> kable()
signal avg. monthly turnover
alpha 17.8%
exp 17.6%

Top 10 in the last formation month

Code
holdings |> filter(form_ym == last_form) |>
  mutate(value = round(value, 5), form_ym = format(form_ym, "%Y-%m")) |> dt(10)

5. Four portfolios and concentration

Portfolios are formed at the end of month t and held in month t+1 (January 2021 to December 2025 = 60 months): alpha_EW, alpha_VW, exp_EW, exp_VW (EW = 1/10 each; VW = market cap at the end of t). A stock without a return in the holding month is dropped and the weights are rescaled.

Code
ret_tbl <- stock |> select(ticker, ym, ret)
cap_tbl <- stock |> select(ticker, form_ym = ym, mktcap)

hr <- holdings |>
  mutate(hold_ym = form_ym %m+% months(1)) |>
  left_join(cap_tbl, by = c("ticker", "form_ym")) |>
  left_join(ret_tbl |> rename(hold_ym = ym), by = c("ticker", "hold_ym"))

wts <- hr |>
  filter(!is.na(ret)) |>
  group_by(signal, form_ym) |>
  mutate(EW = 1 / n(), VW = mktcap / sum(mktcap)) |>
  ungroup()

port4 <- wts |>
  group_by(signal, hold_ym) |>
  summarise(EW = sum(EW * ret), VW = sum(VW * ret), .groups = "drop") |>
  pivot_longer(c(EW, VW), names_to = "scheme", values_to = "ret") |>
  transmute(portfolio = paste(signal, scheme, sep = "_"), hold_ym, ret)

hr |> group_by(signal) |>
  summarise(`stock-months` = n(), `missing return` = sum(is.na(ret)),
            share = percent(mean(is.na(ret)), 0.01)) |> kable()
signal stock-months missing return share
alpha 600 0 0.00%
exp 600 0 0.00%

Concentration of the value-weighted portfolios

Code
vw <- hr |>
  group_by(signal, form_ym) |>
  mutate(w = mktcap / sum(mktcap)) |>
  arrange(desc(w), .by_group = TRUE) |>
  mutate(pos = row_number()) |>
  ungroup()

conc <- vw |>
  group_by(signal, form_ym) |>
  summarise(max_w = max(w), top3 = sum(w[pos <= 3]), hhi = sum(w^2), .groups = "drop")

conc |> group_by(signal) |>
  summarise(`Avg. largest weight` = percent(mean(max_w), 0.1),
            `Avg. top-3 weight`   = percent(mean(top3), 0.1),
            `Avg. HHI`            = round(mean(hhi), 3),
            `Effective N (1/HHI)` = round(mean(1 / hhi), 1)) |>
  kable(caption = "Equal weights would give: largest 10%, top-3 30%, HHI 0.10, effective N 10.")
Equal weights would give: largest 10%, top-3 30%, HHI 0.10, effective N 10.
signal Avg. largest weight Avg. top-3 weight Avg. HHI Effective N (1/HHI)
alpha 36.5% 68.4% 0.222 4.8
exp 36.0% 72.2% 0.228 4.6
Code
vw |> group_by(signal, pos) |> summarise(w = mean(w), .groups = "drop") |>
  ggplot(aes(factor(pos), w, fill = signal)) +
  geom_col(position = "dodge") +
  scale_y_continuous(labels = percent) +
  labs(x = "Holding, ranked by weight", y = "Average weight", fill = "Signal",
       title = "Average value weights of the top-10 portfolios") +
  theme_minimal()

6. Benchmarks: 0050 and the top-50 value-weighted proxy

Code
etf_ret <- etf |> mutate(ticker = "0050") |> add_ret() |>
  filter(ym >= first_form %m+% months(1), ym <= last_data) |>
  transmute(portfolio = "0050", hold_ym = ym, ret)

# cross-check with quantmod::Delt (simple percentage change of the adjusted price)
etf_x  <- xts(etf$adj_price, order.by = etf$ym)
etf_chk <- tibble(ym = etf$ym, r = as.numeric(Delt(etf_x))) |>
  filter(ym >= first_form %m+% months(1), ym <= last_data)
stopifnot(isTRUE(all.equal(etf_chk$r, etf_ret$ret)))

# the 4-for-1 split of June 2025 must not appear as a -75% month
stopifnot(min(etf_ret$ret, na.rm = TRUE) > -0.5)

vw50 <- top50 |>
  filter(ym <= last_form) |>
  transmute(ticker, form_ym = ym, mktcap) |>
  mutate(hold_ym = form_ym %m+% months(1)) |>
  left_join(ret_tbl |> rename(hold_ym = ym), by = c("ticker", "hold_ym")) |>
  filter(!is.na(ret)) |>
  group_by(hold_ym) |>
  summarise(ret = sum(mktcap * ret) / sum(mktcap), .groups = "drop") |>
  mutate(portfolio = "VW50")

series <- c("alpha_EW", "alpha_VW", "exp_EW", "exp_VW", "VW50", "0050")

portfolio_returns <- bind_rows(port4, vw50, etf_ret) |>
  mutate(portfolio = factor(portfolio, levels = series)) |>
  arrange(portfolio, hold_ym) |>
  mutate(portfolio = as.character(portfolio))

cmp <- inner_join(vw50 |> select(hold_ym, vw50 = ret), etf_ret |> select(hold_ym, e0050 = ret),
                  by = "hold_ym")
tibble(Correlation = round(cor(cmp$vw50, cmp$e0050), 3),
       `Tracking error (ann.)` = percent(sd(cmp$vw50 - cmp$e0050) * sqrt(12), 0.1),
       `Cum. return VW50` = percent(prod(1 + cmp$vw50) - 1, 0.1),
       `Cum. return 0050` = percent(prod(1 + cmp$e0050) - 1, 0.1),
       Difference = percent((prod(1 + cmp$vw50) - 1) - (prod(1 + cmp$e0050) - 1), 0.1)) |> kable()
Correlation Tracking error (ann.) Cum. return VW50 Cum. return 0050 Difference
0.957 4.2% 3.3% 12.3% -9.0%

VW50 is the 50 largest stocks by market cap each month with uncapped weights, while 0050 has its own selection, weight caps, rebalancing rules, fees and dividend treatment, so the two series are highly correlated but not identical.

7. Performance versus 0050

Return, risk, tracking error and information ratio come from PerformanceAnalytics (geometric annualisation; tracking error = sd of the monthly active return x sqrt(12); information ratio = annualised active premium / tracking error). The FF3 alpha comes from regressing the excess return on MKT_RF, SMB and HML.

Code
pw <- portfolio_returns |>
  pivot_wider(names_from = portfolio, values_from = ret) |>
  left_join(fac |> rename(hold_ym = ym), by = "hold_ym") |>
  arrange(hold_ym)

pw_xts <- xts(as.matrix(pw[series]), order.by = pw$hold_ym)
rf_xts <- xts(pw$rf, order.by = pw$hold_ym)
b_xts  <- pw_xts[, "0050"]

perf_one <- function(p) {
  R  <- pw_xts[, p]
  ex <- pw[[p]] - pw$rf
  co <- summary(lm(ex ~ mkt_rf + smb + hml, data = pw))$coefficients
  isb <- p == "0050"
  tibble(portfolio  = p,
         cum_ret    = as.numeric(Return.cumulative(R)),
         ann_ret    = as.numeric(Return.annualized(R, scale = 12)),
         ann_vol    = as.numeric(StdDev.annualized(R, scale = 12)),
         sharpe     = as.numeric(SharpeRatio.annualized(R, Rf = rf_xts, scale = 12)),
         max_dd     = -as.numeric(maxDrawdown(R)),
         ff3_alpha_m = co[1, 1], t_alpha = co[1, 3],
         ann_active = if (isb) NA_real_ else as.numeric(ActivePremium(R, b_xts, scale = 12)),
         te         = if (isb) NA_real_ else as.numeric(TrackingError(R, b_xts, scale = 12)),
         ir         = if (isb) NA_real_ else as.numeric(InformationRatio(R, b_xts, scale = 12)),
         hit        = if (isb) NA_real_ else mean(as.numeric(R) > as.numeric(b_xts)))
}
performance <- map_dfr(series, perf_one)

performance |>
  transmute(Portfolio = portfolio,
            `Cum. return` = percent(cum_ret, 0.1), `Ann. return` = percent(ann_ret, 0.1),
            `Ann. vol` = percent(ann_vol, 0.1), Sharpe = round(sharpe, 2),
            `Max drawdown` = percent(max_dd, 0.1),
            `FF3 alpha (monthly)` = percent(ff3_alpha_m, 0.01), `t(alpha)` = round(t_alpha, 2),
            `Ann. active return` = percent(ann_active, 0.1), `Tracking error` = percent(te, 0.1),
            `Info ratio` = round(ir, 2), `Beats 0050` = percent(hit, 1)) |>
  kable()
Portfolio Cum. return Ann. return Ann. vol Sharpe Max drawdown FF3 alpha (monthly) t(alpha) Ann. active return Tracking error Info ratio Beats 0050
alpha_EW 9.0% 1.7% 14.1% 0.15 -30.6% 0.13% 0.57 -0.6% 6.4% -0.10 47%
alpha_VW 3.1% 0.6% 16.3% 0.08 -30.7% 0.11% 0.34 -1.7% 9.0% -0.19 50%
exp_EW 30.4% 5.5% 15.8% 0.38 -22.9% 0.41% 1.71 3.1% 6.4% 0.49 55%
exp_VW -2.7% -0.5% 18.1% 0.03 -28.6% -0.07% -0.21 -2.9% 8.9% -0.32 53%
VW50 3.3% 0.7% 14.2% 0.07 -24.4% 0.07% 0.52 -1.7% 4.2% -0.41 43%
0050 12.3% 2.4% 14.3% 0.19 -25.7% 0.14% 2.01 NA NA NA NA

Growth of NT$100

Code
growth <- bind_rows(tibble(portfolio = series, hold_ym = first_form, ret = 0),  # start at NT$100
                    portfolio_returns) |>
  arrange(portfolio, hold_ym) |>
  group_by(portfolio) |>
  mutate(value = 100 * cumprod(1 + ret)) |> ungroup() |>
  mutate(portfolio = factor(portfolio, levels = series))

ggplot(growth, aes(hold_ym, value, colour = portfolio, linewidth = portfolio == "0050")) +
  geom_line() +
  scale_linewidth_manual(values = c(`TRUE` = 1.4, `FALSE` = 0.7), guide = "none") +
  labs(x = NULL, y = "Value of NT$100", colour = NULL,
       title = "Growth of NT$100: top-10 portfolios, VW50 proxy and 0050",
       subtitle = "Held January 2021 to December 2025") +
  theme_minimal() + theme(legend.position = "bottom")

8. Checks

Code
w_ok <- wts |> group_by(signal, form_ym) |>
  summarise(a = sum(EW), b = sum(VW), .groups = "drop") |>
  summarise(ok = all(abs(a - 1) < 1e-9 & abs(b - 1) < 1e-9)) |> pull(ok)

tibble(check = c("10 stocks per signal and formation month",
                 "holdings rows = 1,200",
                 "weights add to 1",
                 "60 holding months for every series",
                 "portfolio_returns rows = 360",
                 "performance rows = 6",
                 "holding month = formation month + 1 (no look-ahead)"),
       passed = c(all(count(holdings, signal, form_ym)$n == top_n),
                  nrow(holdings) == 1200,
                  w_ok,
                  all(count(portfolio_returns, portfolio)$n == 60),
                  nrow(portfolio_returns) == 360,
                  nrow(performance) == 6,
                  all(hr$hold_ym == hr$form_ym %m+% months(1)))) |> kable()
check passed
10 stocks per signal and formation month TRUE
holdings rows = 1,200 TRUE
weights add to 1 TRUE
60 holding months for every series TRUE
portfolio_returns rows = 360 TRUE
performance rows = 6 TRUE
holding month = formation month + 1 (no look-ahead) TRUE
Code
dir.create("output", showWarnings = FALSE)
write_csv(holdings, "output/holdings.csv")
write_csv(portfolio_returns, "output/portfolio_returns.csv")
write_csv(performance, "output/performance.csv")

9. Discussion

Code
four    <- performance |> filter(portfolio %in% series[1:4])
best    <- four |> slice_max(t_alpha, n = 1, with_ties = FALSE)
any_sig <- any(abs(four$t_alpha) > 1.96)
bench   <- performance |> filter(portfolio == "0050")

Did the portfolios beat 0050 after adjusting for risk? The monthly FF3 alphas of the four portfolios range from -0.07% to 0.41%. The highest t-statistic is 1.71 (exp_EW), so no portfolio has a statistically significant alpha (|t| > 1.96). 0050 returned 2.4% a year; the best information ratio among the four portfolios is 0.49.

EW vs. VW. (Rewrite in your own words.) The value-weighted portfolios put on average 36.3% in their largest stock (equal weights: 10%) and have an effective N of about 4.7 stocks, so they depend on a few large names, while the equal-weighted ones give more weight to smaller stocks of the top 50.

Alpha rule vs. FF3_exp rule. (Rewrite.) The two lists share on average 1.1 of 10 stocks. Alpha is the unexplained part of past returns and is very noisy over 36 months, whereas FF3_exp depends only on the factor loadings and factor premia and is more stable.

Limitations. (Keep three, in your own words.) The top-50 proxy is not the real 0050; alphas and betas from 36 monthly observations are noisy and overlapping windows are strongly dependent; no trading costs; only 60 holding months; stocks with missing returns are dropped.

10. Publish

Render the file, then push the .qmd (and the data it needs) to GitHub and publish at https://connect.posit.cloud. Submit the link on TronClass together with holdings.csv, portfolio_returns.csv and performance.csv if requested.