We have Fama-French pricing factor data from 2000-01 to 2024-06. We want to have a look at its descriptive statistics.
data <- read_csv("data/FF_3Factors_US_monthly.csv")
get_stat <- function(x, q_list=c(0.025, 0.5, 0.975)){
## Return extended summary statistics with quantiles and sd.
# @q_list: vector of quantiles to calculate;
x <- na.omit(x)
c(summary(x), quantile(x, q_list), "sd"=sd(x) )
}
apply(data[,-1], 2, get_stat)
## Mkt-RF SMB HML RF
## Min. -17.230000 -17.2000000 -13.8300000 0.0000000
## 1st Qu. -2.020000 -1.8475000 -1.6925000 0.0100000
## Median 1.175000 0.0850000 -0.0500000 0.0900000
## Mean 0.577551 0.1342517 0.1777211 0.1418707
## 3rd Qu. 3.307500 1.8400000 1.7775000 0.2275000
## Max. 13.650000 21.3600000 12.8800000 0.5600000
## 2.5% -9.424250 -5.0090000 -7.4225000 0.0000000
## 50% 1.175000 0.0850000 -0.0500000 0.0900000
## 97.5% 8.697000 6.0207500 7.8932500 0.4767500
## sd 4.609053 3.2149253 3.4991826 0.1596741
ggplot(data) +
geom_histogram(aes(x=SMB, y=..density..),
fill="#BDBCBC",
color="black",
binwidth = 2,
boundary=0) +
labs(x="Small minus big, SMB")
ggplot(data) +
geom_histogram(aes(x=HML, y=..density..),
fill="#BDBCBC",
color="black",
binwidth = 2,
boundary=0) +
labs(x="High minus low, HML")
Before 2013 NIBOR: Norges Bank
After 2013 Norwegian Overnight Weighted Average rate: Norske Finansielle Referenser AS (NoRe)
Titlon: 3 months Norwegian Government Bills, from the bondindex
table, CloseYield field
.
Financial service companies publish surveys about financial data. For instance, PwC Norge.
library(quantmod)
aapl <- getSymbols("AAPL",
src = 'yahoo',
from = "2014-08-01",
to = "2024-09-17",
auto.assign = FALSE
)
aapl
## AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume AAPL.Adjusted
## 2014-08-01 23.7250 24.1550 23.7025 24.0325 194044000 21.20968
## 2014-08-04 24.0925 24.1450 23.7925 23.8975 159832000 21.09054
## 2014-08-05 23.8400 23.9200 23.5900 23.7800 223732000 20.98684
## 2014-08-06 23.6875 23.8700 23.6775 23.7400 154232000 20.95154
## 2014-08-07 23.7325 23.9875 23.5250 23.6200 186844000 20.94932
## 2014-08-08 23.5650 23.7050 23.3200 23.6850 167460000 21.00697
## 2014-08-11 23.8175 24.0200 23.7100 23.9975 146340000 21.28414
## 2014-08-12 24.0100 24.2200 23.9025 23.9925 135180000 21.27971
## 2014-08-13 24.0375 24.3100 24.0100 24.3100 127664000 21.56130
## 2014-08-14 24.3325 24.3925 24.2000 24.3750 112464000 21.61895
## ...
## 2024-09-03 228.5500 229.0000 221.1700 222.7700 50190600 222.52518
## 2024-09-04 221.6600 221.7800 217.4800 220.8500 43840200 220.60730
## 2024-09-05 221.6300 225.4800 221.5200 222.3800 36615400 222.13560
## 2024-09-06 223.9500 225.2400 219.7700 220.8200 48423000 220.57733
## 2024-09-09 220.8200 221.2700 216.7100 220.9100 67180000 220.66722
## 2024-09-10 218.9200 221.4800 216.7300 220.1100 51591000 219.86810
## 2024-09-11 221.4600 223.0900 217.8900 222.6600 44587100 222.41530
## 2024-09-12 222.5000 223.5500 219.8200 222.7700 37498200 222.52518
## 2024-09-13 223.5800 224.0400 221.9100 222.5000 36766600 222.25548
## 2024-09-16 216.5400 217.2200 213.9200 216.3200 59357400 216.08228
Candlestick Plot
chartSeries(aapl, subset="2024-09", theme=chartTheme('white',up.col='green',dn.col='red'))
Calculate monthly return, \(r_t = \frac{P_t-P_{t-1}}{P_{t-1}} = \frac{P_t}{P_{t-1}}-1\).
You may either use the function quantmod::monthlyReturn()
or calculate manually.
aapl <- aapl %>%
apply.monthly(last)
aapl$return <- monthlyReturn(aapl$AAPL.Adjusted, type='arithmetic')
aapl <- head(aapl, -1)
aapl
## AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume AAPL.Adjusted
## 2014-08-29 25.7150 25.7250 25.5500 25.6250 178380000 22.72762
## 2014-09-30 25.2025 25.3850 25.1325 25.1875 221056400 22.33959
## 2014-10-31 27.0025 27.0100 26.8025 27.0000 178557200 23.94715
## 2014-11-28 29.8175 29.8500 29.5125 29.7325 99257600 26.48504
## 2014-12-31 28.2050 28.2825 27.5525 27.5950 165613600 24.58101
## 2015-01-30 29.6000 30.0000 29.2125 29.2900 334982000 26.09087
## 2015-02-27 32.5000 32.6425 32.0600 32.1150 248059200 28.72022
## 2015-03-31 31.5225 31.6225 31.0900 31.1075 168362400 27.81922
## 2015-04-30 32.1600 32.1600 31.1450 31.2875 332781600 27.98019
## 2015-05-29 32.8075 32.8625 32.4750 32.5700 203538000 29.24879
## ...
## 2023-11-30 189.8400 190.3200 188.1900 189.9500 48794400 189.02396
## 2023-12-29 193.9000 194.4000 191.7300 192.5300 42628800 191.59138
## 2024-01-31 187.0400 187.1000 184.3500 184.4000 55467800 183.50102
## 2024-02-29 181.2700 182.5700 179.5300 180.7500 136682600 180.09834
## 2024-03-28 171.7500 172.2300 170.5100 171.4800 65672700 170.86176
## 2024-04-30 173.3300 174.9900 170.0000 170.3300 65934800 169.71590
## 2024-05-31 191.4400 192.5700 189.9100 192.2500 75158300 191.81670
## 2024-06-28 215.7700 216.0700 210.3000 210.6200 82542700 210.14528
## 2024-07-31 221.4400 223.8200 220.6300 222.0800 50036300 221.57947
## 2024-08-30 230.1900 230.4000 227.4800 229.0000 52990800 228.74834
## return
## 2014-08-29 0.000000000
## 2014-09-30 -0.017073105
## 2014-10-31 0.071960286
## 2014-11-28 0.105978772
## 2014-12-31 -0.071890915
## 2015-01-30 0.061424124
## 2015-02-27 0.100776504
## 2015-03-31 -0.031371661
## 2015-04-30 0.005786313
## 2015-05-29 0.045339376
## ...
## 2023-11-30 0.113780167
## 2023-12-29 0.013582557
## 2024-01-31 -0.042227173
## 2024-02-29 -0.018543109
## 2024-03-28 -0.051286355
## 2024-04-30 -0.006706350
## 2024-05-31 0.130222330
## 2024-06-28 0.095552593
## 2024-07-31 0.054410877
## 2024-08-30 0.032353490
# calculate manually
with(aapl, AAPL.Adjusted/lag(AAPL.Adjusted)-1)
## AAPL.Adjusted
## 2014-08-29 NA
## 2014-09-30 -0.017073105
## 2014-10-31 0.071960286
## 2014-11-28 0.105978772
## 2014-12-31 -0.071890915
## 2015-01-30 0.061424124
## 2015-02-27 0.100776504
## 2015-03-31 -0.031371661
## 2015-04-30 0.005786313
## 2015-05-29 0.045339376
## ...
## 2023-11-30 0.113780167
## 2023-12-29 0.013582557
## 2024-01-31 -0.042227173
## 2024-02-29 -0.018543109
## 2024-03-28 -0.051286355
## 2024-04-30 -0.006706350
## 2024-05-31 0.130222330
## 2024-06-28 0.095552593
## 2024-07-31 0.054410877
## 2024-08-30 0.032353490
Merge equity data with FF factors.
reg_data <- aapl %>%
as_tibble() %>%
add_column(Date=index(aapl), .before = 1)
reg_data <- reg_data %>%
mutate(year=year(Date),
mon=month(Date))
data <- data %>% mutate_at(vars(-Date), ~./100)
data <- data %>%
mutate(year=year(Date),
mon=month(Date))
reg_data <- reg_data %>%
left_join(data[,-1], by=c("year","mon"))
reg_data
## # A tibble: 121 × 14
## Date AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume AAPL.Adjusted
## <date> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 2014-08-29 25.7 25.7 25.5 25.6 178380000 22.7
## 2 2014-09-30 25.2 25.4 25.1 25.2 221056400 22.3
## 3 2014-10-31 27.0 27.0 26.8 27 178557200 23.9
## 4 2014-11-28 29.8 29.9 29.5 29.7 99257600 26.5
## 5 2014-12-31 28.2 28.3 27.6 27.6 165613600 24.6
## 6 2015-01-30 29.6 30 29.2 29.3 334982000 26.1
## 7 2015-02-27 32.5 32.6 32.1 32.1 248059200 28.7
## 8 2015-03-31 31.5 31.6 31.1 31.1 168362400 27.8
## 9 2015-04-30 32.2 32.2 31.1 31.3 332781600 28.0
## 10 2015-05-29 32.8 32.9 32.5 32.6 203538000 29.2
## # ℹ 111 more rows
## # ℹ 7 more variables: return <dbl>, year <dbl>, mon <dbl>, `Mkt-RF` <dbl>,
## # SMB <dbl>, HML <dbl>, RF <dbl>
Calculate excess return.
# calculate excess return
reg_data <- reg_data %>%
mutate(eRi = return-RF) %>%
rename(rmrf=`Mkt-RF`)
reg_data %>%
select(-year,-mon) %>%
knitr::kable(floating.environment="sidewaystable", digits = 5, escape=F) %>%
kable_styling(bootstrap_options = c("striped", "hover"), full_width = F, latex_options="scale_down") %>%
scroll_box(width = "100%", height = "500px")
Date | AAPL.Open | AAPL.High | AAPL.Low | AAPL.Close | AAPL.Volume | AAPL.Adjusted | return | rmrf | SMB | HML | RF | eRi |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2014-08-29 | 25.7150 | 25.7250 | 25.5500 | 25.6250 | 178380000 | 22.72762 | 0.00000 | 0.0424 | 0.0040 | -0.0045 | 0.0000 | 0.00000 |
2014-09-30 | 25.2025 | 25.3850 | 25.1325 | 25.1875 | 221056400 | 22.33959 | -0.01707 | -0.0197 | -0.0371 | -0.0134 | 0.0000 | -0.01707 |
2014-10-31 | 27.0025 | 27.0100 | 26.8025 | 27.0000 | 178557200 | 23.94715 | 0.07196 | 0.0252 | 0.0421 | -0.0181 | 0.0000 | 0.07196 |
2014-11-28 | 29.8175 | 29.8500 | 29.5125 | 29.7325 | 99257600 | 26.48504 | 0.10598 | 0.0255 | -0.0206 | -0.0309 | 0.0000 | 0.10598 |
2014-12-31 | 28.2050 | 28.2825 | 27.5525 | 27.5950 | 165613600 | 24.58101 | -0.07189 | -0.0006 | 0.0249 | 0.0227 | 0.0000 | -0.07189 |
2015-01-30 | 29.6000 | 30.0000 | 29.2125 | 29.2900 | 334982000 | 26.09087 | 0.06142 | -0.0311 | -0.0056 | -0.0358 | 0.0000 | 0.06142 |
2015-02-27 | 32.5000 | 32.6425 | 32.0600 | 32.1150 | 248059200 | 28.72022 | 0.10078 | 0.0613 | 0.0063 | -0.0186 | 0.0000 | 0.10078 |
2015-03-31 | 31.5225 | 31.6225 | 31.0900 | 31.1075 | 168362400 | 27.81922 | -0.03137 | -0.0112 | 0.0304 | -0.0037 | 0.0000 | -0.03137 |
2015-04-30 | 32.1600 | 32.1600 | 31.1450 | 31.2875 | 332781600 | 27.98019 | 0.00579 | 0.0059 | -0.0306 | 0.0182 | 0.0000 | 0.00579 |
2015-05-29 | 32.8075 | 32.8625 | 32.4750 | 32.5700 | 203538000 | 29.24879 | 0.04534 | 0.0136 | 0.0093 | -0.0114 | 0.0000 | 0.04534 |
2015-06-30 | 31.3925 | 31.5300 | 31.2150 | 31.3575 | 177482800 | 28.15993 | -0.03723 | -0.0153 | 0.0291 | -0.0079 | 0.0000 | -0.03723 |
2015-07-31 | 30.6500 | 30.6600 | 30.2275 | 30.3250 | 171540000 | 27.23272 | -0.03293 | 0.0154 | -0.0417 | -0.0413 | 0.0000 | -0.03293 |
2015-08-31 | 28.0075 | 28.6325 | 28.0000 | 28.1900 | 224917200 | 25.43001 | -0.06620 | -0.0604 | 0.0033 | 0.0277 | 0.0000 | -0.06620 |
2015-09-30 | 27.5425 | 27.8850 | 27.1825 | 27.5750 | 265892000 | 24.87522 | -0.02182 | -0.0307 | -0.0262 | 0.0056 | 0.0000 | -0.02182 |
2015-10-30 | 30.2475 | 30.3050 | 29.8625 | 29.8750 | 197461200 | 26.95004 | 0.08341 | 0.0775 | -0.0188 | -0.0046 | 0.0000 | 0.08341 |
2015-11-30 | 29.4975 | 29.8525 | 29.4375 | 29.5750 | 156721200 | 26.79361 | -0.00580 | 0.0056 | 0.0360 | -0.0042 | 0.0000 | -0.00580 |
2015-12-31 | 26.7525 | 26.7575 | 26.2050 | 26.3150 | 163649200 | 23.84020 | -0.11023 | -0.0217 | -0.0284 | -0.0261 | 0.0001 | -0.11033 |
2016-01-29 | 23.6975 | 24.3350 | 23.5875 | 24.3350 | 257666000 | 22.04641 | -0.07524 | -0.0577 | -0.0342 | 0.0209 | 0.0001 | -0.07534 |
2016-02-29 | 24.2150 | 24.5575 | 24.1625 | 24.1725 | 140865200 | 22.01802 | -0.00129 | -0.0007 | 0.0073 | -0.0057 | 0.0002 | -0.00149 |
2016-03-31 | 27.4300 | 27.4750 | 27.2200 | 27.2475 | 103553600 | 24.81894 | 0.12721 | 0.0696 | 0.0082 | 0.0119 | 0.0002 | 0.12701 |
2016-04-29 | 23.4975 | 23.6800 | 23.1275 | 23.4350 | 274126000 | 21.34626 | -0.13992 | 0.0091 | 0.0076 | 0.0328 | 0.0001 | -0.14002 |
2016-05-31 | 24.9000 | 25.1000 | 24.7050 | 24.9650 | 169228800 | 22.87833 | 0.07177 | 0.0178 | -0.0017 | -0.0166 | 0.0001 | 0.07167 |
2016-06-30 | 23.6100 | 23.9425 | 23.5750 | 23.9000 | 143345600 | 21.90235 | -0.04266 | -0.0005 | 0.0061 | -0.0148 | 0.0002 | -0.04286 |
2016-07-29 | 26.0475 | 26.1375 | 25.9200 | 26.0525 | 110934800 | 23.87494 | 0.09006 | 0.0395 | 0.0249 | -0.0132 | 0.0002 | 0.08986 |
2016-08-31 | 26.4150 | 26.6425 | 26.4100 | 26.5250 | 118649600 | 24.43963 | 0.02365 | 0.0049 | 0.0115 | 0.0318 | 0.0002 | 0.02345 |
2016-09-30 | 28.1150 | 28.3425 | 27.9500 | 28.2625 | 145516400 | 26.04053 | 0.06550 | 0.0025 | 0.0212 | -0.0124 | 0.0002 | 0.06530 |
2016-10-31 | 28.4125 | 28.5575 | 28.3000 | 28.3850 | 105677600 | 26.15340 | 0.00433 | -0.0202 | -0.0440 | 0.0409 | 0.0002 | 0.00413 |
2016-11-30 | 27.9000 | 28.0500 | 27.5675 | 27.6300 | 144649200 | 25.58846 | -0.02160 | 0.0486 | 0.0571 | 0.0821 | 0.0001 | -0.02170 |
2016-12-30 | 29.1625 | 29.3000 | 28.8575 | 28.9550 | 122345200 | 26.81556 | 0.04796 | 0.0182 | 0.0010 | 0.0353 | 0.0003 | 0.04766 |
2017-01-31 | 30.2875 | 30.3475 | 30.1550 | 30.3375 | 196804000 | 28.09590 | 0.04775 | 0.0194 | -0.0119 | -0.0275 | 0.0004 | 0.04735 |
2017-02-28 | 34.2700 | 34.3600 | 34.1750 | 34.2475 | 93931600 | 31.85452 | 0.13378 | 0.0357 | -0.0205 | -0.0167 | 0.0004 | 0.13338 |
2017-03-31 | 35.9300 | 36.0675 | 35.7525 | 35.9150 | 78646800 | 33.40550 | 0.04869 | 0.0017 | 0.0114 | -0.0335 | 0.0003 | 0.04839 |
2017-04-28 | 36.0225 | 36.0750 | 35.8175 | 35.9125 | 83441600 | 33.40317 | -0.00007 | 0.0109 | 0.0073 | -0.0213 | 0.0005 | -0.00057 |
2017-05-31 | 38.4925 | 38.5425 | 38.0950 | 38.1900 | 97804800 | 35.66814 | 0.06781 | 0.0106 | -0.0257 | -0.0378 | 0.0006 | 0.06721 |
2017-06-30 | 36.1125 | 36.2400 | 35.9450 | 36.0050 | 92096400 | 33.62743 | -0.05721 | 0.0078 | 0.0225 | 0.0148 | 0.0006 | -0.05781 |
2017-07-31 | 37.4750 | 37.5825 | 37.0325 | 37.1825 | 79383600 | 34.72719 | 0.03270 | 0.0187 | -0.0151 | -0.0031 | 0.0007 | 0.03200 |
2017-08-31 | 40.9100 | 41.1300 | 40.8700 | 41.0000 | 107140400 | 38.44297 | 0.10700 | 0.0016 | -0.0167 | -0.0210 | 0.0009 | 0.10610 |
2017-09-29 | 38.3025 | 38.5325 | 38.0000 | 38.5300 | 105199200 | 36.12701 | -0.06024 | 0.0251 | 0.0447 | 0.0313 | 0.0009 | -0.06114 |
2017-10-31 | 41.9750 | 42.4125 | 41.7350 | 42.2600 | 144187200 | 39.62438 | 0.09681 | 0.0225 | -0.0194 | 0.0020 | 0.0009 | 0.09591 |
2017-11-30 | 42.6075 | 43.0350 | 42.1100 | 42.9625 | 166108800 | 40.42789 | 0.02028 | 0.0312 | -0.0055 | -0.0003 | 0.0008 | 0.01948 |
2017-12-29 | 42.6300 | 42.6475 | 42.3050 | 42.3075 | 103999600 | 39.81153 | -0.01525 | 0.0106 | -0.0132 | 0.0006 | 0.0009 | -0.01615 |
2018-01-31 | 41.7175 | 42.1100 | 41.6250 | 41.8575 | 129915600 | 39.38808 | -0.01064 | 0.0557 | -0.0312 | -0.0129 | 0.0012 | -0.01184 |
2018-02-28 | 44.8150 | 45.1550 | 44.5125 | 44.5300 | 151128400 | 42.07376 | 0.06819 | -0.0365 | 0.0026 | -0.0104 | 0.0011 | 0.06709 |
2018-03-29 | 41.9525 | 42.9375 | 41.7250 | 41.9450 | 153594000 | 39.63134 | -0.05805 | -0.0235 | 0.0406 | -0.0021 | 0.0011 | -0.05915 |
2018-04-30 | 40.5325 | 41.8150 | 40.4600 | 41.3150 | 169709600 | 39.03609 | -0.01502 | 0.0028 | 0.0113 | 0.0054 | 0.0014 | -0.01642 |
2018-05-31 | 46.8050 | 47.0575 | 46.5350 | 46.7175 | 109931200 | 44.31080 | 0.13512 | 0.0265 | 0.0526 | -0.0322 | 0.0014 | 0.13372 |
2018-06-29 | 46.5725 | 46.7975 | 45.7275 | 46.2775 | 90950800 | 43.89347 | -0.00942 | 0.0048 | 0.0113 | -0.0233 | 0.0014 | -0.01082 |
2018-07-31 | 47.5750 | 48.0350 | 47.3350 | 47.5725 | 157492000 | 45.12177 | 0.02798 | 0.0319 | -0.0222 | 0.0045 | 0.0016 | 0.02638 |
2018-08-31 | 56.6275 | 57.2175 | 56.5000 | 56.9075 | 173360400 | 54.16517 | 0.20042 | 0.0344 | 0.0115 | -0.0400 | 0.0016 | 0.19882 |
2018-09-28 | 56.1975 | 56.4600 | 56.0050 | 56.4350 | 91717600 | 53.71543 | -0.00830 | 0.0006 | -0.0229 | -0.0170 | 0.0015 | -0.00980 |
2018-10-31 | 54.2200 | 55.1125 | 54.1550 | 54.7150 | 153435600 | 52.07832 | -0.03048 | -0.0768 | -0.0474 | 0.0341 | 0.0019 | -0.03238 |
2018-11-30 | 45.0725 | 45.0825 | 44.2575 | 44.6450 | 158126000 | 42.64185 | -0.18120 | 0.0169 | -0.0068 | 0.0028 | 0.0018 | -0.18300 |
2018-12-31 | 39.6325 | 39.8400 | 39.1200 | 39.4350 | 140014000 | 37.66563 | -0.11670 | -0.0957 | -0.0237 | -0.0188 | 0.0020 | -0.11870 |
2019-01-31 | 41.5275 | 42.2500 | 41.1400 | 41.6100 | 162958400 | 39.74304 | 0.05515 | 0.0840 | 0.0289 | -0.0044 | 0.0021 | 0.05305 |
2019-02-28 | 43.5800 | 43.7275 | 43.2300 | 43.2875 | 112861600 | 41.52258 | 0.04478 | 0.0340 | 0.0207 | -0.0270 | 0.0018 | 0.04298 |
2019-03-29 | 47.4575 | 47.5200 | 47.1350 | 47.4875 | 94256000 | 45.55134 | 0.09703 | 0.0110 | -0.0306 | -0.0413 | 0.0019 | 0.09513 |
2019-04-30 | 50.7650 | 50.8500 | 49.7775 | 50.1675 | 186139600 | 48.12208 | 0.05644 | 0.0397 | -0.0172 | 0.0215 | 0.0021 | 0.05434 |
2019-05-31 | 44.0575 | 44.4975 | 43.7475 | 43.7675 | 108174400 | 42.14468 | -0.12421 | -0.0694 | -0.0131 | -0.0237 | 0.0021 | -0.12631 |
2019-06-28 | 49.6700 | 49.8750 | 49.2625 | 49.4800 | 124442400 | 47.64538 | 0.13052 | 0.0693 | 0.0028 | -0.0070 | 0.0018 | 0.12872 |
2019-07-31 | 54.1050 | 55.3425 | 52.8250 | 53.2600 | 277125600 | 51.28523 | 0.07639 | 0.0119 | -0.0193 | 0.0047 | 0.0019 | 0.07449 |
2019-08-30 | 52.5400 | 52.6125 | 51.8000 | 52.1850 | 84573600 | 50.44101 | -0.01646 | -0.0258 | -0.0239 | -0.0479 | 0.0016 | -0.01806 |
2019-09-30 | 55.2250 | 56.1450 | 55.1975 | 55.9925 | 103909600 | 54.12127 | 0.07296 | 0.0143 | -0.0096 | 0.0675 | 0.0018 | 0.07116 |
2019-10-31 | 61.8100 | 62.2925 | 59.3150 | 62.1900 | 139162000 | 60.11165 | 0.11068 | 0.0206 | 0.0030 | -0.0190 | 0.0016 | 0.10908 |
2019-11-29 | 66.6500 | 67.0000 | 66.4750 | 66.8125 | 46617600 | 64.77354 | 0.07755 | 0.0388 | 0.0079 | -0.0201 | 0.0012 | 0.07635 |
2019-12-31 | 72.4825 | 73.4200 | 72.3800 | 73.4125 | 100805600 | 71.17213 | 0.09878 | 0.0277 | 0.0074 | 0.0177 | 0.0014 | 0.09738 |
2020-01-31 | 80.2325 | 80.6700 | 77.0725 | 77.3775 | 199588400 | 75.01614 | 0.05401 | -0.0011 | -0.0312 | -0.0628 | 0.0013 | 0.05271 |
2020-02-28 | 64.3150 | 69.6025 | 64.0925 | 68.3400 | 426510000 | 66.41167 | -0.11470 | -0.0813 | 0.0107 | -0.0380 | 0.0012 | -0.11590 |
2020-03-31 | 63.9000 | 65.6225 | 63.0000 | 63.5725 | 197002000 | 61.77869 | -0.06976 | -0.1338 | -0.0482 | -0.1383 | 0.0013 | -0.07106 |
2020-04-30 | 72.4900 | 73.6325 | 72.0875 | 73.4500 | 183064000 | 71.37748 | 0.15537 | 0.1365 | 0.0246 | -0.0134 | 0.0000 | 0.15537 |
2020-05-29 | 79.8125 | 80.2875 | 79.1175 | 79.4850 | 153532400 | 77.45129 | 0.08509 | 0.0558 | 0.0249 | -0.0486 | 0.0001 | 0.08499 |
2020-06-30 | 90.0200 | 91.4950 | 90.0000 | 91.2000 | 140223200 | 88.86655 | 0.14739 | 0.0246 | 0.0269 | -0.0221 | 0.0001 | 0.14729 |
2020-07-31 | 102.8850 | 106.4150 | 100.8250 | 106.2600 | 374336800 | 103.54124 | 0.16513 | 0.0577 | -0.0231 | -0.0141 | 0.0001 | 0.16503 |
2020-08-31 | 127.5800 | 131.0000 | 126.0000 | 129.0400 | 225702700 | 125.96510 | 0.21657 | 0.0763 | -0.0024 | -0.0297 | 0.0001 | 0.21647 |
2020-09-30 | 113.7900 | 117.2600 | 113.6200 | 115.8100 | 142675200 | 113.05035 | -0.10253 | -0.0363 | 0.0002 | -0.0270 | 0.0001 | -0.10263 |
2020-10-30 | 111.0600 | 111.9900 | 107.7200 | 108.8600 | 190272600 | 106.26595 | -0.06001 | -0.0210 | 0.0438 | 0.0423 | 0.0001 | -0.06011 |
2020-11-30 | 116.9700 | 120.9700 | 116.8100 | 119.0500 | 169410200 | 116.41364 | 0.09549 | 0.1247 | 0.0580 | 0.0206 | 0.0001 | 0.09539 |
2020-12-31 | 134.0800 | 134.7400 | 131.7200 | 132.6900 | 99116600 | 129.75159 | 0.11457 | 0.0463 | 0.0488 | -0.0151 | 0.0001 | 0.11447 |
2021-01-29 | 135.8300 | 136.7400 | 130.2100 | 131.9600 | 177523800 | 129.03775 | -0.00550 | -0.0003 | 0.0737 | 0.0304 | 0.0001 | -0.00560 |
2021-02-26 | 122.5900 | 124.8500 | 121.2000 | 121.2600 | 164560400 | 118.75188 | -0.07971 | 0.0278 | 0.0206 | 0.0709 | 0.0000 | -0.07971 |
2021-03-31 | 121.6500 | 123.5200 | 121.1500 | 122.1500 | 118323800 | 119.62349 | 0.00734 | 0.0308 | -0.0236 | 0.0740 | 0.0000 | 0.00734 |
2021-04-30 | 131.7800 | 133.5600 | 131.0700 | 131.4600 | 109839500 | 128.74092 | 0.07622 | 0.0493 | -0.0319 | -0.0097 | 0.0000 | 0.07622 |
2021-05-28 | 125.5700 | 125.8000 | 124.5500 | 124.6100 | 71311100 | 122.23987 | -0.05050 | 0.0029 | -0.0021 | 0.0708 | 0.0000 | -0.05050 |
2021-06-30 | 136.1700 | 137.4100 | 135.8700 | 136.9600 | 63261400 | 134.35495 | 0.09911 | 0.0275 | 0.0166 | -0.0784 | 0.0000 | 0.09911 |
2021-07-30 | 144.3800 | 146.3300 | 144.1100 | 145.8600 | 70440600 | 143.08565 | 0.06498 | 0.0127 | -0.0397 | -0.0184 | 0.0000 | 0.06498 |
2021-08-31 | 152.6600 | 152.8000 | 151.2900 | 151.8300 | 86453100 | 149.16527 | 0.04249 | 0.0291 | -0.0041 | -0.0019 | 0.0000 | 0.04249 |
2021-09-30 | 143.6600 | 144.3800 | 141.2800 | 141.5000 | 89056700 | 139.01660 | -0.06804 | -0.0437 | 0.0068 | 0.0515 | 0.0000 | -0.06804 |
2021-10-29 | 147.2200 | 149.9400 | 146.4100 | 149.8000 | 124953200 | 147.17090 | 0.05866 | 0.0665 | -0.0235 | -0.0045 | 0.0000 | 0.05866 |
2021-11-30 | 159.9900 | 165.5200 | 159.9200 | 165.3000 | 174048100 | 162.63591 | 0.10508 | -0.0155 | -0.0131 | -0.0044 | 0.0000 | 0.10508 |
2021-12-31 | 178.0900 | 179.2300 | 177.2600 | 177.5700 | 64062300 | 174.70816 | 0.07423 | 0.0310 | -0.0168 | 0.0325 | 0.0001 | 0.07413 |
2022-01-31 | 170.1600 | 175.0000 | 169.5100 | 174.7800 | 115541600 | 171.96310 | -0.01571 | -0.0625 | -0.0595 | 0.1288 | 0.0000 | -0.01571 |
2022-02-28 | 163.0600 | 165.4200 | 162.4300 | 165.1200 | 95056600 | 162.66579 | -0.05407 | -0.0229 | 0.0220 | 0.0311 | 0.0000 | -0.05407 |
2022-03-31 | 177.8400 | 178.0300 | 174.4000 | 174.6100 | 103049300 | 172.01472 | 0.05747 | 0.0305 | -0.0162 | -0.0181 | 0.0001 | 0.05737 |
2022-04-29 | 161.8400 | 166.2000 | 157.2500 | 157.6500 | 131747600 | 155.30682 | -0.09713 | -0.0946 | -0.0139 | 0.0620 | 0.0001 | -0.09723 |
2022-05-31 | 149.0700 | 150.6600 | 146.8400 | 148.8400 | 103718400 | 146.84317 | -0.05450 | -0.0034 | -0.0184 | 0.0848 | 0.0003 | -0.05480 |
2022-06-30 | 137.2500 | 138.3700 | 133.7700 | 136.7200 | 98964500 | 134.88580 | -0.08143 | -0.0843 | 0.0210 | -0.0601 | 0.0006 | -0.08203 |
2022-07-29 | 161.2400 | 163.6300 | 159.5000 | 162.5100 | 101786900 | 160.32979 | 0.18863 | 0.0957 | 0.0280 | -0.0405 | 0.0008 | 0.18783 |
2022-08-31 | 160.3100 | 160.5800 | 157.1400 | 157.2200 | 87991100 | 155.32623 | -0.03121 | -0.0377 | 0.0140 | 0.0029 | 0.0019 | -0.03311 |
2022-09-30 | 141.2800 | 143.1000 | 138.0000 | 138.2000 | 124925300 | 136.53531 | -0.12098 | -0.0935 | -0.0082 | 0.0005 | 0.0019 | -0.12288 |
2022-10-31 | 153.1600 | 154.2400 | 151.9200 | 153.3400 | 97943200 | 151.49295 | 0.10955 | 0.0783 | 0.0007 | 0.0802 | 0.0023 | 0.10725 |
2022-11-30 | 141.4000 | 148.7200 | 140.5500 | 148.0300 | 111380900 | 146.48955 | -0.03303 | 0.0460 | -0.0350 | 0.0138 | 0.0029 | -0.03593 |
2022-12-30 | 128.4100 | 129.9500 | 127.4300 | 129.9300 | 77034200 | 128.57790 | -0.12227 | -0.0641 | -0.0070 | 0.0136 | 0.0033 | -0.12557 |
2023-01-31 | 142.7000 | 144.3400 | 142.2800 | 144.2900 | 65874500 | 142.78842 | 0.11052 | 0.0665 | 0.0500 | -0.0402 | 0.0035 | 0.10702 |
2023-02-28 | 147.0500 | 149.0800 | 146.8300 | 147.4100 | 50547000 | 146.09869 | 0.02318 | -0.0258 | 0.0117 | -0.0080 | 0.0034 | 0.01978 |
2023-03-31 | 162.4400 | 165.0000 | 161.9100 | 164.9000 | 68749800 | 163.43311 | 0.11865 | 0.0251 | -0.0552 | -0.0887 | 0.0036 | 0.11505 |
2023-04-28 | 168.4900 | 169.8500 | 167.8800 | 169.6800 | 55209200 | 168.17061 | 0.02899 | 0.0061 | -0.0335 | -0.0005 | 0.0035 | 0.02549 |
2023-05-31 | 177.3300 | 179.3500 | 176.7600 | 177.2500 | 99625300 | 175.91628 | 0.04606 | 0.0035 | 0.0160 | -0.0772 | 0.0036 | 0.04246 |
2023-06-30 | 191.6300 | 194.4800 | 191.2600 | 193.9700 | 85069600 | 192.51045 | 0.09433 | 0.0646 | 0.0154 | -0.0025 | 0.0040 | 0.09033 |
2023-07-31 | 196.0600 | 196.4900 | 195.2600 | 196.4500 | 38824100 | 194.97179 | 0.01279 | 0.0321 | 0.0207 | 0.0409 | 0.0045 | 0.00829 |
2023-08-31 | 187.8400 | 189.1200 | 187.4800 | 187.8700 | 60794500 | 186.70815 | -0.04238 | -0.0239 | -0.0312 | -0.0112 | 0.0045 | -0.04688 |
2023-09-29 | 172.0200 | 173.0700 | 170.3400 | 171.2100 | 51814200 | 170.15115 | -0.08868 | -0.0524 | -0.0249 | 0.0151 | 0.0043 | -0.09298 |
2023-10-31 | 169.3500 | 170.9000 | 167.9000 | 170.7700 | 44846000 | 169.71388 | -0.00257 | -0.0318 | -0.0386 | 0.0017 | 0.0047 | -0.00727 |
2023-11-30 | 189.8400 | 190.3200 | 188.1900 | 189.9500 | 48794400 | 189.02396 | 0.11378 | 0.0884 | -0.0001 | 0.0161 | 0.0044 | 0.10938 |
2023-12-29 | 193.9000 | 194.4000 | 191.7300 | 192.5300 | 42628800 | 191.59138 | 0.01358 | 0.0487 | 0.0634 | 0.0493 | 0.0043 | 0.00928 |
2024-01-31 | 187.0400 | 187.1000 | 184.3500 | 184.4000 | 55467800 | 183.50102 | -0.04223 | 0.0070 | -0.0510 | -0.0233 | 0.0047 | -0.04693 |
2024-02-29 | 181.2700 | 182.5700 | 179.5300 | 180.7500 | 136682600 | 180.09834 | -0.01854 | 0.0506 | -0.0016 | -0.0354 | 0.0042 | -0.02274 |
2024-03-28 | 171.7500 | 172.2300 | 170.5100 | 171.4800 | 65672700 | 170.86176 | -0.05129 | 0.0283 | -0.0246 | 0.0416 | 0.0043 | -0.05559 |
2024-04-30 | 173.3300 | 174.9900 | 170.0000 | 170.3300 | 65934800 | 169.71590 | -0.00671 | -0.0467 | -0.0234 | -0.0054 | 0.0047 | -0.01141 |
2024-05-31 | 191.4400 | 192.5700 | 189.9100 | 192.2500 | 75158300 | 191.81670 | 0.13022 | 0.0434 | 0.0061 | -0.0137 | 0.0044 | 0.12582 |
2024-06-28 | 215.7700 | 216.0700 | 210.3000 | 210.6200 | 82542700 | 210.14528 | 0.09555 | 0.0278 | -0.0302 | -0.0331 | 0.0041 | 0.09145 |
2024-07-31 | 221.4400 | 223.8200 | 220.6300 | 222.0800 | 50036300 | 221.57947 | 0.05441 | NA | NA | NA | NA | NA |
2024-08-30 | 230.1900 | 230.4000 | 227.4800 | 229.0000 | 52990800 | 228.74834 | 0.03235 | NA | NA | NA | NA | NA |
Calculate annualized average excess return.
\[ \begin{aligned} r^A &= \big(1+\text{HPR}(T)\big)^{\frac{12}{T}}-1 \\ &= \left[\prod_{t=1}^T (1+r_{t}) \right]^{\frac{12}{T}}-1 \end{aligned} \] Note that the formula indicates \(\text{HPR}(T) = \left[\prod_{t=1}^T (1+r_{t}) \right]-1\), which is the holding period return for \(T\)-period.
n <- nrow(reg_data)-1 # number of months
r_A <- prod(reg_data$eRi+1, na.rm = TRUE)^{12/n}-1
r_A
## [1] 0.2315527
Plot excess return and ERP.
library(xts)
plot_data <- xts(reg_data[,c("eRi","rmrf")], order.by = reg_data$Date)
plot_data
## eRi rmrf
## 2014-08-29 0.000000000 0.0424
## 2014-09-30 -0.017073105 -0.0197
## 2014-10-31 0.071960286 0.0252
## 2014-11-28 0.105978772 0.0255
## 2014-12-31 -0.071890915 -0.0006
## 2015-01-30 0.061424124 -0.0311
## 2015-02-27 0.100776504 0.0613
## 2015-03-31 -0.031371661 -0.0112
## 2015-04-30 0.005786313 0.0059
## 2015-05-29 0.045339376 0.0136
## ...
## 2023-11-30 0.109380167 0.0884
## 2023-12-29 0.009282557 0.0487
## 2024-01-31 -0.046927173 0.0070
## 2024-02-29 -0.022743109 0.0506
## 2024-03-28 -0.055586355 0.0283
## 2024-04-30 -0.011406350 -0.0467
## 2024-05-31 0.125822330 0.0434
## 2024-06-28 0.091452593 0.0278
## 2024-07-31 NA NA
## 2024-08-30 NA NA
col_vec <- c("black", "red")
plot.xts(plot_data, col = col_vec, main = "Excess Returns on Asset and Market")
addLegend("topright",
legend.names = c("META", "Equity Risk Premium"),
lty = c(1, 1),
lwd = c(2, 2),
col = col_vec,
bg = "white",
box.col = "white")
CAPM as a regression can be expressed as
\[ r_{t} - r_{f,t} = \alpha + \beta (r_{m,t}-r_{f,t}) + \varepsilon_{t} \] where \(\alpha\) (intercept) and \(\beta\) (slope) are the parameters to estimate.
We use the following data to estimate the parameters.
capm_ml <- lm(eRi~rmrf, data=reg_data)
summary(capm_ml)
##
## Call:
## lm(formula = eRi ~ rmrf, data = reg_data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.212236 -0.036970 0.002496 0.041311 0.148802
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.009168 0.005620 1.631 0.106
## rmrf 1.187585 0.120201 9.880 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.05994 on 117 degrees of freedom
## (2 observations deleted due to missingness)
## Multiple R-squared: 0.4548, Adjusted R-squared: 0.4502
## F-statistic: 97.61 on 1 and 117 DF, p-value: < 2.2e-16
The Fama-French three-factor model as a regression can be expressed as
\[ r_{t} - r_{f,t} = \alpha + \beta^{RMRF} (r_{m,t}-r_{f,t}) + \beta^{SMB}SMB_t + \beta^{HML}HML_t + \varepsilon_{t} \]
FF_ml <- lm(eRi~rmrf+SMB+HML, data=reg_data)
summary(FF_ml)
##
## Call:
## lm(formula = eRi ~ rmrf + SMB + HML, data = reg_data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -0.210858 -0.028634 -0.001951 0.034289 0.128891
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.007119 0.005292 1.345 0.181
## rmrf 1.235424 0.117441 10.520 < 2e-16 ***
## SMB -0.214322 0.196916 -1.088 0.279
## HML -0.569461 0.137374 -4.145 6.52e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.05596 on 115 degrees of freedom
## (2 observations deleted due to missingness)
## Multiple R-squared: 0.5329, Adjusted R-squared: 0.5207
## F-statistic: 43.74 on 3 and 115 DF, p-value: < 2.2e-16
Merge the two models in one table.
library(stargazer)
stargazer(capm_ml, FF_ml, type="html",
title="Regression Results for AAPL",
align = TRUE)
Dependent variable: | ||
eRi | ||
(1) | (2) | |
rmrf | 1.188*** | 1.235*** |
(0.120) | (0.117) | |
SMB | -0.214 | |
(0.197) | ||
HML | -0.569*** | |
(0.137) | ||
Constant | 0.009 | 0.007 |
(0.006) | (0.005) | |
Observations | 119 | 119 |
R2 | 0.455 | 0.533 |
Adjusted R2 | 0.450 | 0.521 |
Residual Std. Error | 0.060 (df = 117) | 0.056 (df = 115) |
F Statistic | 97.614*** (df = 1; 117) | 43.737*** (df = 3; 115) |
Note: | p<0.1; p<0.05; p<0.01 |
Excel can achieve the same results. You use Analysis ToolPak
\(\rightarrow\) Regression
to conduct the regression. It will generate similar regression tables for you.
Analysis ToolPak
: