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

pq_return(dt, x = "close|value", method = "arithmetic", freq = "all",
  date_range = "max", from = NULL, to = Sys.Date(),
  print_step = 1L)

Arguments

dt

a list/dataframe of daily series dataset

x

the variable used to calculate returns.

method

the method to calcualte returns.

freq

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

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.

print_step

a non-negative integer. Print symbol name by each print_step iteration. Default is 1L.

Examples

dts = md_stock(c('000001', '^000001'), source = '163')
#> 1/2 000001 #> 2/2 ^000001
# set freq dts_returns1 = pq_return(dts, freq = 'all')
#> 1/2 000001.SZ #> 2/2 000001.SS
dts_returns2 = pq_return(dts, freq = 'weekly')
#> 1/2 000001.SZ #> 2/2 000001.SS
# set method dts_returns3 = pq_return(dts, freq = 'monthly', method = 'arithmetic') # default method
#> 1/2 000001.SZ #> 2/2 000001.SS
dts_returns4 = pq_return(dts, freq = 'monthly', method = 'log')
#> 1/2 000001.SZ #> 2/2 000001.SS