pq_portfolio calculates the weight returns or the wealth index of a portfolio of assets.

pq_portfolio(dt, w = NULL, rcol = "returns", wcol = "weights",
  wealthindex = FALSE, method = "arithmetic")

Arguments

dt

a list/dataframe of returns by asset

w

a dataframe of weights by asset. If it is NULL, then the weights by asset are equal.

rcol

the returns column name

wcol

the weights column name

wealthindex

logical, whether to return a wealth index. Defaults to FALSE.

method

the method to calculate asset returns, the available values include arithmetic and log, defaults to arithmetic.

Examples

library(pedquant)
library(data.table)

data(dt_banks)
datadj = md_stock_adjust(dt_banks, adjust = FALSE)

dt = pq_return(datadj, x = 'close_adj', freq = 'monthly')
w = data.table(
   symbol = c("601288.SS","601328.SS","601398.SS","601939.SS","601988.SS"), 
   weights = c(0.1, 0.2, 0.3, 0.3, 0.1)
   )

ret = pq_portfolio(dt, w)
retidx = pq_portfolio(dt, w, wealthindex = TRUE)
pq_plot(retidx, x = 'wealthindex')
#> $symbol

#>