It performs arithmetic operation on numeric columns on multiple series.

pq_opr(dt, opr, x = "close", rm_na = FALSE, ...)

Arguments

dt

a list/dataframe of time series datasets.

opr

operation string.

x

the numeric column names, defaults to close.

rm_na

weather to remove NA values when perform arithmetic.

...

additional parameters.

Examples

data("dt_banks")

dt1 = pq_opr(dt_banks, '601288.SS/601988.SS')
print(dt1)
#> $`601288.SS/601988.SS`
#>                    symbol              name       date     close
#>    1: 601288.SS/601988.SS 农业银行/中国银行 2013-12-31 0.9465649
#>    2: 601288.SS/601988.SS 农业银行/中国银行 2014-01-02 0.9463602
#>    3: 601288.SS/601988.SS 农业银行/中国银行 2014-01-03 0.9609375
#>    4: 601288.SS/601988.SS 农业银行/中国银行 2014-01-06 0.9644269
#>    5: 601288.SS/601988.SS 农业银行/中国银行 2014-01-07 0.9642857
#>   ---                                                           
#> 1217: 601288.SS/601988.SS 农业银行/中国银行 2018-12-24 0.9832869
#> 1218: 601288.SS/601988.SS 农业银行/中国银行 2018-12-25 0.9861496
#> 1219: 601288.SS/601988.SS 农业银行/中国银行 2018-12-26 0.9889807
#> 1220: 601288.SS/601988.SS 农业银行/中国银行 2018-12-27 0.9917355
#> 1221: 601288.SS/601988.SS 农业银行/中国银行 2018-12-28 0.9972299
#> 

dt2 = pq_opr(dt_banks, c('(601288.SS+601988.SS)/2', '(601288.SS*601988.SS)^0.5'))
print(dt2)
#> $`(601288.SS+601988.SS)/2`
#>                        symbol                  name       date close
#>    1: (601288.SS+601988.SS)/2 (农业银行+中国银行)/2 2013-12-31 2.550
#>    2: (601288.SS+601988.SS)/2 (农业银行+中国银行)/2 2014-01-02 2.540
#>    3: (601288.SS+601988.SS)/2 (农业银行+中国银行)/2 2014-01-03 2.510
#>    4: (601288.SS+601988.SS)/2 (农业银行+中国银行)/2 2014-01-06 2.485
#>    5: (601288.SS+601988.SS)/2 (农业银行+中国银行)/2 2014-01-07 2.475
#>   ---                                                               
#> 1217: (601288.SS+601988.SS)/2 (农业银行+中国银行)/2 2018-12-24 3.560
#> 1218: (601288.SS+601988.SS)/2 (农业银行+中国银行)/2 2018-12-25 3.585
#> 1219: (601288.SS+601988.SS)/2 (农业银行+中国银行)/2 2018-12-26 3.610
#> 1220: (601288.SS+601988.SS)/2 (农业银行+中国银行)/2 2018-12-27 3.615
#> 1221: (601288.SS+601988.SS)/2 (农业银行+中国银行)/2 2018-12-28 3.605
#> 
#> $`(601288.SS*601988.SS)^0.5`
#>                          symbol                    name       date    close
#>    1: (601288.SS*601988.SS)^0.5 (农业银行*中国银行)^0.5 2013-12-31 2.549039
#>    2: (601288.SS*601988.SS)^0.5 (农业银行*中国银行)^0.5 2014-01-02 2.539035
#>    3: (601288.SS*601988.SS)^0.5 (农业银行*中国银行)^0.5 2014-01-03 2.509502
#>    4: (601288.SS*601988.SS)^0.5 (农业银行*中国银行)^0.5 2014-01-06 2.484593
#>    5: (601288.SS*601988.SS)^0.5 (农业银行*中国银行)^0.5 2014-01-07 2.474591
#>   ---                                                                      
#> 1217: (601288.SS*601988.SS)^0.5 (农业银行*中国银行)^0.5 2018-12-24 3.559874
#> 1218: (601288.SS*601988.SS)^0.5 (农业银行*中国银行)^0.5 2018-12-25 3.584913
#> 1219: (601288.SS*601988.SS)^0.5 (农业银行*中国银行)^0.5 2018-12-26 3.609945
#> 1220: (601288.SS*601988.SS)^0.5 (农业银行*中国银行)^0.5 2018-12-27 3.614969
#> 1221: (601288.SS*601988.SS)^0.5 (农业银行*中国银行)^0.5 2018-12-28 3.604997
#>