if (FALSE) {
library(pedquant)
library(data.table)
# load data
data(dt_banks)
data(dt_ssec)
# calculate returns
datret1 = pq_return(dt_banks, 'close', freq = 'monthly', rcol_name = 'Ra')
datret2 = pq_return(dt_ssec, 'close', freq = 'monthly', rcol_name = 'Rb')
# merge returns of assets and baseline
datRaRb = merge(
rbindlist(datret1)[, .(date, symbol, Ra)],
rbindlist(datret2)[, .(date, Rb)],
by = 'date', all.x = TRUE
)
# claculate table.CAPM metrics
perf_capm = pq_performance(datRaRb, Ra = 'Ra', Rb = 'Rb', perf_fun = 'table.CAPM')
rbindlist(perf_capm, idcol = 'symbol')
}
Run the code above in your browser using DataLab