1

Here is my script:

def ma process(data table){
  cols = open'high'low'close' volume'amount'vwap
     base_table = select trade date, symbol from data_table
     for(col in cols){
     print(col)
        data = select trade_date, symbol, sma(col,5) as aaa from data_table
        base table = lj(base,table,data,trade date'symbol)
    }
}
stock_db = database('dfs://stock db')
data_table = stock_db.loadTable('stock daily_hfq')
ma_process(data table)

An error message was reported: X must be a numeric vector. Can anyone help me identify the cause of this issue and modify my script?

1 Answers1

1

cols is a string and cannot be directly used in the SQL query as a column reference. To query a column based on the given column name, use metaprogramming:

col="xxx"
sql(select=[sqlCol("trade_date"),sqlCol("symbol"), sqlColAlias(makeUnifiedCall(sma, [sqlCol(col), 5]), `aaa) ], from="data_table" )
dontyousee
  • 458
  • 2
  • 9