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, ...)

Arguments

dt

a list/dataframe of time series datasets.

Ra

the column name of asset returns.

Rb

the column name of baseline returns, defaults to NULL.

perf_fun

performance function from PerformanceAnalytics package, see pq_perf_funs.

...

additional parameters, the arguments used in PerformanceAnalytics functions.

Examples

 
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: 601288.SS  0.0019 0.6059 0.8592 0.5884    0.5217           0.0225
#> 2: 601328.SS -0.0024 0.9744 1.2088 0.8993    0.6584          -0.0282
#> 3: 601398.SS  0.0003 0.6492 0.7433 0.6784    0.6354           0.0035
#> 4: 601939.SS  0.0022 0.8753 1.0881 0.8821    0.6286           0.0269
#> 5: 601988.SS -0.0013 0.7135 0.8570 0.8227    0.6307          -0.0152
#>    Correlation Correlation p-value Tracking Error Active Premium
#> 1:      0.7223                   0         0.1597         0.0039
#> 2:      0.8114                   0         0.1945        -0.0418
#> 3:      0.7971                   0         0.1673         0.0194
#> 4:      0.7929                   0         0.1895         0.0215
#> 5:      0.7941                   0         0.1708        -0.0046
#>    Information Ratio Treynor Ratio
#> 1:            0.0247        0.0788
#> 2:           -0.2148       -0.0896
#> 3:            0.1162       -0.0403
#> 4:            0.1134       -0.0275
#> 5:           -0.0267       -0.0703