Step 0: Estimate N Time Series Regression

step0 <- data %>% 
  nest(data = c(date,ri,MKT,SMB,HML)) %>% 
  mutate(estimates = map(
    data,
    ~tidy(lm(ri ~ MKT + SMB + HML, data = .x))
  )) %>% 
  unnest(estimates) %>% 
  select(symbol, estimate, term) %>% 
  pivot_wider(names_from  = term,
              values_from = estimate) %>% 
  select(symbol, 
         b_MKT = MKT, 
         b_HML = HML, 
         b_SMB = SMB)


step0 <- data %>% 
  left_join(step0, by = "symbol")
Step 0: Estimate N Time series Regression
symbol date ri MKT SMB HML b_MKT b_HML b_SMB
AAPL 4-Jan-11 0.0052063 -0.0013139 -0.0065 0.0008 0.9000063 -0.0578213 0.0685351
AAPL 5-Jan-11 0.0081463 0.0049947 0.0018 0.0013 0.9000063 -0.0578213 0.0685351
AAPL 6-Jan-11 -0.0008082 -0.0021252 0.0001 -0.0025 0.9000063 -0.0578213 0.0685351
AAPL 7-Jan-11 0.0071361 -0.0018465 0.0022 -0.0006 0.9000063 -0.0578213 0.0685351
AAPL 10-Jan-11 0.0186573 -0.0013773 0.0041 0.0039 0.9000063 -0.0578213 0.0685351
AAPL 11-Jan-11 -0.0023682 0.0037182 0.0016 0.0036 0.9000063 -0.0578213 0.0685351

Step 1: Estimate T Cross-sectional regression

step1 <- step0 %>% 
    nest(data = c(symbol, ri, b_MKT, b_SMB, b_HML)) %>% 
  mutate(estimates = map(
    data,
    ~tidy(lm(ri ~ b_MKT + b_SMB + b_HML, data = .x))
  )) %>%
  unnest(estimates) %>% 
  select(date, estimate, term) %>% 
  pivot_wider(names_from  = term,
              values_from = estimate) %>% 
  select(date, b_MKT, b_HML, b_SMB)
Step 1: Estimate T Cross-sectional regression
date b_MKT b_HML b_SMB
4-Jan-11 0.0416292 0.0573720 -0.0255197
5-Jan-11 -0.0113470 0.0628473 -0.1580455
6-Jan-11 0.0373012 -0.1732343 0.0070293
7-Jan-11 0.0127224 -0.0642265 0.0322688
10-Jan-11 -0.0366313 0.0586457 0.0171230
11-Jan-11 0.0040892 0.0898581 -0.0953614

Step 2: Estimate time series averages

# Step2: Estimate time series averages
t.test(step1$b_MKT, mu=0)
## 
##  One Sample t-test
## 
## data:  step1$b_MKT
## t = -0.37879, df = 1256, p-value = 0.7049
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.002546371  0.001722208
## sample estimates:
##     mean of x 
## -0.0004120813
t.test(step1$b_SMB, mu=0)
## 
##  One Sample t-test
## 
## data:  step1$b_SMB
## t = 0.97712, df = 1256, p-value = 0.3287
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.003711466  0.011076953
## sample estimates:
##   mean of x 
## 0.003682744
t.test(step1$b_HML, mu=0)
## 
##  One Sample t-test
## 
## data:  step1$b_HML
## t = -0.18044, df = 1256, p-value = 0.8568
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  -0.005541205  0.004607776
## sample estimates:
##     mean of x 
## -0.0004667146