Principle:TA Lib Ta lib python Abstract Function Instantiation
| Knowledge Sources | |
|---|---|
| Domains | Technical_Analysis, Software_Architecture |
| Last Updated | 2026-02-09 22:00 GMT |
Overview
A factory pattern that creates configurable indicator function objects from string names, enabling programmatic and dynamic indicator selection at runtime.
Description
The Abstract API uses a Factory Pattern to create indicator function objects. Instead of calling functions directly (e.g., talib.SMA(data)), users create Function objects by name:
sma = abstract.Function('SMA')
This enables:
- Dynamic indicator selection: Choose indicators by string name at runtime
- Introspection: Query function metadata, parameters, input names, output names
- Configuration: Set parameters and inputs separately from execution
- Reuse: Call the same configured function multiple times with different data
The factory validates the function name against all 161 supported indicators and binds the corresponding C function object.
Usage
Use this principle when you need to select indicators dynamically (e.g., from user input, configuration files, or iterating over a list of indicator names).
Theoretical Basis
The Factory Pattern decouples object creation from usage:
# Abstract factory pattern
class FunctionFactory:
def create(name: str) -> FunctionObject:
validate(name)
c_function = lookup_c_binding(name)
return FunctionObject(name, c_function)
Pre-instantiated Function objects are also available as module-level globals (e.g., abstract.SMA, abstract.RSI), created at import time for all 161 indicators.