'Apply ta_py function to Cudf dataframe - RAPIDS
trying to create a new column on a cudf dataframe based on VWMA from ta_py :
#creating df
CJ_m30 = cudf.read_csv("/media/f333a/Data/CJ_m30.csv",
names = ["DateTime","Bid","Ask","Open", "High", "Low", "Close"])
#trying to create new column based on func
import ta_py as ta
length = 40
def process_vwma(data):
VWMA = ta.vwma(data,length)
return VWMA
CJ_m30['VWMA'] = CJ_m30['Close'].apply(process_vwma, axis = 0)
returns error :
ValueError: UDFs using *args or **kwargs are not yet supported.
updated: now error is :
TypingError: Failed in cuda mode pipeline (step: nopython frontend) Failed in cuda mode pipeline (step: nopython frontend) Unknown attribute 'vwma' of type Module(<module 'ta_py' from '/home/f320x/anaconda3/envs/rapids-22.02/lib/python3.9/site-packages/ta_py/init.py'>)
File "../../../../../tmp/ipykernel_3478/1395824149.py", line 6:
During: typing of get attribute at /tmp/ipykernel_3478/1395824149.py (6)
File "../../../../../tmp/ipykernel_3478/1395824149.py", line 6:
During: resolving callee type: type(<numba.cuda.compiler.Dispatcher object at 0x7f05b67a47c0>) During: typing of call at /home/f320x/anaconda3/envs/rapids-22.02/lib/python3.9/site-packages/cudf/core/series.py (2495)
File "../../../anaconda3/envs/rapids-22.02/lib/python3.9/site-packages/cudf/core/series.py", line 2495: >>> def f(x):
return df.apply(lambda row: f_(row[name])) ^
Can someone give an explanation ? Thank you
Solution 1:[1]
Building on Nick's comment, the data used in VWMA in ta_py
, https://github.com/Bitvested/ta.py#vwma, is structured very differently than you have it as or are passing into it. It's an array with price (close), but also volume, which you don't have. The data you're giving it is for is SMA - but not in the way the functions should be used, as Nick said.
If you want to use Close for SMA, borrowing from https://www.datacamp.com/community/tutorials/moving-averages-in-pandas
import cudf
product = {'day' : [1,2,3,4,5,6,7,8,9,10,11,12],'close':[290,260,288,300,310,303,329,340,316,330,308,310]}
df = cudf.DataFrame(product)
print(df.head())
df['SMA'] = df.iloc[:,1].rolling(window=3).mean() # you change your window size , eg from "3" in this example to "40"
print(df.head())
which outputs this:
day close SMA
0 1 290 <NA>
1 2 260 <NA>
2 3 288 279.3333333
3 4 300 282.6666667
4 5 310 299.3333333
If you want VWMA, get a dataset that has volume data as well. This keeps everything on GPU, instead of mixing CPU and GPU libraries. Also look into cuSignal for signal analysis.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | TaureanDyerNV |