Open kzk2000 opened 2 years ago
Here is one way to do something similar. We currently do not have a way to supply a rolling window to an aggregator so I am going to leave this issue open. In the mean time, below explains my thinking around your issue.
I made a new table that is the np random values like you provided in your example.
Then a function my_function
that can do whatever calculation needed. This just sums array elements but can be a function of any complexity. Just use any python function notation you like.
Since you wanted to add to the original table I have the meat as one line.
The _
will access the array elements of the column and .subVector
in this case takes 3 values for the calculations.
We have built in support for mean(avg) , median and sum.
Since the first two rows are NAN, just show values that makes sense by applying a where filter out the first two rows.
Then drop those from the table since they clutter the screen.
import numpy as np
from deephaven.TableTools import newTable, doubleCol
def my_function(A):
total = 0
for i in range(0, len(A)):
total = total + A[i]
return total
dh_table = newTable(\
doubleCol("X", np.random.randn(10,1)))\
.update("A= X_.subVector(i-2,i+1)",\
"rolling_mean = avg(A)", \
"rolling_median =median(A)", \
"rolling_sum = sum(A)", \
"FuncX=my_function(A)")\
.where("X_[i-2]>=-10").dropColumns("A")
As heavy pandas user, and after searching the docs for it, I'm still having trouble of doing something simple as below using Deephaven's dynamic tables. Is there a native way to apply arbitrary Python funcs as a rolling window? NOTE: this is not an EMA that can be updated with just the last tick.
Thanks for any pointers in advance!
yields