pq_return calculates returns for daily series based on specified column, frequency and method type.

pq_return(dt, x, freq = "monthly", date_type = "eop",
  method = "arithmetic", cumreturns = FALSE, rcol_name = "returns",
  cols_keep = NULL, date_range = "max", from = NULL, to = Sys.Date())

Arguments

dt

a list/dataframe of daily series dataset

x

the column name of adjusted asset price.

freq

the frequency of returns. It supports c('all', 'daily', 'weekly', 'monthly', 'quarterly', 'yearly').

date_type

the available date type are eop (end of period) and bop (bebinning of period), defaults to the eop.

method

the method to calculate asset returns, the available methods including arithmetic and log, defaults to arithmetic.

cumreturns

logical, whether to return cumulative returns. Defaults to FALSE.

rcol_name

setting the column name of returns, defaults to returns.

cols_keep

the columns keep in the return data. The columns of symbol, name and date will always kept if they are exist in the input data.

date_range

date range. Available value includes '1m'-'11m', 'ytd', 'max' and '1y'-'ny'. Default is max.

from

the start date. Default is NULL. If it is NULL, then calculate using date_range and end date.

to

the end date. Default is the current date.

Examples

# \donttest{
data(dt_banks)

# create a close_adj column
datadj = md_stock_adjust(dt_banks, adjust = FALSE)

# set freq
dts_returns1 = pq_return(datadj, x = 'close_adj', freq = 'all')

# set method
dts_returns2 = pq_return(datadj, x = 'close_adj', method = 'log')

# set cols_keep
dts_returns3 = pq_return(datadj, x = 'close_adj', cols_keep = 'cap_total')

# }