使用SMA在SQL查询中报告的错误:X必须是数值向量。

huangapple go评论76阅读模式
英文:

Error reported when using sma in a SQL query: X must be a numeric vector

问题

以下是您的脚本:

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)

错误消息报告了X必须是数值向量。是否有人可以帮助我确定此问题的原因并修改我的脚本?

英文:

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

得分: 1

cols 是一个字符串,不能直接在 SQL 查询中用作列引用。要根据给定的列名查询列,请使用元编程:

col="xxx"
sql(select=[sqlCol("trade_date"), sqlCol("symbol"), sqlColAlias(makeUnifiedCall(sma, [sqlCol(col), 5]), 'aaa')], from="data_table")
英文:

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" )

huangapple
  • 本文由 发表于 2023年7月18日 15:09:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/76710277.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定