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.SH -0.0029 0.0724  0.0968  0.0964    0.0113          -0.0347
#> 2: 601328.SH -0.0001 0.1147 -0.0257  0.3716    0.0155          -0.0012
#> 3: 601398.SH -0.0047 0.2386  0.2711  0.4381    0.0802          -0.0545
#> 4: 601939.SH -0.0023 0.2817  0.1165  0.3164    0.0575          -0.0269
#> 5: 601988.SH -0.0009 0.0969  0.1387 -0.0737    0.0219          -0.0105
#>    Correlation Correlation p-value Tracking Error Active Premium
#> 1:      0.1062              0.5436         0.1771        -0.0832
#> 2:      0.1245              0.4762         0.1963        -0.0520
#> 3:      0.2832              0.0993         0.1712        -0.0967
#> 4:      0.2398              0.1652         0.2078        -0.0741
#> 5:      0.1480              0.3962         0.1714        -0.0573
#>    Information Ratio Treynor Ratio
#> 1:           -0.4698       -0.4961
#> 2:           -0.2647       -0.0406
#> 3:           -0.5648       -0.2070
#> 4:           -0.3566       -0.0952
#> 5:           -0.3341       -0.1026