pq_performance
calculates performance metrics based on returns of market price or portfolio. The performance analysis functions are calling from PerformanceAnalytics
package, which includes many widely used performance metrics.
pq_performance(dt, Ra, Rb = NULL, perf_fun, ...)
a list/dataframe of time series datasets.
the column name of asset returns.
the column name of baseline returns, defaults to NULL.
performance function from PerformanceAnalytics
package, see pq_perf_funs
.
additional parameters, the arguments used in PerformanceAnalytics
functions.
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')
#> symbol Alpha Beta Beta+ Beta- R-squared Annualized Alpha
#> 1: 601328.SS -0.0024 0.9744 1.2088 0.8993 0.6584 -0.0282
#> 2: 601398.SS 0.0003 0.6492 0.7433 0.6784 0.6354 0.0035
#> 3: 601939.SS 0.0022 0.8753 1.0881 0.8821 0.6286 0.0269
#> 4: 601988.SS -0.0013 0.7135 0.8570 0.8227 0.6307 -0.0152
#> 5: 601288.SS 0.0019 0.6059 0.8592 0.5884 0.5217 0.0225
#> Correlation Correlation p-value Tracking Error Active Premium
#> 1: 0.8114 0 0.1945 -0.0418
#> 2: 0.7971 0 0.1673 0.0194
#> 3: 0.7929 0 0.1895 0.0215
#> 4: 0.7941 0 0.1708 -0.0046
#> 5: 0.7223 0 0.1597 0.0039
#> Information Ratio Treynor Ratio
#> 1: -0.2148 -0.0896
#> 2: 0.1162 -0.0403
#> 3: 0.1134 -0.0275
#> 4: -0.0267 -0.0703
#> 5: 0.0247 0.0788