pq_addti: adding technical indicators

pq_addtiR Documentation

adding technical indicators

Description

pq_addti creates technical indicators using the functions provided in TTR package.

Usage

pq_addti(dt, ...)

Arguments

dt

a list/dataframe of time series datasets.

...

list of technical indicator parameters: sma = list(n=50), macd = list().

  1. There are four types of parameters.

    • set by default and do not required, such as 'OHLC', 'HLC', 'HL' and 'volume'.

    • set by default and can be modified, such as 'price', 'prices', 'x'. Its default value is 'close' or 'value' column.

    • always required, such as 'y', 'w'.

    • numeric parameters, such as 'n', 'sd', 'v', 'nFast', 'nSlow', 'nSig', 'accel'. These parameters should be provided, otherwise using default values in corresponding function.

  2. TTR functions are summarized in below. See TTR package's help document for more detailed parameters.

    • moving averages: SMA, EMA, DEMA, WMA, EVWMA, ZLEMA, VWAP, VMA, HMA, ALMA, GMMA

    • rolling functions: runMin, runMax, runMean, runMedian; runCov, runCor; runVar, runSD, runMAD; runSum, wilderSum

    • bands / channels: BBands, PBands, DonchianChannel

    • SAR, ZigZag

    • trend direction/strength: aroon, CCI, ADX, TDI, VHF, EMV

    • volatility measures: ATR, chaikinVolatility, volatility, SNR

    • money flowing into/out: OBV, chaikinAD, CLV, CMF, MFI, williamsAD

    • rate of change / momentum: ROC, momentum, KST, TRIX

    • oscillator: MACD, DPO, DVI, ultimateOscillator; RSI, CMO; stoch, SMI, WPR

Examples


# load data
data('dt_ssec')

# add technical indicators
dt_ti1 = pq_addti(dt_ssec, sma=list(n=20), sma=list(n=50), macd = list())

# specify the price column x
dt_ti11 = pq_addti(dt_ssec, sma=list(n=20, x='open'), sma=list(n=50, x='open'))
dt_ti12 = pq_addti(dt_ssec, x='open', sma=list(n=20), sma=list(n=50))

# only technical indicators
dt_ti2 = pq_addti(
  dt_ssec, sma=list(n=20), sma=list(n=50), macd = list(), 
  col_kp = c('symbol', 'name')
)

dt_ti3 = pq_addti(
  dt_ssec, sma=list(n=20), sma=list(n=50), macd = list(), 
  col_kp = NULL
)

# self-defined technical indicators
bias = function(x, n=50, maType='SMA') {
    library(TTR)
    (x/do.call(maType, list(x=x, n=n))-1)*100
}

dt_ti3 = pq_addti(dt_ssec, bias = list(n = 200))



ShichenXie/getpedr documentation built on March 5, 2024, 5:10 a.m.