It performs arithmetic operation on numeric columns on multiple series.

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

Arguments

dt

a list/dataframe of time series datasets.

opr

operation string.

x

the date column name, defaults to date.

y

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 农业银行/中国银行 2010-07-15 0.7826087
#>    2: 601288.SS/601988.SS 农业银行/中国银行 2010-07-16 0.7842566
#>    3: 601288.SS/601988.SS 农业银行/中国银行 2010-07-19 0.7832370
#>    4: 601288.SS/601988.SS 农业银行/中国银行 2010-07-20 0.7698864
#>    5: 601288.SS/601988.SS 农业银行/中国银行 2010-07-21 0.7677054
#>   ---                                                           
#> 1812: 601288.SS/601988.SS 农业银行/中国银行 2017-12-25 0.9387755
#> 1813: 601288.SS/601988.SS 农业银行/中国银行 2017-12-26 0.9518987
#> 1814: 601288.SS/601988.SS 农业银行/中国银行 2017-12-27 0.9566327
#> 1815: 601288.SS/601988.SS 农业银行/中国银行 2017-12-28 0.9618321
#> 1816: 601288.SS/601988.SS 农业银行/中国银行 2017-12-29 0.9647355
#> 

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 2010-07-15 3.075
#>    2: (601288.SS+601988.SS)/2 (农业银行+中国银行)/2 2010-07-16 3.060
#>    3: (601288.SS+601988.SS)/2 (农业银行+中国银行)/2 2010-07-19 3.085
#>    4: (601288.SS+601988.SS)/2 (农业银行+中国银行)/2 2010-07-20 3.115
#>    5: (601288.SS+601988.SS)/2 (农业银行+中国银行)/2 2010-07-21 3.120
#>   ---                                                               
#> 1812: (601288.SS+601988.SS)/2 (农业银行+中国银行)/2 2017-12-25 3.800
#> 1813: (601288.SS+601988.SS)/2 (农业银行+中国银行)/2 2017-12-26 3.855
#> 1814: (601288.SS+601988.SS)/2 (农业银行+中国银行)/2 2017-12-27 3.835
#> 1815: (601288.SS+601988.SS)/2 (农业银行+中国银行)/2 2017-12-28 3.855
#> 1816: (601288.SS+601988.SS)/2 (农业银行+中国银行)/2 2017-12-29 3.900
#> 
#> $`(601288.SS*601988.SS)^0.5`
#>                          symbol                    name       date    close
#>    1: (601288.SS*601988.SS)^0.5 (农业银行*中国银行)^0.5 2010-07-15 3.052048
#>    2: (601288.SS*601988.SS)^0.5 (农业银行*中国银行)^0.5 2010-07-16 3.037548
#>    3: (601288.SS*601988.SS)^0.5 (农业银行*中国银行)^0.5 2010-07-19 3.062123
#>    4: (601288.SS*601988.SS)^0.5 (农业银行*中国银行)^0.5 2010-07-20 3.088560
#>    5: (601288.SS*601988.SS)^0.5 (农业银行*中国银行)^0.5 2010-07-21 3.092944
#>   ---                                                                      
#> 1812: (601288.SS*601988.SS)^0.5 (农业银行*中国银行)^0.5 2017-12-25 3.798105
#> 1813: (601288.SS*601988.SS)^0.5 (农业银行*中国银行)^0.5 2017-12-26 3.853829
#> 1814: (601288.SS*601988.SS)^0.5 (农业银行*中国银行)^0.5 2017-12-27 3.834058
#> 1815: (601288.SS*601988.SS)^0.5 (农业银行*中国银行)^0.5 2017-12-28 3.854270
#> 1816: (601288.SS*601988.SS)^0.5 (农业银行*中国银行)^0.5 2017-12-29 3.899372
#>