@@ -60,4 +60,62 @@ to Z by default.
60
60
So on, the resulting plot which will be outputted from the previous block of code will look like:
61
61
62
62
.. 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
63
121
:align: center
0 commit comments