因子函数类似递归的需求怎么实现

请问自己写因子函数的时候,例如

@state
def abc(close){
    ....
    return value
}

, 这个因子函数的输出值value,要依赖于上一个的value结果值,类似递归的需求。请问这种在DDB里面要怎么写啊?例如下图需求:

attachments-2023-11-9vbX2AHD6550e593af0a6.png

第一个output是close[0]

请先 登录 后评论

1 个回答

wale

可以用iterate函数:https://docs.dolphindb.cn/zh/help/200/FunctionsandCommands/FunctionReferences/i/iterate.html

close = 1..5
alpha = 2
output = iterate(init=close[0], coeffs=1, input=([0]<-close[1:])*alpha)
请先 登录 后评论