Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Poor performance of some indicators #98

Closed
giollord opened this issue Oct 14, 2020 · 3 comments
Closed

Poor performance of some indicators #98

giollord opened this issue Oct 14, 2020 · 3 comments

Comments

@giollord
Copy link

Some functions (especially ones which use Pandas.Series and DataFrame instead on numpy arrays) are very slow.
I have OHLCV dataset with 26k records and I'm having such execution times with default parameters:
WMA - 25.37s
HMA - 75.044s
SAR - 14.03s
CCI - 64.758s
SQZMI - 6.877s
MFI - 7.054s
IFT_RSI - 25.08s

Could be that there are other slow functions, but I tested the same dataset on just these ones and performance was pretty good: SMA, EMA, DEMA, TEMA, ZLEMA, VWAP, SMMA, BBANDS, KC, DO, TP, CHANDELIER, APZ, TRIX, KST, TSI, ER, MACD, VW_MACD, EV_MACD, MOM, AO, CHAIKIN, RSI, STOCHRSI, STC, CMO, QSTICK, WTO, ATR, VORTEX, COPP are under 0.1s;
KAMA and UO just a bit more than 1s.

I did some experiments and at least in a case of WMA and IFT_RSI I've got time about 0.3s for a really small adjustment in code:
weights = pd.Series(np.arange(1, period + 1)) replace with weights = np.arange(1, period + 1)
For CCI adding raw=True increases speed drastically (about x60-x70):
mad = tp_rolling.apply(lambda s: abs(s - s.mean()).mean(), raw=True)

@peerchemist
Copy link
Owner

I'll dig into this next week.

@giollord
Copy link
Author

I really like your project, but I'm too lazy to contribute normally by making pull request, sorry for that...
So, just as an idea for optimizing MFI, SQZMI and SAR:
MFI:

_mf["neg"] = _mf.apply(neg, axis=1)
_mf["pos"] = _mf.apply(pos, axis=1)

replace with (unfortunately, doesn't give very big boost)

_mf["neg"] = 0
_mf.loc[_mf["delta"] < 0, "neg"] = _mf["rmf"]
_mf["pos"] = 0
_mf.loc[_mf["delta"] > 0, "pos"] = _mf["rmf"]

SQZMI:

comb["SQZ"] = (comb["BB_LOWER"] > comb["KC_LOWER"]) & (comb["BB_UPPER"] < comb["KC_UPPER"])

SAR:

high, low = ohlc.high.to_numpy(), ohlc.low.to_numpy()

@peerchemist
Copy link
Owner

I've adopted e65409f, but that is as far as I would go at this point.

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

No branches or pull requests

2 participants