Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:TA Lib Ta lib python Abstract Function Configuration

From Leeroopedia
Revision as of 16:48, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/TA_Lib_Ta_lib_python_Abstract_Function_Configuration.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Knowledge Sources
Domains Technical_Analysis, Software_Architecture
Last Updated 2026-02-09 22:00 GMT

Overview

Concrete tool for configuring Abstract API Function parameters and input arrays via set_input_arrays, set_parameters, input_names, and parameters properties.

Description

The Function class exposes several configuration methods:

  • set_input_arrays(input_arrays) — Validates and binds input data (dict/DataFrame)
  • set_parameters(parameters, **kwargs) — Sets indicator-specific parameters
  • input_names (property) — Gets/sets which price series to use
  • parameters (property) — Gets/sets the current parameter values
  • info (property) — Returns complete function metadata dict

All configuration methods invalidate cached outputs, ensuring fresh computation on next access.

Usage

Call these methods on a Function object after creation and before execution to customize the indicator's behavior.

Code Reference

Source Location

  • Repository: ta-lib-python
  • File: talib/_abstract.pxi
  • Lines: L193-214 (input_names property), L227-272 (set_input_arrays), L276-284 (get_parameters), L286-297 (set_parameters), L172-177 (info property)

Signature

class Function:
    def set_input_arrays(self, input_arrays: dict | pd.DataFrame | pl.DataFrame) -> bool:
        """
        Sets the dict of input arrays. Returns True if valid, raises Exception if keys missing.
        """

    def set_parameters(self, parameters: dict = None, **kwargs) -> None:
        """
        Sets function parameter values.
        e.g., set_parameters(timeperiod=20) or set_parameters({'timeperiod': 20})
        """

    @property
    def input_names(self) -> OrderedDict:
        """Returns dict of input price series names."""

    @property
    def parameters(self) -> OrderedDict:
        """Returns OrderedDict of current parameter names and values."""

    @property
    def info(self) -> dict:
        """Returns full metadata dict including name, group, input_names, parameters, output_names."""

Import

from talib import abstract

I/O Contract

Inputs

Name Type Required Description
input_arrays dict / pd.DataFrame / pl.DataFrame Yes Data with named price series keys
parameters dict / kwargs No Indicator-specific parameters (e.g., timeperiod, nbdevup)

Outputs

Name Type Description
set_input_arrays return bool True if input was accepted
parameters OrderedDict Current parameter values
input_names OrderedDict Input price series mapping
info dict Complete function metadata

Usage Examples

Configure Parameters

from talib import abstract
import numpy as np

sma = abstract.Function('SMA')

# Inspect default parameters
print(sma.parameters)
# OrderedDict([('timeperiod', 30)])

# Set custom parameters
sma.parameters = {'timeperiod': 50}
print(sma.parameters)
# OrderedDict([('timeperiod', 50)])

# Alternative: use set_parameters
sma.set_parameters(timeperiod=10)

Configure Input Arrays

inputs = {
    'open': np.random.random(100),
    'high': np.random.random(100) + 1,
    'low': np.random.random(100),
    'close': np.random.random(100) + 0.5,
    'volume': np.random.random(100) * 1000,
}

sma = abstract.Function('SMA')
sma.set_input_arrays(inputs)

# Check what inputs SMA needs
print(sma.input_names)
# OrderedDict([('price', 'close')])  — SMA only uses 'close'

Inspect Function Info

bbands = abstract.Function('BBANDS')
print(bbands.info)
# {'name': 'BBANDS', 'group': 'Overlap Studies',
#  'input_names': OrderedDict([('price', 'close')]),
#  'parameters': OrderedDict([('timeperiod', 5), ('nbdevup', 2.0), ('nbdevdn', 2.0), ('matype', 0)]),
#  'output_names': ['upperband', 'middleband', 'lowerband'],
#  ...}

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment