Skip to main content

A simple technical indicator package

Project description

PyTechnicalIndicators

PyTechnicalIndicators is a Python library with a number of common technical indicators used to analyse financial data.

This README will walk you through the Python functions used to calculate various technical indicators and how to call them. It will not explain what each one is and when or where to use them. If you need more information use Google, Wikipedia, or Investopedia.

Table of Contents


Installation

Use the package manager pip to install PyTechnicalIndicators.

pip install PyTechnicalIndicators

Usage

The below is a break down of the various functions in the package, for a detailed example see the Example.

The library is split into three sections Single, Bulk and Chart_Patterns.

Single and Bulk have identical functions, Single returns a single value, Bulk returns a list. This is to reduce compute time if you only a single value returned for you series, or to avoid looping a call if you have a lot of data to process.

It is important to note that the functions expect a list of prices to work, with the oldest value at the beginning of the list and the most recent price at the end. An indexed Pandas DF will not work, you will have to list() before your variables you pass it into these functions, the Example has more details.


Single

Single is broken down into 3 sections:

  • moving_averages: contains the common moving averages (moving average, exponential ma, smoothed ma, macd), as well as a personalised moving average.
  • strength_indicators: currently only has Relative Strength Index and Stochastic as well as their personalised variations.
  • candle_indicators: currently only has Bollinger Bands and the Ichimoku Cloud as well as their personalised variations.

By personalised variations we mean that we have allowed the user to determine how certain calculations were done. For example, the RSI uses as smoothed MA to calculate the average gains, the personalised RSI allows you to choose your MA model. Each personalised function will have more detail on how to use it .

Moving Averages

Calling moving_averages

from PyTechnicalIndicators.Single import moving_averages

moving_average(prices)

The simple moving average of a series

Parameters:

  • prices: list of floats or ints with oldest values at position 0 and newest value in position n

Example:

prices = [100, 102, 101 ... ]

ma = moving_averages.moving_average(prices)

exponential_moving_average(prices)

The exponential moving average (EMA), this is usually used when the latest prices are expected to have a greater impact

Parameters:

  • prices: list of floats or ints with oldest values at position 0 and newest value in position n

Example:

prices = [100, 102, 101 ... ]

ema = moving_averages.exponential_moving_average(prices)

smoothed_moving_average(prices)

The smoothed moving average (SMA) is similar to the exponential moving average, the calculation of the alpha varies slightly (see personalised_moving_average for a more detailed explanation of the alpha)

Parameters:

  • prices: list of floats or ints with oldest values at position 0 and newest value in position n

Example:

prices = [100, 102, 101 ... ]

sma = moving_averages.smoothed_moving_average(prices)

personalised_moving_average(prices, alpha_nominator, alpha_denominator)

The personalised moving average (PMA) allows you to determine your nominator and denominator values for the alpha. The alpha determines the impact of previous prices, the higher the alpha the lower past values have an impact. The calculation is as follows:

alpha = alpha_nominator / (length_prices + alpha_denominator)

The alpha_denominator may be a little confusing as it isn't itself the entire denominator, it is a variable that gets added to the length of the submitted prices to form the actual alpha_denominator.

The EMA used an alpha nominator of 2 and an alpha denominator of 1. The SMA used an alpha nominator of 1 and an alpha denominator of 0.

Parameters:

  • prices: list of floats or ints with oldest values at position 0 and newest value in position n
  • alpha_nominator: float or int, can be 0, but it isn't recommended.
  • alpha_denominator: float or int, can be 0

Example:

prices = [100, 102, 101 ... ]

pma = moving_averages.personalised_moving_average(prices, 3, 2)

moving_average_divergence_convergence(prices)

The moving average divergence convergence (MACD) only returns the MACD line, to get the single line you will need to call signal_line (detailed below), the histogram is simply one minus the other, and isn't yet provided here.

The moving_average_divergence_convergence requires the length of prices to be at least 26 as that is the number of periods taken into account, it accepts more, but discards the extra no passing them in will only impact your performance.

If you want to pass in a smaller or bigger period see personalised_macd.

Parameters:

  • prices: list of floats or ints with oldest values at position 0 and newest value in position n, must be at least 26 periods in length

Example:

prices = [100, 102, 101 ... ]

macd = moving_averages.moving_average_divergence_convergence(prices)

signal_line(macd)

The signal line returns the line that is complementary to moving_average_divergence_convergence, and is required to be 9 periods long, no more, no less. If you'd like to pass in a different amount see personalised_signal_line

Parameters:

  • macd: list of 9 macds retrieved from moving_average_divergence_convergence

Example:

macd = [1.2, 1.45, 0.98 ... ]

signal = moving_averages.signal_line(macd[:-9])

personalised_macd(prices, short_period, long_period, ma_model='ema')

The personalised macd allows you to determine what the short period and long period are for the macd calculation. Essentially the macd is the subsctraction of the EMA of the short period - the EMA of the long period, which are 12 and 26 respectively in the traditional MACD. Here we allow you to determine what those periods are. We also allow you to chose you moving average model in the event where you would prefer something other than the EMA.

Parameters:

  • prices: list of floats or ints with oldest values at position 0 and newest value in position n, the length of prices must be at least as big as the value for your long_period
  • short_period: int, value strictly greater than 0 but smaller than your long_period.
  • long_period: int, value strictly greater than the short period but smaller or equal to the length of prices.
  • ma_model: optional The moving average model of your choice (defaults to EMA):
    • for moving average either of the following: 'ma', 'moving average', 'moving_average'
    • for smoothed moving average either of the following: 'sma', 'smoothed moving average', 'smoothed_moving_average'
    • for exponential moving average either of the following: 'ema', 'exponential moving average', 'exponential_moving_average'

Example:

prices = [100, 102, 101 ... ]

pers_macd = moving_averages.personalised_macd(prices, 10, 20, 'smoothed moving average')

personalised_signal_line(macd, ma_model='ema')

The personalised signal line is similar to the personalised MACD in that it lets you decide of the length of the macds that you want to pass in, however is doesn't require you to insert a variable, it will instead just calculate it based on the length of the macd list provided.

You can also choose the MA model you would like to run, it is normally just a EMA but you are free to choose your model.personalised

Parameters:

  • macd: list of macds can be either from a normal macd or a personalised one. The length of the list needs to be greater than 1 and can be as large as you like.
  • ma_model: optional The moving average model of your choice (defaults to EMA):
    • for moving average either of the following: 'ma', 'moving average', 'moving_average'
    • for smoothed moving average either of the following: 'sma', 'smoothed moving average', 'smoothed_moving_average'
    • for exponential moving average either of the following: 'ema', 'exponential moving average', 'exponential_moving_average'

Example:

macd = [1.2, 1.45, 0.98 ... ]

signal = moving_averages.personalised_signal_line(macd, 'moving_average')

Strength Indicators

Calling stength indicators

from PyTechnicalIndicators.Single import strength_indicators

relative_strength_index(prices)

Returns the relative strength index (RSI) of submitted prices, the length of prices needs to be 14 periods long, no more, no less.

Parameters:

  • prices: list of floats or ints of prices that needs to be exactly 14 periods long.

Example:

prices = [100, 102, 101 ... ]

rsi = strength_indicators.relative_strength_index(prices)

personalised_rsi(prices, ma_model='sma')

The personalised RSI allows you to choose which MA model to use as well as the number of periods. The traditional RSI uses 14 periods and a SMA model.

Parameters:

  • prices: list of floats or int, the length of prices needs to be exactly of length of the period that you want to evaluate. than 1 and can be as large as you like.
  • ma_model: optional The moving average model of your choice (defaults to SMA):
    • for moving average either of the following: 'ma', 'moving average', 'moving_average'
    • for smoothed moving average either of the following: 'sma', 'smoothed moving average', 'smoothed_moving_average'
    • for exponential moving average either of the following: 'ema', 'exponential moving average', 'exponential_moving_average'

Example:

prices = [100, 102, 101 ... ]

pers_rsi = strength_indicators.personalised_rsi(prices, 'ema')

stochastic_oscillator(close_prices)

Returns the stochastic oscillator (SO) for submitted close prices which need to be 14 periods long, no more, no less.

Parameters:

  • close_prices: list of floats or ints of closing prices that needs to be exactly 14 periods long.

Example:

close = [99, 103, 96 ... ]

so = strength_indicators.stochastic_oscillator(close)

personalised_stochastic_oscillator(close_prices)

The personalised version of the stochastic oscillator allows you to submit close prices of any length.

Parameters:

  • close_prices: list of floats or ints of closing prices, the length is of your choosing.

Example:

close = [99, 103, 96 ... ]

pers_so = strength_indicators.personalised_stochastic_oscillator(close)

Candle Indicators

Calling candle indicators

from PyTechnicalIndicators.Single import candle_indicators 

bollinger_bands(typical_prices)

Returns the upper and lower Bollinger Band for a submitted typical prices, which need to be 20 periods long, no more, no less.

The typical price is calculated by taking the average of the High, Low, and Close ( (High + Low + Close) / 3 ).

Parameters:

  • typical_prices: list of floats or ints of exactly 20 periods long.

Example:

typical_prices = [100, 102, 101 ... ]

bband = candle_indicators.bollinger_bands(typical_prices)

personalised_bollinger_bands(typical_price, ma_model='ma', stddev_multiplier=2)

The personalised version allows you to choose the length of typical prices to submit as well as the MA model to run.

The traditional Bollinger Band model uses a MA and 20 periods.

Parameters:

  • typical_prices: a list of floats or ints of exactly 20 periods long.
  • ma_model: optional The moving average model of your choice (defaults to MA):
    • for moving average either of the following: 'ma', 'moving average', 'moving_average'
    • for smoothed moving average either of the following: 'sma', 'smoothed moving average', 'smoothed_moving_average'
    • for exponential moving average either of the following: 'ema', 'exponential moving average', 'exponential_moving_average'
  • stddev_multiplier: int, number of standard deviations, defaults to 2.

Example:

typical_prices = [100, 102, 101 ... ]

pers_bband = candle_indicators.personalised_bollinger_bands(typical_prices, 'ema')

ichimoku_cloud(highs, lows)

Returns the leading span A and leading span B, using the highs and lows of a series, these need to be 52 periods long, no more, no less.

Parameters:

  • highs: list of floats or ints of the highs of a series, needs to be 52 periods long.
  • lows: list of floats or ints of the lows of a series, needs to be 52 periods long.

Example:

typical_prices = [100, 102, 101 ... ]

icloud = candle_indicators.ichimoku_cloud(highs, lows)

personalised_ichimoku_cloud(highs, lows, conversion_period, base_period, span_b_period)

The personalised version of the Ichimoku Cloud allows you to play around with the variables of the Ichimoku Cloud. These are rather involved so don't play around with them if you don't know what you're doing, or do, I won't judge.

Parameters:

  • highs: list of floats or ints of the highs of a series, needs to be 52 periods long.
  • lows: list of floats or ints of the lows of a series, needs to be 52 periods long.
  • conversion_period:
  • base_period:
  • span_b_period:

Example:

typical_prices = [100, 102, 101 ... ]

pers_icloud = candle_indicators.personalised_ichimoku_cloud(highs, lows, , , )

Bulk

Bulk is broken down into 4 sections, in a very similar way to Single, the only difference is that these are meant to run against large datasets, and return a list of values as opposed to a single point like in Single.

  • basic_indicators: These are a list of Python math and statistics functions that have been wrapped up in a loop to allow them to return a list. These are mostly to be used within the other functions.
  • moving_averages: contains the common moving averages (moving average, exponential ma, smoothed ma, macd), as well as a personalised moving average.
  • strength_indicators: currently only has Relative Strength Index and Stochastic as well as their personalised variations.
  • candle_indicators: currently only has Bollinger Bands and the Ichimoku Cloud as well as their personalised variations.

By personalised variations we mean that we have allowed the user to determine how certain calculations were done. For example, the RSI uses as smoothed MA to calculate the average gains, the personalised RSI allows you to choose your MA model. Each personalised function will have more detail on how to use it.

Basic Indicators

Calling basic_indicators

from PyTechnicalIndicators.Bulk import basic_indicators

log(prices)

Returns a list of logs for the list of submitted prices. This is just the Python math log function wrapped in a loop to return a list of logs.

Parameters:

  • prices: list of floats or ints of prices that needs to be exactly 14 periods long.

Example:

prices = [100, 102, 101 ... ]

logs = basic_indicators.log(prices)

log_difference(prices)

Returns a list of log difference for the list of submitted prices. This substracts the log of t and t-1.

Parameters:

  • prices: list of floats or ints of prices that needs to be exactly 14 periods long.

Example:

prices = [100, 102, 101 ... ]

log_diff = basic_indicators.log_diff(prices)

stddev(prices, period, fill_empty=False, fill_value=None)

Returns a list of standard deviations for the list of submitted prices. This uses the Python statistics stdev wrapped in a loop. It expects a period to know how many prices to apply the stdev to.

Parameters:

  • prices: list of floats or ints of prices that needs to be at least one in length.
  • period: int, the number of prices that you would like taken into account to calculate the standard deviation.
  • fill_empty: Boolean, whether you want to fill the list with a value to match the length of the submitted prices. This is helpful when using this with Pandas as it will allow to insert the returned list directly into your DataFrame (see (Example)[] )
  • fill_value: The value that you want used to fill in the empty spaces.

Example:

prices = [100, 102, 101 ... ]

std_devs = basic_indicators.stddev(prices, 10, True, 0)

mean(prices, period, fill_empty=False, fill_value=None)

Returns a list of means for the list of submitted prices. This uses the Python statistics mean function wrapped in a loop. It expects a period to know how many prices to apply the mean to.

Parameters:

  • prices: list of floats or ints of prices that needs to be at least 1.
  • period: int, the number of prices that you would like taken into account to calculate the mean.
  • fill_empty: Boolean, whether you want to fill the list with a value to match the length of the submitted prices. This is helpful when using this with Pandas as it will allow to insert the returned list directly into your DataFrame (see (Example)[] )
  • fill_value: The value that you want used to fill in the empty spaces.

Example:

prices = [100, 102, 101 ... ]

mean = basic_indicators.mean(prices, 5, True, None)

median(prices, period, fill_empty=False, fill_value=None)

Returns a list of medians for the list of submitted prices. This uses the Python statistics median function wrapped in a loop. It expects a period to know how many prices to apply the median to.

Parameters:

  • prices: list of floats or ints of prices that needs to be at least 1.
  • period: int, the number of prices that you would like taken into account to calculate the median.
  • fill_empty: Boolean, whether you want to fill the list with a value to match the length of the submitted prices. This is helpful when using this with Pandas as it will allow to insert the returned list directly into your DataFrame (see (Example)[] )
  • fill_value: The value that you want used to fill in the empty spaces.

Example:

prices = [100, 102, 101 ... ]

medians = basic_indicators.median(prices, 12)

variance(prices, period, fill_empty=False, fill_value=None)

Returns a list of medians for the list of submitted prices. This uses the Python statistics variance function wrapped in a loop. It expects a period to know how many prices to apply the variance to.

