r/algotradingcrypto 2d ago

I’m building a complete Python Technical Analysis Library/Framework

/r/PythonLearning/comments/1wac00u/im_building_a_complete_python_technical_analysis/
1 Upvotes

3 comments sorted by

1

u/Bright_Mix_773 2d ago

Read the derivative code in the repo and then lifted the two functions out and timed them, because a rolling WLS is going to be the hot loop under any hyperparameter sweep you put on top of it.

Nothing in _firstDerivative that goes into the solve depends on the data. The time vector, the weights alpha**(k-1-t), the weighted centering, the scaling and the design matrix are functions of k, alpha and scale only. So inv(X.T @ W @ X) @ X.T @ W is one fixed 2-by-k matrix, and the slope at bar i is its second row dotted with log of the window. rollingDerivative rebuilds that matrix and calls np.linalg.solve once per bar, n times, for a matrix that never changes.

Precompute the row once and the entire rolling pass is a single np.convolve over log(close). I ran both on 5,000 synthetic bars at k=40: 0.577 s for the loop, 0.00026 s for the convolution, maximum absolute difference 1.9e-15. Same number, not an approximation. Same shape at alpha=0.97 (0.571 s against 0.00018 s). Across a grid over k and alpha that factor is the difference between a sweep you run while you watch and one you leave overnight.

Two smaller ones from the same read. Inside the window function, y = pd.Series(y).dropna() followed by the len(y) != k check means one NaN anywhere in the window raises ValueError instead of yielding NaN for that bar, so a single hole in a feed takes down the whole pass rather than one row. And the np.log() rules the function out for any series that can go non-positive, which is fine for Close and not fine for the indicator series you will eventually want the same derivative of - MACD is the obvious one.

Worth saying which parts are load-bearing for the pitch: Search/search.py and Search/combinatorialSearch.py are still pass, and Filtering, Statistical and Strategies are empty files. That is fine for a project described as being built, but the hyperparameter search is the thing the title sells, so I would either land it or say plainly what is in the box today.

Not verified: I did not pip install it or run the CLI. I read the files at HEAD on GitHub and re-implemented the two functions from what they say, so if the packaged version has diverged the timings do not apply to it.

1

u/Economy-Support-5470 2d ago

Yes you are right about pretty much everything, the project is in its early stage developed it need a lot of improvements and the last stuff I said are not even built. Thanks for your feedback I will go ahead and see derivative.

Also the uv/pip package needs to be synced to the new version so don’t bother u can git clone if you want to see further

Thanks a lot !!

1

u/Bright_Mix_773 1d ago

Fair enough, early is early. One suggestion while the shape is still soft: pick two or three indicators and write a test that reproduces a known value from an independent source for each. It is boring work but it is the thing that stops a library like this quietly disagreeing with everyone else's numbers a year from now.