pedquant (version 0.1.3)

pq_return: calculating returns by frequency

Description

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

Usage

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 calculate 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

Run this code
# NOT RUN {
dts = md_stock(c('000001', '^000001'), source = '163')

# set freq
dts_returns1 = pq_return(dts, freq = 'all')
dts_returns2 = pq_return(dts, freq = 'weekly')

# set method
dts_returns3 = pq_return(dts, freq = 'monthly', method = 'arithmetic') # default method
dts_returns4 = pq_return(dts, freq = 'monthly', method = 'log')
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab