Skip to content

Commit 4a3042f

Browse files
author
Álvaro Bartolomé del Canto
committed
several changes
- add identify_all_trends function - handled overlapped trends - identify_trends modified to adapt to overlapped trends handling - tests updated to cover trendet - updated docs
1 parent c376c83 commit 4a3042f

13 files changed

+377
-33
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ dist: xenial
99

1010
install:
1111
- pip install -r requirements.txt
12-
- pip install trendet==0.2
12+
- pip install trendet==0.3
1313
- pip install pytest==5.1.0
1414
- pip install codecov==2.0.15
1515
- pip install pytest-cov==2.7.1

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ In order to get this package working you will need to install it using pip by ty
2828

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

31-
``$ python -m pip install trendet==0.2``
31+
``$ python -m pip install trendet==0.3``
3232

3333
## Usage
3434

@@ -88,6 +88,10 @@ with plt.style.context('paper'):
8888
plt.show()
8989
````
9090

91+
Further usage insights can be found on the [docs](https://trendet.readthedocs.io/) or on the following
92+
[gist](https://gist.github.com/alvarob96/98f94dcfec59f78a16ad2edbf464ce75#file-identify_all_trends-py). Anyways,
93+
feel free to create your own scripts on how you use **trendet** or how can it be used in order to improve its features.
94+
9195
## Contribute
9296

9397
As this is an open source project it is open to contributions, bug reports, bug fixes, documentation improvements,

docs/api.rst

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
API Reference
2+
=============
3+
4+
.. toctree::
5+
:maxdepth: 2
6+
7+
trendet.rst

docs/conf.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,17 @@
1717

1818
# -- Project information -----------------------------------------------------
1919

20+
import sys
21+
import os
22+
23+
sys.path.insert(0, os.path.abspath('..'))
24+
2025
project = 'trendet'
2126
copyright = '2019, Alvaro Bartolome del Canto'
2227
author = 'Alvaro Bartolome del Canto'
2328

2429
# The full version, including alpha/beta/rc tags
25-
release = '0.2'
30+
release = '0.3'
2631

2732

2833
# -- General configuration ---------------------------------------------------

docs/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Welcome to trendet's documentation!
1616
introduction.rst
1717
installation.rst
1818
usage.rst
19+
api.rst
1920
contribute.rst
2021
disclaimer.rst
2122

docs/installation.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ In order to get this package working you will need to install it using pip by ty
77

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

10-
$ python -m pip install trendet==0.2
10+
$ python -m pip install trendet==0.3

docs/trendet.rst

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
:mod:`trendet`
2+
========================
3+
4+
.. automodule:: trendet
5+
:special-members:
6+
:exclude-members:
7+
:members:

docs/trendet_example_all.png

287 KB
Loading

docs/usage.rst

+58
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,62 @@ to Z by default.
6060
So on, the resulting plot which will be outputted from the previous block of code will look like:
6161

6262
.. image:: https://raw.githubusercontent.com/alvarob96/trendet/master/docs/trendet_example.png
63+
:align: center
64+
65+
Additionally **trendet** allows the user to identify/detect all the up and down trends on the market
66+
via the function `identify_all_trends` which has been included in 0.3 release. So on, the sample code for
67+
its usage is as follows:
68+
69+
.. code-block:: python
70+
71+
import trendet
72+
73+
import matplotlib.pyplot as plt
74+
import seaborn as sns
75+
76+
sns.set(style='darkgrid')
77+
78+
df = identify_all_trends(equity='bbva',
79+
from_date='01/01/2018',
80+
to_date='01/01/2019',
81+
window_size=5)
82+
83+
df.reset_index(inplace=True)
84+
85+
with plt.style.context('paper'):
86+
plt.figure(figsize=(20, 10))
87+
88+
ax = sns.lineplot(x=df['Date'], y=df['Close'])
89+
90+
labels = df['Up Trend'].dropna().unique().tolist()
91+
92+
for label in labels:
93+
sns.lineplot(x=df[df['Up Trend'] == label]['Date'],
94+
y=df[df['Up Trend'] == label]['Close'],
95+
color='green')
96+
97+
ax.axvspan(df[df['Up Trend'] == label]['Date'].iloc[0],
98+
df[df['Up Trend'] == label]['Date'].iloc[-1],
99+
alpha=0.2,
100+
color='green')
101+
102+
labels = df['Down Trend'].dropna().unique().tolist()
103+
104+
for label in labels:
105+
sns.lineplot(x=df[df['Down Trend'] == label]['Date'],
106+
y=df[df['Down Trend'] == label]['Close'],
107+
color='red')
108+
109+
ax.axvspan(df[df['Down Trend'] == label]['Date'].iloc[0],
110+
df[df['Down Trend'] == label]['Date'].iloc[-1],
111+
alpha=0.2,
112+
color='red')
113+
114+
plt.show()
115+
116+
Which as described before, plots all the trends identified on the specified stock time series
117+
data removing overlapped trends keeping just the longer trend as minor trends are ignored. So the
118+
output of the previous block of code on **trendet** usage is the following plot:
119+
120+
.. image:: https://raw.githubusercontent.com/alvarob96/trendet/master/docs/trendet_example_all.png
63121
:align: center

setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ def readme():
1111

1212
setup(
1313
name='trendet',
14-
version='0.2',
14+
version='0.3',
1515
packages=find_packages(),
1616
url='https://github.com/alvarob96/trendet',
17-
download_url='https://github.com/alvarob96/trendet/archive/0.2.tar.gz',
17+
download_url='https://github.com/alvarob96/trendet/archive/0.3.tar.gz',
1818
license='MIT License',
1919
author='Alvaro Bartolome',
2020
author_email='[email protected]',

tests/test_trendet.py

+20-9
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,32 @@
66
import pytest
77

88
import trendet
9+
import investpy
910

1011

1112
def test_trendet():
1213
"""
1314
This function checks that main functions of trendet work properly.
1415
"""
1516

16-
print(trendet.__author__)
17-
print(trendet.__version__)
17+
author = trendet.__author__
18+
version = trendet.__version__
1819

19-
params = [
20-
{
21-
'equity': 'bbva',
20+
equities = investpy.get_equities_list()
21+
22+
params = list()
23+
24+
for equity in equities[:15]:
25+
obj = {
26+
'equity': equity,
2227
'from_date': '01/01/2018',
2328
'to_date': '01/01/2019',
2429
'window_size': 5,
25-
'trend_limit': 3,
30+
'trend_limit': 5,
2631
'labels': None,
27-
},
28-
]
32+
}
33+
34+
params.append(obj)
2935

3036
for param in params:
3137
trendet.identify_trends(equity=param['equity'],
@@ -35,6 +41,11 @@ def test_trendet():
3541
trend_limit=param['trend_limit'],
3642
labels=param['labels'])
3743

44+
trendet.identify_all_trends(equity=param['equity'],
45+
from_date=param['from_date'],
46+
to_date=param['to_date'],
47+
window_size=param['window_size'])
48+
3849

3950
if __name__ == '__main__':
40-
test_trendet()
51+
test_trendet()

tests/test_trendet_errors.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ def test_errors():
1313
This function raises trendet errors to improve coverage
1414
"""
1515

16-
print(trendet.__author__)
17-
print(trendet.__version__)
18-
1916
params = [
2017
{
2118
'equity': ['error'],
@@ -164,8 +161,16 @@ def test_errors():
164161
trend_limit=param['trend_limit'],
165162
labels=param['labels'])
166163
except:
167-
continue
164+
pass
165+
166+
try:
167+
trendet.identify_all_trends(equity=param['equity'],
168+
from_date=param['from_date'],
169+
to_date=param['to_date'],
170+
window_size=param['window_size'])
171+
except:
172+
pass
168173

169174

170175
if __name__ == '__main__':
171-
test_errors()
176+
test_errors()

0 commit comments

Comments
 (0)