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 Correlation
#> 1: 601288.SS 0.0048 0.6490 0.9538 0.4703    0.4898           0.0592      0.6998
#> 2: 601328.SS 0.0057 0.7513 0.9886 0.5825    0.4789           0.0701      0.6920
#> 3: 601398.SS 0.0051 0.6739 0.7942 0.6160    0.5239           0.0625      0.7238
#> 4: 601939.SS 0.0061 0.9472 1.1829 0.7994    0.5138           0.0763      0.7168
#> 5: 601988.SS 0.0040 0.7474 0.9353 0.7874    0.5312           0.0485      0.7289
#>    Correlation p-value Tracking Error Active Premium Information Ratio
#> 1:                   0         0.1788         0.0440            0.2459
#> 2:                   0         0.1961         0.0522            0.2661
#> 3:                   0         0.1719         0.0478            0.2782
#> 4:                   0         0.2202         0.0566            0.2571
#> 5:                   0         0.1780         0.0328            0.1842
#>    Treynor Ratio
#> 1:        0.1192
#> 2:        0.1139
#> 3:        0.1205
#> 4:        0.0950
#> 5:        0.0886