Skip to content

Commit

Permalink
feat: add performace compare
Browse files Browse the repository at this point in the history
  • Loading branch information
Yvictor committed Jun 5, 2024
1 parent b899157 commit a989f72
Show file tree
Hide file tree
Showing 5 changed files with 7,981 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
examples/* linguist-documentation
3 changes: 2 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
target: [x86_64, aarch64-unknown-linux-gnu]
target: [x86_64]
#, aarch64-unknown-linux-gnu]
#, aarch64, armv7]
steps:
- uses: actions/checkout@v3
Expand Down
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,46 @@ df.with_columns(
),
)
```
## Performance

### Polars with polars_talib
``` python
%%timeit
df = p.with_columns(
plta.sma(timeperiod=5).over("Symbol").alias("sma5"),
plta.macd(fastperiod=10, slowperiod=20, signalperiod=5).over("Symbol").alias("macd"),
plta.stoch(pl.col("high"), pl.col("low"), pl.col("close"), fastk_period=14, slowk_period=7, slowd_period=7).over("Symbol").alias("stoch"),
plta.wclprice().over("Symbol").alias("wclprice"),
).with_columns(
pl.col("macd").struct.field("macd"),
pl.col("macd").struct.field("macdsignal"),
pl.col("macd").struct.field("macdhist"),
pl.col("stoch").struct.field("slowk"),
pl.col("stoch").struct.field("slowd"),
).select(
pl.exclude("stoch")
).filter(
pl.col("Symbol") == "AAPL"
).collect()
```

135 ms ± 5.6 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

### Pandas with talib
```python
%%timeit
df["sma5"] = df.groupby("Ticker")["close"].transform(lambda x: ta.SMA(x, timeperiod=5))
df["macd"] = df.groupby("Ticker")["close"].transform(lambda x: ta.MACD(x, fastperiod=10, slowperiod=20, signalperiod=5)[0])
df["macdsignal"] = df.groupby("Ticker")["close"].transform(lambda x: ta.MACD(x, fastperiod=10, slowperiod=20, signalperiod=5)[1])
df["macdhist"] = df.groupby("Ticker")["close"].transform(lambda x: ta.MACD(x, fastperiod=10, slowperiod=20, signalperiod=5)[2])
df["slowk"] = df.groupby("Ticker").apply(lambda x: ta.STOCH(x, fastk_period=14, slowk_period=7, slowd_period=7)).droplevel(0)["slowk"]
df["slowd"] = df.groupby("Ticker").apply(lambda x: ta.STOCH(x, fastk_period=14, slowk_period=7, slowd_period=7)).droplevel(0)["slowd"]
df["wclprice"] = df.groupby("Ticker").apply(lambda x: ta.WCLPRICE(x)).droplevel(0)
df.loc["AAPL"]
```
19.2 s ± 367 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

It's about 150x faster, see more detail in [basic.ipynb](./examples/basic.ipynb)

## Supported Indicators and Functions

Expand Down
Loading

0 comments on commit a989f72

Please sign in to comment.