Skip to content
All library documents

Using a Python Technical Analysis Library for Financial Features

Article Technical Analysis

Summary

The document introduces a Python library for adding technical analysis features to financial time series containing open, high, low, close, and volume data. It describes using the library with pandas and shows two workflows: adding a broad set of indicators to a dataset, or calculating selected Bollinger Bands features from closing prices. The examples include a 20-period window and a deviation setting of two, and demonstrate creating band values and indicators for prices crossing the bands.

The page is introductory documentation rather than a strategy evaluation. It provides no backtest, trading rules, performance evidence, or discussion of how to handle lookahead bias and data quality. It does show that missing values may be dropped or filled, but does not explain the consequences of those choices. The features can support analysis or model inputs; the document does not establish that any indicator predicts returns.

Key ideas

  • The library computes technical analysis features from financial time series using pandas.
  • It can add a broad collection of features or calculate selected indicators individually.
  • The Bollinger Bands example derives moving average, upper and lower bands, and band-crossing indicators from closing prices.
  • Missing values can be dropped or filled, but the page does not assess how those choices affect results.

Tags

Full text
# Load datas


.. Technical Analysis Library in Python documentation master file, created by
   sphinx-quickstart on Tue Apr 10 15:47:09 2018.
   You can adapt this file completely to your liking, but it should at least
   contain the root `toctree` directive.

Welcome to Technical Analysis Library in Python's documentation!
================================================================

It is a Technical Analysis library to financial time series datasets (open, close, high, low, volume). You can use it to do feature engineering from financial datasets. It is built on Python Pandas library.

Installation (python >= v3.6)
================================================================

.. code-block:: bash

    > virtualenv -p python3 virtualenvironment
    > source virtualenvironment/bin/activate
    > pip install ta

Examples
==================

Example adding all features:

.. code-block:: python

    import pandas as pd
    from ta import add_all_ta_features
    from ta.utils import dropna

    # Load datas
    df = pd.read_csv('ta/tests/data/datas.csv', sep=',')

    # Clean NaN values
    df = dropna(df)

    # Add ta features filling NaN values
    df = add_all_ta_features(
        df, open="Open", high="High", low="Low", close="Close", volume="Volume_BTC", fillna=True)


Example adding a particular feature:

.. code-block:: python

   import pandas as pd
   from ta.utils import dropna
   from ta.volatility import BollingerBands


   # Load datas
   df = pd.read_csv('ta/tests/data/datas.csv', sep=',')

   # Clean NaN values
   df = dropna(df)

   # Initialize Bollinger Bands Indicator
   indicator_bb = BollingerBands(close=df["Close"], window=20, window_dev=2)

   # Add Bollinger Bands features
   df['bb_bbm'] = indicator_bb.bollinger_mavg()
   df['bb_bbh'] = indicator_bb.bollinger_hband()
   df['bb_bbl'] = indicator_bb.bollinger_lband()

   # Add Bollinger Band high indicator
   df['bb_bbhi'] = indicator_bb.bollinger_hband_indicator()

   # Add Bollinger Band low indicator
   df['bb_bbli'] = indicator_bb.bollinger_lband_indicator()

Motivation
==================

* English: https://towardsdatascience.com/technical-analysis-library-to-financial-datasets-with-pandas-python-4b2b390d3543
* Spanish: https://medium.com/datos-y-ciencia/biblioteca-de-an%C3%A1lisis-t%C3%A9cnico-sobre-series-temporales-financieras-para-machine-learning-con-cb28f9427d0


Contents
==================
.. toctree::
   TA <ta>


Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

Shown in full with attribution under the source's licence. Licence: MIT

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.