2025-10-20
capm_models <- rets %>% nest_by(ticker) %>% mutate(model = list(lm(ret ~ mkt, data = data))) summary(capm_models$model[[1]]) # AAPL beta summary (example)
## ## Call: ## lm(formula = ret ~ mkt, data = data) ## ## Residuals: ## Min 1Q Median 3Q Max ## -0.038224 -0.010580 -0.000246 0.010038 0.045434 ## ## Coefficients: ## Estimate Std. Error t value Pr(>|t|) ## (Intercept) 0.0001137 0.0006748 0.168 0.866 ## mkt 0.6420567 0.0529620 12.123 <2e-16 *** ## --- ## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 ## ## Residual standard error: 0.01509 on 498 degrees of freedom ## Multiple R-squared: 0.2279, Adjusted R-squared: 0.2263 ## F-statistic: 147 on 1 and 498 DF, p-value: < 2.2e-16
| Ticker | Ann. Return | Ann. Vol | Beta |
|---|---|---|---|
| MSFT | 4.1% | 22.7% | 0.4166043 |
| AAPL | 0.7% | 27.2% | 0.6420567 |
| NVDA | -14.3% | 48.3% | 1.9413390 |
We simulate prices with geometric Brownian motion:
Daily return: \[ r_t \;=\; \frac{P_t - P_{t-1}}{P_{t-1}} \]
Indexed price (start at 100): \[ I_t \;=\; 100 \times \prod_{s=1}^{t}\bigl(1 + r_s\bigr) \]
A super simple way to define beta: \[ \beta \;=\; \frac{\operatorname{Cov}(r_i,\; r_m)}{\operatorname{Var}(r_m)} \]