Skip to content

Commit

Permalink
several changes
Browse files Browse the repository at this point in the history
- add identify_all_trends function
- handled overlapped trends
- identify_trends modified to adapt to overlapped trends handling
- tests updated to cover trendet
- updated docs
  • Loading branch information
Álvaro Bartolomé del Canto committed Aug 23, 2019
1 parent c376c83 commit 4a3042f
Show file tree
Hide file tree
Showing 13 changed files with 377 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dist: xenial

install:
- pip install -r requirements.txt
- pip install trendet==0.2
- pip install trendet==0.3
- pip install pytest==5.1.0
- pip install codecov==2.0.15
- pip install pytest-cov==2.7.1
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ In order to get this package working you will need to install it using pip by ty

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

``$ python -m pip install trendet==0.2``
``$ python -m pip install trendet==0.3``

## Usage

Expand Down Expand Up @@ -88,6 +88,10 @@ with plt.style.context('paper'):
plt.show()
````

Further usage insights can be found on the [docs](https://trendet.readthedocs.io/) or on the following
[gist](https://gist.github.com/alvarob96/98f94dcfec59f78a16ad2edbf464ce75#file-identify_all_trends-py). 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.

## Contribute

As this is an open source project it is open to contributions, bug reports, bug fixes, documentation improvements,
Expand Down
7 changes: 7 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
API Reference
=============

.. toctree::
:maxdepth: 2

trendet.rst
7 changes: 6 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@

# -- Project information -----------------------------------------------------

import sys
import os

sys.path.insert(0, os.path.abspath('..'))

project = 'trendet'
copyright = '2019, Alvaro Bartolome del Canto'
author = 'Alvaro Bartolome del Canto'

# The full version, including alpha/beta/rc tags
release = '0.2'
release = '0.3'


# -- General configuration ---------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Welcome to trendet's documentation!
introduction.rst
installation.rst
usage.rst
api.rst
contribute.rst
disclaimer.rst

Expand Down
2 changes: 1 addition & 1 deletion docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ In order to get this package working you will need to install it using pip by ty

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

$ python -m pip install trendet==0.2
$ python -m pip install trendet==0.3
7 changes: 7 additions & 0 deletions docs/trendet.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
:mod:`trendet`
========================

.. automodule:: trendet
:special-members:
:exclude-members:
:members:
Binary file added docs/trendet_example_all.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 58 additions & 0 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,62 @@ to Z by default.
So on, the resulting plot which will be outputted from the previous block of code will look like:

.. image:: https://raw.githubusercontent.com/alvarob96/trendet/master/docs/trendet_example.png
:align: center

Additionally **trendet** allows the user to identify/detect all the up and down trends on the market
via the function `identify_all_trends` which has been included in 0.3 release. So on, the sample code for
its usage is as follows:

.. code-block:: python
import trendet
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(style='darkgrid')
df = identify_all_trends(equity='bbva',
from_date='01/01/2018',
to_date='01/01/2019',
window_size=5)
df.reset_index(inplace=True)
with plt.style.context('paper'):
plt.figure(figsize=(20, 10))
ax = sns.lineplot(x=df['Date'], y=df['Close'])
labels = df['Up Trend'].dropna().unique().tolist()
for label in labels:
sns.lineplot(x=df[df['Up Trend'] == label]['Date'],
y=df[df['Up Trend'] == label]['Close'],
color='green')
ax.axvspan(df[df['Up Trend'] == label]['Date'].iloc[0],
df[df['Up Trend'] == label]['Date'].iloc[-1],
alpha=0.2,
color='green')
labels = df['Down Trend'].dropna().unique().tolist()
for label in labels:
sns.lineplot(x=df[df['Down Trend'] == label]['Date'],
y=df[df['Down Trend'] == label]['Close'],
color='red')
ax.axvspan(df[df['Down Trend'] == label]['Date'].iloc[0],
df[df['Down Trend'] == label]['Date'].iloc[-1],
alpha=0.2,
color='red')
plt.show()
Which as described before, plots all the trends identified on the specified stock time series
data removing overlapped trends keeping just the longer trend as minor trends are ignored. So the
output of the previous block of code on **trendet** usage is the following plot:

.. image:: https://raw.githubusercontent.com/alvarob96/trendet/master/docs/trendet_example_all.png
:align: center
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ def readme():

setup(
name='trendet',
version='0.2',
version='0.3',
packages=find_packages(),
url='https://github.com/alvarob96/trendet',
download_url='https://github.com/alvarob96/trendet/archive/0.2.tar.gz',
download_url='https://github.com/alvarob96/trendet/archive/0.3.tar.gz',
license='MIT License',
author='Alvaro Bartolome',
author_email='alvarob96@usal.es',
Expand Down
29 changes: 20 additions & 9 deletions tests/test_trendet.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,32 @@
import pytest

import trendet
import investpy


def test_trendet():
"""
This function checks that main functions of trendet work properly.
"""

print(trendet.__author__)
print(trendet.__version__)
author = trendet.__author__
version = trendet.__version__

params = [
{
'equity': 'bbva',
equities = investpy.get_equities_list()

params = list()

for equity in equities[:15]:
obj = {
'equity': equity,
'from_date': '01/01/2018',
'to_date': '01/01/2019',
'window_size': 5,
'trend_limit': 3,
'trend_limit': 5,
'labels': None,
},
]
}

params.append(obj)

for param in params:
trendet.identify_trends(equity=param['equity'],
Expand All @@ -35,6 +41,11 @@ def test_trendet():
trend_limit=param['trend_limit'],
labels=param['labels'])

trendet.identify_all_trends(equity=param['equity'],
from_date=param['from_date'],
to_date=param['to_date'],
window_size=param['window_size'])


if __name__ == '__main__':
test_trendet()
test_trendet()
15 changes: 10 additions & 5 deletions tests/test_trendet_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ def test_errors():
This function raises trendet errors to improve coverage
"""

print(trendet.__author__)
print(trendet.__version__)

params = [
{
'equity': ['error'],
Expand Down Expand Up @@ -164,8 +161,16 @@ def test_errors():
trend_limit=param['trend_limit'],
labels=param['labels'])
except:
continue
pass

try:
trendet.identify_all_trends(equity=param['equity'],
from_date=param['from_date'],
to_date=param['to_date'],
window_size=param['window_size'])
except:
pass


if __name__ == '__main__':
test_errors()
test_errors()
Loading

0 comments on commit 4a3042f

Please sign in to comment.