TTI (Trading Technical Indicators)

repository·master·Indexed 40 days ago

https://github.com/vsaveris/trading-technical-indicators

A Python library that combines traditional technical analysis with AI-driven tooling. TTI provides 62 technical indicators, signal generation, graphing, and a trading simulation engine for backtesting indicator effectiveness using historical market data. It includes utilities for handling missing financial data via fillMissingValues and supports a wide range of indicators such as RSI, MACD, and Bollinger Bands.

Tokens
5.1K
Snippets
13
Records
28
Agent score
94%

What's inside TTI

  1. Data structure of technical indicator outputs

    master

    Technical indicators in tti return data in various shapes depending on the indicator type:

    • Single-column indicators: Most oscillators and trend indicators (e.g., AverageTrueRange, ChaikinMoneyFlow, Momentum) return a DataFrame with a single column named after the indicator (e.g., atr, cmf, mom).
    • Multi-column indicators: Some indicators return multiple components. For example:
      • BollingerBands: Returns middle_band, upper_band, and lower_band.
      • DirectionalMovementIndex: Returns +di, -di, dx, adx, and adxr.
      • IchimokuCloud: Returns tenkan_sen, kijun_sen, senkou_a, and senkou_b.
      • StochasticOscillator: Returns %K and %D.
      • MovingAverageConvergenceDivergence: Returns macd and signal_line.
      • PriceChannel: Returns highest_high and lowest_low.
      • ProjectionOscillator: Returns posc and trigger_line.
  2. Understand technical indicator outputs and signals

    master

    When executing technical indicators in the tti package, the output typically consists of three components:

    1. Calculated Data: A pandas DataFrame containing the indicator values indexed by date. Note that early rows often contain NaN values due to the indicator's lookback period or warm-up time.
    2. Specific Values: The indicator value at a specific timestamp (e.g., Technical Indicator value at 2012-09-12 00:00:00 : [141.1675]).
    3. Trading Signals: A tuple representing the recommended action and its associated strength/value. Common signals include:
      • ('buy', -1)
      • ('sell', 1)
      • ('hold', 0)
  3. Understand Trading Simulation output and statistics

    master

    The signals_simulation tool performs trading simulations for various technical indicators in the tti.indicators package. Each simulation produces a performance report containing execution time, a saved visualization graph, and detailed simulation statistics.

    Simulation Statistics Fields

    When reviewing simulation results, the following metrics are provided:

    • number_of_trading_days: Total duration of the simulation in days.
    • number_of_buy_signals: Total count of buy signals generated by the indicator.
    • number_of_ignored_buy_signals: Buy signals that were not acted upon.
    • number_of_sell_signals: Total count of sell signals generated by the indicator.
    • number_of_ignored_sell_signals: Sell signals that were not acted upon.
    • last_stock_value: The price of the stock at the end of the simulation.
    • last_exposure: The total value of current market exposure.
    • last_open_long_positions: Number of active long positions at the end of the simulation.
    • last_open_short_positions: Number of active short positions at the end of the simulation.
    • last_portfolio_value: The value of the portfolio (excluding cash/balance).
    • last_earnings: Total earnings generated during the simulation.
    • final_balance: The final cash balance after all trades and earnings.
  4. Understand the output of technical indicators

    master

    When executing technical indicators using the tti.indicators package, the output typically consists of four components:

    1. Calculation Time: The time taken to compute the indicator.
    2. Visualizations: A generated graph saved as a PNG file (e.g., ./figures/example_IndicatorName.png).
    3. Indicator Data: A pandas DataFrame containing the calculated values indexed by date. Note that early rows often contain NaN values due to the lookback period required for calculation.
    4. Point-in-time Values: Specific indicator values retrieved for a given timestamp.
    5. Trading Signals: A tuple containing a signal label and a numeric value (e.g., ('buy', -1), ('hold', 0), or ('sell', 1)).
  5. How to use technical indicators in TTI

    master

    To use an indicator, follow these steps:

    1. Load your market data into a pandas.DataFrame with a datetime index.
    2. Instantiate the specific indicator class from tti.indicators, passing your data to the input_data parameter.
    3. Use the indicator's methods to retrieve data, signals, or visualizations.

    Core Indicator Methods

    • getTiData(): Returns the calculated indicator data as a DataFrame.
    • getTiValue(date=None): Returns the indicator value for a specific date. If no date is provided, it returns the most recent value.
    • getTiSignal(): Returns the current trading signal (e.g., ('buy', -1)).
    • getTiGraph().show(): Generates and displays a graph of the indicator.
    • getTiSimulation(...): Executes a trading simulation based on the indicator's signals.
    import pandas as pd
    from tti.indicators import AccumulationDistributionLine
    
    # Load data
    df = pd.read_csv('./data/SCMN.SW.csv', parse_dates=True, index_col=0)
    
    # Initialize indicator
    indicator = AccumulationDistributionLine(input_data=df)
    
    # Access data and signals
    data = indicator.getTiData()
    signal = indicator.getTiSignal()
    value = indicator.getTiValue()
    
    # Visualize
    indicator.getTiGraph().show()
  6. Install the TTI library

    master

    You can install the stable release of Trading Technical Indicators (TTI) via pip. If you want to use the latest unreleased development version, you must clone the repository and install it locally.

    Stable Release (0.2.2)

    pip install tti

    Unreleased Development Version

    git clone https://github.com/vsaveris/trading-technical-indicators.git
    pip install .
    pip install tti
  7. Use the tti.indicators API

    master

    The tti.indicators package provides a consistent interface for various technical indicators. While specific indicators may require different input columns (e.g., AccumulationDistributionLine requires close, high, low, and volume), the core workflow remains the same:

    1. Prepare a pandas.DataFrame with the required columns and a datetime index.
    2. Instantiate the indicator class with your data.
    3. Use the provided methods to retrieve data, signals, graphs, or run simulations.

    Note: Always ensure your DataFrame index is set to the date column for correct time-series processing.

    import pandas as pd
    from tti.indicators import AccumulationDistributionLine
    
    # Prepare data
    df = pd.read_csv('./data/SCMN.SW.csv', parse_dates=True, index_col=0)
    
    # Initialize indicator
    indicator = AccumulationDistributionLine(input_data=df)
  8. Understand the structure of sample_data.csv

    master

    The sample_data.csv file provided in the examples directory contains historical trading data for the period from 2000-02-01 to 2012-09-12. It is structured with the following columns, which are required for calculating most technical indicators:

    • date: The timestamp for the period.
    • open: The opening price.
    • high: The highest price during the period.
    • low: The lowest price during the period.
    • close: The closing price.
    • volume: The trading volume.