DolphinDB error: mstd(X, window, [minPeriods]). window must be at least 2

DolphinDB error: mstd(X, window, [minPeriods]). window must be at least 2

我写的代码是:

t = table(1:0, `Id`Factor`DataSource`Parameter, [INT, STRING, STRING, DOUBLE[]]);
insert into t values(0, "f1", "tt", [[100, 14, 14]]);

Date = 2021.01.02 2021.01.02  2021.01.04  2021.01.05 2021.01.07 2021.01.08
X = 1 4 10 -1 2 4
tt = table(Date,X as x)
def f1(tt, params){
 a = select Date, mstd(x,params[0]), mstd(x,params[1]), mstd(x,params[2]) from tt ;  
 return a
}

def f(func_name, table_name, params){
 return funcByName(func_name)(objByName(table_name), params);
}
each(f, t.Factor, t.DataSource, t.Parameter)

但是报错:

each(f, t."Factor", t."DataSource", t."Parameter") => f: return funcByName(func_name) ( objByName(table_name), params ) => f1: a = select Date,mstd(x, params[0]) as mstd_x from tt => Usage: mstd(X, window, [minPeriods]). window must be at least 2.

我在列中使用 arrayvector 创建 table,不确定是否是问题所在。我该如何解决?

您代码中params的数据类型为double类型。改成int类型,因为函数mstd的参数window应该是int。

修改后的代码为:

def f1(tt, params){
a = select Date, mstd(x,int(params[0])) as mstd1, mstd(x,int(params[1])) as mstd2, mstd(x,int(params[2])) as mstd3 from tt ;
 return a
}