2025-10-20

Price with moving averages

Return distributions

Code slide — estimate CAPM beta

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

Interactive: indexed price

Interactive: candlestick (plotly)

3D interactive: risk–return–beta

Results table

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

Model ideas (math 1/2: GBM)

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) \]

  • \(P_t\) is today’s price; \(P_{t-1}\) is yesterday’s.
  • If \(r_t = 0.01\) that is a 1% gain.
  • \(I_t\) compounds daily returns to show growth since the start.

Model ideas (math 2/2: CAPM + inference)

A super simple way to define beta: \[ \beta \;=\; \frac{\operatorname{Cov}(r_i,\; r_m)}{\operatorname{Var}(r_m)} \]

  • \(r_i\): your stock’s daily return
  • \(r_m\): market’s daily return
  • If \(\beta \approx 1\): moves like the market
  • If \(\beta > 1\): more sensitive (amplifies market moves)
  • If \(\beta < 1\): less sensitive (dampens market moves)