pq_return
calculates returns for daily series based on specified column, frequency and method type.
pq_return(dt, x, freq = "daily", n = 1, date_type = "eop",
method = "arithmetic", cumreturns = FALSE, rcol_name = NULL,
cols_keep = NULL, date_range = "max", from = NULL, to = Sys.Date(),
...)
a list/dataframe of daily series.
the column name of adjusted asset price.
the frequency of returns. It supports 'daily', 'weekly', 'monthly', 'quarterly', 'yearly' and 'all'. Defaults to daily.
the number of preceding periods used as the base value, defaults to 1, which means based on the previous period value.
the available date type are eop (end of period) and bop (beginning of period), defaults to the eop.
the method to calculate asset returns, the available methods including arithmetic and log, defaults to arithmetic.
logical, whether to return cumulative returns. Defaults to FALSE.
setting the column name of returns, defaults to NULL.
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. Available value includes '1m'-'11m', 'ytd', 'max' and '1y'-'ny'. Default is max.
the start date. Default is NULL. If it is NULL, then calculate using date_range and end date.
the end date. Default is the current date.
ignored
# \donttest{
# load data and adjust
data(dt_banks)
datadj = md_stock_adjust(dt_banks)
# 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')
# cumulative returns
dts_cumreturns = pq_return(datadj, x = 'close_adj', from = '2012-01-01', cumreturns = TRUE)
e1 = pq_plot(dts_cumreturns, y = 'cumreturns.daily', title='cumreturns',
arrange = list(rows=1, cols=1))
e1[[1]]
#> NULL
# }