Depedencies | |
---|---|
Required | |
Optional |
Tests | |
---|---|
pytest |
Does not support intra timestep updates:
The update functions for the indicators are not intelligent yet, they do not know if the new data being processed is a terminated candle. If you're working with a 1 minute timeframe, and you update SMA (example) 5 times within a minute, the last 5 values of the SMA will be within that TimeFrame. This will have to be handled on your end until I'm requested to, or deem it necessary to implement this into the code. Happy Trading 🤓
Not being worked on:
I am currently working on some ML stuff for the foreseeable future, this library will likely get some more love in 1-2 months once I've gotten other private projects up to speed.
- Use to_* functions to get indicator data
Leveraing Numpy and Numba, rolling-ta is designed for fast and efficient technical analysis, while maintaining the simplicity and ease of use of Pandas. It provides an intuitive single-responsibility API focused on technical analysis calculations and real-time updates. Prioritizing optimizations for speed, while being lightweight.
Key features include:
- Fast computations by leveraging the best features of NumPy and Numba.
- Incremental updates support, making it suitable for real-time applications.
- Simple, intuitive API for usage/extension without sacrificing performance.
Whether you're calculating simple indicators like SMA, or advanced indicators leveraging Linear Regression, this library delivers powerful performance with a clean and minimalistic interface.
By default, a lot of the stuff like ignore gil and parallel are set to false to increase compatibility. Please view the (Recommended) environment variables to make the library even faster.
py -m pip install rolling-ta
Initilization
from rolling_ta.trend import SMA
# With pyopenxl (see github repo for more info)
from rolling_ta.data import CSVLoader
loader = CSVLoader()
# Load a csv, headers not support (use columns param)
# default columns=[timestamp, open, high, low, close, volume]
data = loader.read_resources()
# returns unnamed pd.Series
sma = SMA(data).to_numpy(dtype=np.float64)
Rolling updates
sma.update(data.iloc[index])
Getting indicator as different types
sma_raw = sma.to_array()
sma_np = sma.to_numpy()
sma_pd = sma.to_series()
Getting an imbedded indicator
adx = ADX(data)
positive_directional_movement = adx.to_numpy(get="pdmi", dtype=np.float64)
rolling-ta uses python-dotenv to read environment variables.
(Recommended)
Tell Numba to write compiled machine code to __pycache__.
If set to 1, Numba will attempt to read compiled machine code into RAM using pickle.
This speeds up subsequent program runs.
NUMBA_DISK_CACHING=0|1
(Recommended w/ NUMBA_DISK_CACHING=1)
Tell Numba to aggressively compile mathematical operations.
Attempts to increase efficiency, slightly increases compile time.
NUMBA_FASTMATH=0|1
(Recommended)
Run looping operations (nb.prange) in parallel.
Drastically speeds up computations with arrays.size >= 100_000
See Linear Regression Indicator speed tests.
NUMBA_PARALLEL=0|1
Tell Numba functions to ignore the python global interpreter lock.
The speed increase with this set to true is 5-10% +/- 1%.
NUMBA_NOGIL=0|1
For more information on Numba compilation, see:
Numba compilation options
When comparing against ta, a popular financial library using purely Pandas and Numpy, we see some significant performance increases across some indicators.
see speed tests
Indicator | Lib | Speed |
---|---|---|
Average Directional Index | Rolling-TA TA |
813 μs ± 102 μs per loop 93.7 ms ± 544 μs per loop |
Average True Range | Rolling-TA TA |
1.32 ms ± 118 μs per loop 40.5 ms ± 835 μs per loop |
Exponential Moving Average | Rolling-TA TA |
52.8 μs ± 1.17 μs per loop 138 μs ± 4.43 μs per loop |
Ichimoku Cloud | Rolling-TA TA |
216 μs ± 65.8 μs per loop 3.07 ms ± 316 μs per loop |
Money Flow Index | Rolling-TA TA |
382 μs ± 11.2 μs per loop 122 ms ± 1.92 ms per loop |
On Balance Volume | Rolling-TA TA |
51.5 μs ± 819 ns per loop 272 μs ± 8.19 μs per loop |
Relative Strength Index | Rolling-TA TA |
172 μs ± 100 μs per loop 1.06 ms ± 49.7 μs per loop |
Simple Moving Average | Rolling-TA TA |
47.7 μs ± 649 ns per loop 264 μs ± 14.4 μs per loop |
True Range | Rolling-TA TA |
72.5 μs ± 1.14 μs per loop 2 ms ± 110 μs per loop |
These tests confirm that the results from python implementations match excel implementations.
Tests pytests
Fixtures fixtures
Excel Sheets resources
Expected Updates for 0.9
- Create update fn overloaded signature that accepts just the price information, instead of forcing people to supply a pd.Series object.
- Allow users to pass a mutable array to Indicator.update() function, instead of having to rebuild their existing data.
- Potential implementation (might be in 1.0), intelligently read existing data and parse required information from it to perform incremental updates.
- Implement Indicator.to_numpy(), Indicator.to_series() for more explicit data return.
- Finish update functions for the following Indicators:
- Linear Regression Indicator (LRI)
- Linear Regression Forecast (LRF)
- Linear Regression R2 (lr2)
- Maybe migrate pandas to polars and test GPU vectoring speed?
If you wish to provide a contribution, please follow these steps:
- Fork the dev branch.
- Implement your changes.
- Run ./pytest to confirm nothing breaks
(You'll need the excel resources from above. Or your own with a link so I can confirm its accuracy) - Run the new implementations within Speed Tests in a python notebook cell affixed with %%timeit.
If you don't follow these steps, the contribution will not be considered.