Python - Install tulipy in Debian

By xngo on March 31, 2019

Overview

Tulipy is the Python bindings for Tulip Indicators. Tulip Indicators itself is an open-source library of functions for technical analysis of financial time series data. It is written in ANSI C for speed and portability. The good thing about this library is it is actively maintained and it cross-checks its results with https://www.ta-lib.org.

Installation

By default, run the following commands to install tulipy in Debian:

# Check which version of Python is installed.
python -V
 
# Install development package of Python.
apt-get install python-dev
 
# Install require packages.
pip install setuptools wheel numpy Cython
 
# Install tulipy.
pip install tulipy

For Python3, run the following commands:

# Install development package of Python.
apt-get install python3-dev
 
# Install require packages.
pip install setuptools wheel numpy Cython
 
# Install tulipy.
pip install tulipy

Usage

#!/usr/bin/python3
import numpy as np
import tulipy as ti
 
# Display Tulip Indicators version.
print(ti.TI_VERSION)
 
# Function to display information about indicator.
#   List of indicators: https://tulipindicators.org/list
def print_info(indicator):
    print("Type:", indicator.type)
    print("Full Name:", indicator.full_name)
    print("Inputs:", indicator.inputs)
    print("Options:", indicator.options)
    print("Outputs:", indicator.outputs)
 
# Display information about Simple Moving Average indicator.
print_info(ti.sma)
 
#######################################################
# Use Square Root vector
sqrt_data = np.array([4.0, 9.0, 100.0])
sqrt_results = ti.sqrt(sqrt_data)
print(sqrt_results);
 
# Use Simple Moving Average
sma_data = np.array([ 81.59, 81.06, 82.87, 83,    83.61,
                      83.15, 82.84, 83.99, 84.55, 84.36,
                      85.53, 86.54, 86.89, 87.77, 87.29])
sma_results = ti.sma(sma_data, period=5)
print(sma_results) # Compare results against https://tulipindicators.org/sma. Should be the same.

Get the input parameters

In the print_info() function above, the indicator.options doesn't give the valid Python identifiers. Instead, check the function signature to find out what are the exact identifiers. Below is an example how to check the signature of the function:

#!/usr/bin/python3
import inspect
import tulipy as ti
 
print(inspect.signature(ti.macd)) 
# (real, short_period, long_period, signal_period)
 
print(inspect.signature(ti.stoch)) 
# (high, low, close, pct_k_period, pct_k_slowing_period, pct_d_period)

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.