-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
cycle_indicators.py
66 lines (55 loc) · 1.33 KB
/
cycle_indicators.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
""""""
# Import Built-Ins:
# Import Third-Party:
# Import Homebrew:
import jhtalib as jhta
def HT_DCPERIOD(df, price='Close'):
"""
Hilbert Transform - Dominant Cycle Period
"""
def HT_DCPHASE(df, price='Close'):
"""
Hilbert Transform - Dominant Cycle Phase
"""
def HT_PHASOR(df, price='Close'):
"""
Hilbert Transform - Phasor Components
"""
def HT_SINE(df, price='Close'):
"""
Hilbert Transform - SineWave
"""
def HT_TRENDLINE(df, price='Close'):
"""
Hilbert Transform - Instantaneous Trendline
"""
def HT_TRENDMODE(df, price='Close'):
"""
Hilbert Transform - Trend vs Cycle Mode
"""
def TS(df, n, price='Close'):
"""
Trend Score
Returns: list of floats = jhta.TS(df, n, price='Close')
Source: https://www.fmlabs.com/reference/default.htm?url=TrendScore.htm
"""
t_list = []
for i in range(len(df[price])):
if i < 1:
t = 0
else:
if df[price][i] >= df[price][i - 1]:
t = 1
else:
t = -1
t_list.append(t)
ts_list = []
for i in range(len(df[price])):
if i + 1 < n:
ts = float('NaN')
else:
start = i + 1 - n
end = i + 1
ts = sum(t_list[start:end])
ts_list.append(ts)
return ts_list