RTTA: Overview

All of the indicators in RTTA basically work the same way. You create an indicator, you feed it data, and it returns answers. You have a choice between feeding it data one bit at a time via the update method or an entire numpy sequence at a time via the batch method. Whatever you do it is important to remember that the indicator object is stateful, so each time you call update or batch, its treated as if more data is being appended to any earlier data the indicator saw. If you want to reset the indicator you need to create a new indicator object.


The specifics of what fields the indicator takes will depend on the underlying operation and the parameters it requires. The best documentation until we bring out documentation online here will be found by importing rtta.indicator and running help(rtta.indicator.EMAIndicator) or whatever indicator you have a question about.

Common to all indicators is a field called fillna. This field pertains to the treatment of outgoing data before the underlying structures have enough data to be considered fully populated. For example, in a Simple Moving Average you might specify a windows size of 10 - what behavior do you want to see when you feed it data point 2, 3, 4 etc. By default each indicator will return nan when it isn't ready, but specifying fillna=True can specify that the indicator take a best guess instead

Incremental use

What inspired the creation of this library was the author's need to process one second interval tick data coming from polygon.io across a large range of instruments. The defining feature for this library is its ability to process data one "tick" at a time, incrementally, instead of all at once. To do this you construct indicator like this:

  ema=EMAIndicator(window=4, fillna=True)

And call .update(x) on it as many times as you want. Each time you call update pass it the next data point, each time update returns it will return the next value in the sequence.

Some indicators return multiple values. Internally a C-structure is being returned with a Cython wrapper that presents a dictionary interface. In that case the indicators will have a dictionary interface that can be used to retrieve the respective values. Which indicators and what field names will be in each indicator's respective documentation.

Batch use

If you have more than one value to process, and want more than one value to return, a batch interface is provided. This is for two reasons - first its for convenience, and second there are optimizations that can be taken when processing bulk data. For example the EMAIndicator.update operation takes 37ns on the author's computer, but processing 10,000 elements requires 14.1 microseconds, or 1.4 nanoseconds per element. If you don't need incremental processing and have your data in a batch format, its always faster to use batch processing.

  ema=EMAIndicator(window=4, fillna=True) ema.batch(arcray)

array must be a one dimensional numpy array of type double. This is the default type numpy creates, so don't worry too much unless you fiddle with numpy data types. batch will return the matching results in a numpy array. If there is more than one channel batch will return the matching results in a dictionary of numpy arrays. The dictionary keys will be documented in the classes doc-strings.

It is important to remember that indicators are stateful for both calls to update and batch. Batch is treated as a lot of calls to update - the internal state of the object is changed just as if you called update over and over again. Calling batch again does not give you a fresh object. If that's what you need, you'll need to create a indicator object.