Skip to content

Commit 08a85eb

Browse files
committed
added local max function
1 parent 7fb533b commit 08a85eb

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

Patterns/TrendLine.py

+37-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
## Requires Python 3
2+
13
import numpy as np
2-
#import pandas.io.data as pd
34
from matplotlib.pyplot import plot, grid, show
45
from pandas_datareader import data, wb
56
import pandas as pd
@@ -55,3 +56,38 @@ def trendGen(xDat, window=1.0/3.0, needPlot=True):
5556
dat = data.DataReader("BABA", "yahoo")['Adj Close']
5657

5758
trendGen(dat, window = 1.0/3)
59+
60+
61+
def findTops(x, window=1.0/3, charts=True):
62+
63+
x = np.array(x)
64+
xLen = len(x)
65+
66+
if window < 1:
67+
window = int(window * xLen)
68+
69+
sigs = np.zeros(xLen, dtype=float)
70+
71+
i = window
72+
73+
while i != xLen:
74+
if x[i] > max(x[i-window:i]): sigs[i] = 1
75+
elif x[i] < min(x[i-window:i]): sigs[i] = -1
76+
i += 1
77+
78+
xmin = np.where(sigs == -1.0)[0]
79+
xmax = np.where(sigs == 1.0)[0]
80+
81+
ymin = x[xmin]
82+
ymax = x[xmax]
83+
84+
if charts is True:
85+
plot(x)
86+
plot(xmin, ymin, 'ro')
87+
plot(xmax, ymax, 'go')
88+
show()
89+
90+
return sigs
91+
92+
93+
findTop(dat, window = 1.0/3)

0 commit comments

Comments
 (0)