In DolphinDB, how to calculate the output value of a factor function based on its previous value?

21 Views Asked by At

Suppose there is a factor defined as follows:

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

I intend to calculate the current factor value based on the previous one, similar to recursive calculation, as shown below:

ouput[i] = close * α + output[i-1]

How to achieve this in DolphinDB?

1

There are 1 best solutions below

0
On BEST ANSWER

You can use the iterate function, please see https://docs.dolphindb.cn/en/help200/FunctionsandCommands/FunctionReferences/i/iterate.html?highlight=iterate

Here is an example script:

close = 1..5
alpha = 2
output = iterate(init=close[0], coeffs=1, input=([0]<-close[1:])*alpha)