cristian-bicheru / fast-ta

Python Technical Analysis Library For Big Data
https://fast-ta.readthedocs.io/en/latest/index.html
MIT License
10 stars 4 forks source link

Reduce code duplication in RSI #6

Closed CalderWhite closed 4 years ago

CalderWhite commented 4 years ago

RSI has a nasty amount of code duplication in momentum_backend.c as well as parallel_momentum_backend.c due to its compliance to working with 2 types. In the parallel backend this is tricky to work around due to the pointer math involved in the argument builder (pointer math is illegal with void pointers).

However, some work can be done on the underlying function that does the actual computation in momentum_backend.c. In order to make a generic function without casting to a different type, the only option we have evaluated currently is using a #define template for the body of the RSI loop (the per-period computation). Although not the prettiest, this would significantly reduce the code duplication, as this single group of instructions is repeated 6 times throughout the code (3 per RSI function, and there are 2: float, double).