Yvictor / polars_ta_extension

Polars extension for Ta-Lib: Support Ta-Lib functions in Polars expressions
MIT License
69 stars 12 forks source link

CCI returns different results every time is runs #11

Open yarimiz opened 1 month ago

yarimiz commented 1 month ago

I've been facing weird issue when trying to calculate CCI (ta.cci). Each time I run the exact same code, on the same data, and same arguments, I get different values for the feature.

the code:

raw_data.with_columns(cci=pl.col("adjusted_close").ta.cci(pl.col("adjusted_high"), pl.col("adjusted_low"), timeperiod=7).over("ticker")).collect())

I've attached a screen recording of the issue as it's the most simple way to display it.

https://github.com/user-attachments/assets/e5ff5e7d-c29e-4ff5-bf5a-e449a90d5b04

where raw_data is a lazyframe with simple structure of row per day per ticker, nothing special. The raw data is sorted.

I tried with and without filtering the lazyframe to only one ticker, sorting by date asc and desc, but nothing helped.

Yvictor commented 1 month ago

I use this example Polars TA Extension - Basic Example

Here is the code snippet I am working with:

p.filter(
    pl.col("Symbol") == "TSLA"
).with_columns(
    plta.cci(pl.col("high"), pl.col("low"), pl.col("close"), 7).over("Symbol").alias("cci_plta"),
    pl.col("close").ta.cci(pl.col("high"), pl.col("low"), 7).over("Symbol").alias("cci_ta"),
).collect()

the result is always same image