Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expanding Average does not return the same result in pandas and polars #34

Open
eitsupi opened this issue Oct 8, 2024 · 0 comments
Open

Comments

@eitsupi
Copy link

eitsupi commented Oct 8, 2024

The two results in the following code block appear to be different.

``` {python}
close = pl.col("close")
ohlcv_pl.select(
[
pl.col("time"),
close.alias("Raw"),
close.rolling_mean(28).alias("28D MA"),
close.alias("Expanding Average").cum_sum() / (close.cum_count() + 1),
close.ewm_mean(alpha=0.03).alias("EWMA($\\alpha=.03$)"),
]
).to_pandas().set_index("time").plot()
plt.ylabel("Close ($)")
```
## Pandas
``` {python}
ohlcv_pd["close"].plot(label="Raw")
ohlcv_pd["close"].rolling(28).mean().plot(label="28D MA")
ohlcv_pd["close"].expanding().mean().plot(label="Expanding Average")
ohlcv_pd["close"].ewm(alpha=0.03).mean().plot(label="EWMA($\\alpha=.03$)")
plt.legend(bbox_to_anchor=(0.63, 0.27))
plt.ylabel("Close ($)")
```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant