Need help with trendet?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

236 Stars 52 Forks MIT License 39 Commits 6 Opened issues


:chart_with_upwards_trend: Python package for trend detection on stock time series data :chart_with_downwards_trend:

Services available


Need anything else?

Contributors list

# 39,225
34 commits

trendet - Trend detection on stock time series data

Python Version PyPi Version Package Status Build Status Build Status Documentation Status codecov Downloads


trendet is a Python package to detect trends on the market so to analyze its behaviour. So on, this package has been created to support investpy features when it comes to data retrieval from different financial products such as stocks, funds or ETFs; and it is intended to be combined with it, but also with every

, formatted as OHLC.

Anyways, trendet can also be used to identify trends from any

which contains any column with
values, even though it is intended to be used with stock data; it can also be used for any


In order to get this package working you will need to install it using pip by typing on the terminal:

$ python -m pip install trendet --upgrade

Or just install the current release or a specific release version such as:

$ python -m pip install trendet==0.7


As trendet is intended to be combined with investpy, the main functionality is to detect trends on stock time series data so to analyse the market and which behaviour does it have in certain date ranges.

In the example presented below, the

function will be used to detect every bearish/bullish trend with a time window above 5 days, which, for example, implies that every bearish (decreasing) trend with a longer length than 5 days will be identified as a down trend and so on added to a
which already contains OHLC values, in new columns called Up Trend and Down Trend which will be labeled as specified, with letters from A to Z by default.
import trendet

import matplotlib.pyplot as plt import seaborn as sns


df = trendet.identify_all_trends(stock='BBVA', country='Spain', from_date='01/01/2018', to_date='01/01/2019', window_size=5, identify='both')


plt.figure(figsize=(20, 10))

ax = sns.lineplot(x=df.index, y=df['Close']) ax.set(xlabel='Date')

labels = df['Up Trend'].dropna().unique().tolist()

for label in labels: sns.lineplot(x=df[df['Up Trend'] == label].index, y=df[df['Up Trend'] == label]['Close'], color='green')

ax.axvspan(df[df['Up Trend'] == label].index[0],
           df[df['Up Trend'] == label].index[-1],

labels = df['Down Trend'].dropna().unique().tolist()

for label in labels: sns.lineplot(x=df[df['Down Trend'] == label].index, y=df[df['Down Trend'] == label]['Close'], color='red')

ax.axvspan(df[df['Down Trend'] == label].index[0],
           df[df['Down Trend'] == label].index[-1],

locs, _ = plt.xticks() labels = []

for position in locs[1:-1]: labels.append(str(df['Date'].loc[position])[:-9])

plt.xticks(locs[1:-1], labels)

Further usage insights can be found on the docs or on the following gist. Anyways, feel free to create your own scripts on how you use trendet or how can it be used in order to improve its features.


As this is an open source project it is open to contributions, bug reports, bug fixes, documentation improvements, enhancements and ideas.

Also there is an open tab of issues where anyone can contribute opening new issues if needed or navigate through them in order to solve them or contribute to its solving.


This package has been created so to identify market trends based on stock historical data retrieved via investpy so to determine which trends have been prevailing on the market based on a single stock OHLC values.

Conclude that this is the result of a research project, so this package has been developed with research purposes and no profit is intended.

Plots have been generated with both matplotlib and seaborn.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.