Parameters:

  • prices: list of floats or ints of prices that needs to be at least 1.
  • period: int, the number of prices that you would like taken into account to calculate the variance.
  • fill_empty: Boolean, whether you want to fill the list with a value to match the length of the submitted prices. This is helpful when using this with Pandas as it will allow to insert the returned list directly into your DataFrame (see (Example)[https://github.com/0100101001010000/PyTechnicalIndicators_Examples/tree/main/Notebook_Example] )
  • fill_value: The value that you want used to fill in the empty spaces.

Example:

prices = [100, 102, 101 ... ]

variances = basic_indicators.variance(prices, 5)

Moving Averages

Calling moving_averages

from PyTechnicalIndicators.Bulk import moving_averages

moving_average(prices, period, fill_empty=False, fill_value=None)

The simple moving average of a series

Parameters:

  • prices: list of floats or ints with oldest values at position 0 and newest value in position n
  • period: int, the number of prices that you would like taken into account to calculate the median.
  • fill_empty: Boolean, whether you want to fill the list with a value to match the length of the submitted prices. This is helpful when using this with Pandas as it will allow to insert the returned list directly into your DataFrame (see (Example)[https://github.com/0100101001010000/PyTechnicalIndicators_Examples/tree/main/Notebook_Example] )
  • fill_value: The value that you want used to fill in the empty spaces.

Example:

prices = [100, 102, 101 ... ]

ma = moving_averages.moving_average(prices, 5, True, 0)

exponential_moving_average(prices, period, fill_empty=False, fill_value=None)

The exponential moving average (EMA), this is usually used when the latest prices are expected to have a greater impact

Parameters:

  • prices: list of floats or ints with oldest values at position 0 and newest value in position n
  • period: int, the number of prices that you would like taken into account to calculate the median.
  • fill_empty: Boolean, whether you want to fill the list with a value to match the length of the submitted prices. This is helpful when using this with Pandas as it will allow to insert the returned list directly into your DataFrame (see (Example)[https://github.com/0100101001010000/PyTechnicalIndicators_Examples/tree/main/Notebook_Example] )
  • fill_value: The value that you want used to fill in the empty spaces.

Example:

prices = [100, 102, 101 ... ]

ema = moving_averages.exponential_moving_average(prices, 25)

smoothed_moving_average(prices, period, fill_empty=False, fill_value=None)

The smoothed moving average (SMA) is similar to the exponential moving average, the calculation of the alpha varies slightly (see personalised_moving_average for a more detailed explanation of the alpha)

Parameters:

  • prices: list of floats or ints with oldest values at position 0 and newest value in position n

Example:

prices = [100, 102, 101 ... ]

sma = moving_averages.smoothed_moving_average(prices, 10, True)

personalised_moving_average(prices, period, alpha_nominator, alpha_denominator, fill_empty=False, fill_value=None)

The personalised moving average (PMA) allows you to determine your nominator and denominator values for the alpha. The alpha determines the impact of previous prices, the higher the alpha the lower past values have an impact. The calculation is as follows:

alpha = alpha_nominator / (length_prices + alpha_denominator)

The alpha_denominator may be a little confusing as it isn't itself the entire denominator, it is a variable that gets added to the length of the submitted prices to form the actual alpha_denominator.

The EMA used an alpha nominator of 2 and an alpha denominator of 1. The SMA used an alpha nominator of 1 and an alpha denominator of 0.

Parameters:

  • prices: list of floats or ints with oldest values at position 0 and newest value in position n
  • period: int, the number of prices that you would like taken into account to calculate the median.
  • alpha_nominator: float or int, can be 0, but it isn't recommended.
  • alpha_denominator: float or int, can be 0
  • fill_empty: Boolean, whether you want to fill the list with a value to match the length of the submitted prices. This is helpful when using this with Pandas as it will allow to insert the returned list directly into your DataFrame (see (Example)[https://github.com/0100101001010000/PyTechnicalIndicators_Examples/tree/main/Notebook_Example] )
  • fill_value: The value that you want used to fill in the empty spaces.

Example:

prices = [100, 102, 101 ... ]

pma = moving_averages.personalised_moving_average(prices, 15, 3, 2, True, prices[0])

moving_average_divergence_convergence(prices)

The moving average divergence convergence (MACD) only returns the MACD line, to get the single line you will need to call signal_line (detailed below), the histogram is simply one minus the other, and isn't yet provided here.

The moving_average_divergence_convergence requires the length of prices to be at least 26 as that is the number of periods taken into account, it accepts more, but discards the extra no passing them in will only impact your performance.

If you want to pass in a smaller or bigger period see personalised_macd.

Parameters:

  • prices: list of floats or ints with oldest values at position 0 and newest value in position n, must be at least 26 periods in length

Example:

prices = [100, 102, 101 ... ]

macd = moving_averages.moving_average_divergence_convergence(prices)

signal_line(macd)

The signal line returns the line that is complementary to moving_average_divergence_convergence, and is required to be 9 periods long, no more, no less. If you'd like to pass in a different amount see personalised_signal_line

Parameters:

  • macd: list of 9 macds retrieved from moving_average_divergence_convergence

Example:

macd = [1.2, 1.45, 0.98 ... ]

signal = moving_averages.signal_line(macd[:-9])

personalised_macd(prices, short_period, long_period, ma_model='ema')

The personalised macd allows you to determine what the short period and long period are for the macd calculation. Essentially the macd is the subsctraction of the EMA of the short period - the EMA of the long period, which are 12 and 26 respectively in the traditional MACD. Here we allow you to determine what those periods are. We also allow you to chose you moving average model in the event where you would prefer something other than the EMA.

Parameters:

  • prices: list of floats or ints with oldest values at position 0 and newest value in position n, the length of prices must be at least as big as the value for your long_period
  • short_period: int, value strictly greater than 0 but smaller than your long_period.
  • long_period: int, value strictly greater than the short period but smaller or equal to the length of prices.
  • ma_model: optional The moving average model of your choice (defaults to EMA):
    • for moving average either of the following: 'ma', 'moving average', 'moving_average'
    • for smoothed moving average either of the following: 'sma', 'smoothed moving average', 'smoothed_moving_average'
    • for exponential moving average either of the following: 'ema', 'exponential moving average', 'exponential_moving_average'

Example:

prices = [100, 102, 101 ... ]

pers_macd = moving_averages.personalised_macd(prices, 10, 20, 'smoothed moving average')

personalised_signal_line(macd, period, ma_model='ema')

The personalised signal line is similar to the personalised MACD in that it lets you decide of the length of the macds that you want to pass in, however is doesn't require you to insert a variable, it will instead just calculate it based on the length of the macd list provided.

You can also choose the MA model you would like to run, it is normally just a EMA but you are free to choose your model.personalised

Parameters:

  • macd: list of macds can be either from a normal macd or a personalised one. The length of the list needs to be greater than 1 and can be as large as you like.
  • period: int, the number of prices that you would like taken into account to calculate the median.
  • ma_model: optional The moving average model of your choice (defaults to EMA):
    • for moving average either of the following: 'ma', 'moving average', 'moving_average'
    • for smoothed moving average either of the following: 'sma', 'smoothed moving average', 'smoothed_moving_average'
    • for exponential moving average either of the following: 'ema', 'exponential moving average', 'exponential_moving_average'

Example:

macd = [1.2, 1.45, 0.98 ... ]

signal = moving_averages.personalised_signal_line(macd, 20, 'moving_average')

Strength Indicators

Calling stength indicators

from PyTechnicalIndicators.Single import strength_indicators

relative_strength_index(prices)

Returns the relative strength index (RSI) of submitted prices, the length of prices needs to be 14 periods long, no more, no less.

Parameters:

  • prices: list of floats or ints of prices that needs to be exactly 14 periods long.

Example:

prices = [100, 102, 101 ... ]

rsi = strength_indicators.relative_strength_index(prices)

personalised_rsi(prices, period, ma_model='sma')

The personalised RSI allows you to choose which MA model to use as well as the number of periods. The traditional RSI uses 14 periods and a SMA model.

Parameters:

  • prices: list of floats or int, the length of prices needs to be exactly of length of the period that you want to evaluate. than 1 and can be as large as you like.
  • period: int, the number of prices that you would like taken into account to calculate the median.
  • ma_model: optional The moving average model of your choice (defaults to SMA):
    • for moving average either of the following: 'ma', 'moving average', 'moving_average'
    • for smoothed moving average either of the following: 'sma', 'smoothed moving average', 'smoothed_moving_average'
    • for exponential moving average either of the following: 'ema', 'exponential moving average', 'exponential_moving_average'

Example:

prices = [100, 102, 101 ... ]

pers_rsi = strength_indicators.personalised_rsi(prices, 20,'ema')

stochastic_oscillator(close_prices)

Returns the stochastic oscillator (SO) for submitted close prices which need to be 14 periods long, no more, no less.

Parameters:

  • close_prices: list of floats or ints of closing prices that needs to be exactly 14 periods long.

Example:

close = [99, 103, 96 ... ]

so = strength_indicators.stochastic_oscillator(close)

personalised_stochastic_oscillator(close_prices, period)

The personalised version of the stochastic oscillator allows you to submit close prices of any length.

Parameters:

  • close_prices: list of floats or ints of closing prices, the length is of your choosing.
  • period: int, the number of prices that you would like taken into account to calculate the median.

Example:

close = [99, 103, 96 ... ]

pers_so = strength_indicators.personalised_stochastic_oscillator(close, 5)

Candle Indicators

Calling candle indicators

from PyTechnicalIndicators.Single import candle_indicators 

bollinger_bands(typical_prices, fill_empty=False, fill_value=None)

Returns the upper and lower Bollinger Band for a submitted typical prices, which need to be 20 periods long, no more, no less.

The typical price is calculated by taking the average of the High, Low, and Close ( (High + Low + Close) / 3 ).

Parameters:

  • typical_prices: a list of floats or ints of exactly 20 periods long.
  • fill_empty: Boolean, whether you want to fill the list with a value to match the length of the submitted prices. This is helpful when using this with Pandas as it will allow to insert the returned list directly into your DataFrame (see (Example)[https://github.com/0100101001010000/PyTechnicalIndicators_Examples/tree/main/Notebook_Example] )
  • fill_value: The value that you want used to fill in the empty spaces.

Example:

typical_prices = [100, 102, 101 ... ]

bband = candle_indicators.bollinger_bands(typical_prices, True, 0)

personalised_bollinger_bands(typical_price, period, ma_model='ma', stddev_multiplier=2, fill_empty=False, fill_value=None)

The personalised version allows you to choose the length of typical prices to submit as well as the MA model to run.

The traditional Bollinger Band model uses a MA and 20 periods.

Parameters:

  • typical_prices: a list of floats or ints of a chosen period period.
  • period: int, the number of prices that you would like taken into account to calculate the median.
  • ma_model: optional The moving average model of your choice (defaults to MA):
    • for moving average either of the following: 'ma', 'moving average', 'moving_average'
    • for smoothed moving average either of the following: 'sma', 'smoothed moving average', 'smoothed_moving_average'
    • for exponential moving average either of the following: 'ema', 'exponential moving average', 'exponential_moving_average'
  • stddev_multiplier: int or float, number of standard deviations, defaults to 2.
  • fill_empty: Boolean, whether you want to fill the list with a value to match the length of the submitted prices. This is helpful when using this with Pandas as it will allow to insert the returned list directly into your DataFrame (see (Example)[https://github.com/0100101001010000/PyTechnicalIndicators_Examples/tree/main/Notebook_Example] )
  • fill_value: The value that you want used to fill in the empty spaces.

Example:

typical_prices = [100, 102, 101 ... ]

pers_bband = candle_indicators.personalised_bollinger_bands(typical_prices, 10, 'ema', 1.5, True, None)

ichimoku_cloud(highs, lows, fill_empty=False, fill_value=None)

Returns the leading span A and leading span B, using the highs and lows of a series, these need to be 52 periods long, no more, no less.

Parameters:

  • highs: list of floats or ints of the highs of a series, needs to be 52 periods long.
  • lows: list of floats or ints of the lows of a series, needs to be 52 periods long.
  • fill_empty: Boolean, whether you want to fill the list with a value to match the length of the submitted prices. This is helpful when using this with Pandas as it will allow to insert the returned list directly into your DataFrame (see (Example)[https://github.com/0100101001010000/PyTechnicalIndicators_Examples/tree/main/Notebook_Example] )
  • fill_value: The value that you want used to fill in the empty spaces.

Example:

highs = [100, 102, 101 ... ]
lows = [90, 86, 92 ... ]

icloud = candle_indicators.ichimoku_cloud(highs, lows, True, 0)

personalised_ichimoku_cloud(highs, lows, conversion_period, base_period, span_b_period, fill_empty=False, fill_value=None)

The personalised version of the Ichimoku Cloud allows you to play around with the variables of the Ichimoku Cloud. These are rather involved so don't play around with them if you don't know what you're doing, or do, I won't judge.

Parameters:

  • highs: list of floats or ints of the highs of a series, needs to be 52 periods long.
  • lows: list of floats or ints of the lows of a series, needs to be 52 periods long.
  • conversion_period:
  • base_period:
  • span_b_period:
  • fill_empty: Boolean, whether you want to fill the list with a value to match the length of the submitted prices. This is helpful when using this with Pandas as it will allow to insert the returned list directly into your DataFrame (see (Example)[https://github.com/0100101001010000/PyTechnicalIndicators_Examples/tree/main/Notebook_Example] )
  • fill_value: The value that you want used to fill in the empty spaces.

Example:

highs = [100, 102, 101 ... ]
lows = [91, 95, 95 ... ]

pers_icloud = candle_indicators.personalised_ichimoku_cloud(highs, lows, , , )

Chart_Patterns

Chart patterns is a collection of functions to help highlight and break down trends in the data.

It is broken down in three parts:

  • peaks: highlights the peaks (highs) of a series
  • pits: highlights the pits (lows) of a series
  • trends: a set of functions to retrieve the trend as an int, angle...

peaks

Calling peaks

from PyTechnicalIndicators.Chart_Patterns import peaks

get_peaks(prices, period=5)

Gets the highest prices of a series within a predetermined period, and returns them as a list.

Parameters:

  • prices: list of floats or ints of the prices of a series.
  • period: optional int, number of prices before and after.

Example:

prices = [100, 102, 101 ... ]

peaks_list = peaks.get_peaks(prices, 2)

get_highest_peak(prices)

Returns the max of the previous function

Parameters:

  • prices: list of floats or ints of the prices of a series.

Example:

prices = [100, 102, 101 ... ]

max_pit = peaks.get_highest_peak(prices)

pits

Calling pits

from PyTechnicalIndicators.Chart_Patterns import pits

get_pits(prices, period=5)

Gets the lowest prices of a series within a predetermined period, and returns them as a list.

Parameters:

  • prices: list of floats or ints of the prices of a series.
  • period: optional int, number of prices before and after.

Example:

prices = [100, 102, 101 ... ]

pits_list = pits.get_pits(prices, 2)

get_lowest_pit(prices)

Returns the min of the previous function

Parameters:

  • prices: list of floats or ints of the prices of a series.

Example:

prices = [100, 102, 101 ... ]

min_pit = peaks.get_highest_peak(prices)

trends

Calling trends

from PyTechnicalIndicators.Chart_Patterns import trends

get_trend(p)

Gets the trend of a set of prices, mostly to be used by other functions in trends, but if you want to use it go for it. Returns a float.

Parameters:

  • p: list of floats or ints to retrieve a trend against.

Example:

# We wouldn't recommend using it like this...
prices = [100, 102, 101 ... ]

trend = trends.get_trend(prices)

get_peak_trend(prices)

Gets the peaks and determines the trend of the peaks. Returns a float.

Parameters:

  • prices: list of floats or ints of prices.

Example:

prices = [100, 102, 101 ... ]

peak_trend = trends.get_peak_trend(prices)

get_pit_trend(prices)

Gets the pits and determines the trend of the pits. Returns a float.

Parameters:

  • prices: list of floats or ints of prices.

Example:

prices = [100, 102, 101 ... ]

pit_trend = trends.get_pit_trend(prices)

get_overall_trend(prices)

Gets the pits and peaks, gets the trend of each, then returns the average of the two. Returns a float.

Parameters:

  • prices: list of floats or ints of prices.

Example:

prices = [100, 102, 101 ... ]

overall_trend = trends.get_overall_trend(prices)

get_trend_angle(price_a, index_a, price_b, index_b)

Determines the angle between two prices, price a should be the price and the start of the period, price b shoul be the price at the end of the period. Some people find this useful.

Parameters:

  • price_a: price a, needs to be before price b.
  • index_a: index of price a.
  • price_b: price b, needs to be after price a.
  • index_b: index of price b.

Example:

angle = trends.get_trend_angle(100, 0, 105, 10)

break_down_trends(prices, min_period=2, peaks_only=False, pits_only=False)

Breaks down the different trends in a series of prices into periods whose trends ressemble one anothers the most. Choosing peaks_only or pit_only will only return one otherwise the two will be returned by default.

Returns a list of tuples with (trend_start_index, trend_end_index, trend)

The Example notebook will illustrate this in an obvious manner.

Parameters:

  • prices: price a, needs to be before price b.
  • min_period: optional number of periods either side of the evaluated price to determine a pit or peak.
  • peaks_only: optional whether or not you only want peaks returned.
  • pits_only: optional whether or not you only want pits returned.

Example:

prices = [100, 102, 101 ... ]

angle = trends.break_down_trends(prices, 5)

merge_trends(typical_prices, min_period=2)

This breaks down the price series into different sections when their trends differ. It is similar to the above but takes into account both highs and lows and treats them as one.

Returns a list of tuples with (trend_start_index, trend_end_index, trend)

Parameters:

  • typical_prices:
  • min_period: optional number of periods either side of the evaluated price to determine a pit or peak

Example:

typical_prices = [100, 102, 101 ... ]

merge_trends = trends.merge_trends(prices, 1)

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

If you need ideas on where to start go to TODO, there will always be something that needs to be done...


License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PyTechnicalIndicators-1.0.10.tar.gz (27.2 kB view details)

Uploaded Source

Built Distribution

PyTechnicalIndicators-1.0.10-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

Details for the file PyTechnicalIndicators-1.0.10.tar.gz.

File metadata

  • Download URL: PyTechnicalIndicators-1.0.10.tar.gz
  • Upload date:
  • Size: 27.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5

File hashes

Hashes for PyTechnicalIndicators-1.0.10.tar.gz
Algorithm Hash digest
SHA256 a94b910401b4f7671cb334e2509bd7149fd18f4c58f1d7df4a554e481a49574d
MD5 68e67b4f4d21ebb9af947317ad8483e8
BLAKE2b-256 28c49a2a192ca17f2c52ee5a9752b5292edab9b8e7aca73f6ad321da757e3822

See more details on using hashes here.

File details

Details for the file PyTechnicalIndicators-1.0.10-py3-none-any.whl.

File metadata

  • Download URL: PyTechnicalIndicators-1.0.10-py3-none-any.whl
  • Upload date:
  • Size: 19.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5

File hashes

Hashes for PyTechnicalIndicators-1.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 5dcac6c5569cdedc33fb5b80b025a1cd8b0e17f9560223833f9b284886122af9
MD5 4c6b56f9499a988c262cc72d13d928ca
BLAKE2b-256 1138d8e8dc8a2040775fbbc2ddfea5248726fe4fc3a0a6f0f528eb00c3f3ca06

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page