1
1
# -*- coding:utf-8 -*-
2
- from collections import OrderedDict
2
+ import talib
3
3
4
- from cycle import Cycle
5
- from momentum import Momentum
6
- from overlap import Overlap
7
- from pattern import Pattern
8
- from statistic import Statistic
9
- from volatility import Volatility
10
- from volume import Volume
4
+ import cycle
5
+ import experimental
6
+ import momentum
7
+ import overlap
8
+ import pattern
9
+ import prices
10
+ import statistic
11
+ import volatility
12
+ import volume
13
+
14
+ # from cycle import *
15
+ # from momentum import *
16
+ # from overlap import *
17
+ # from pattern import *
18
+ # from statistic import *
19
+ # from volatility import *
20
+ # from experimental import *
21
+ # from prices import *
22
+ # from volume import *
23
+
24
+ _function_list = [f for f in
25
+ (* cycle .__all__ , * momentum .__all__ , * overlap .__all__ , * volatility .__all__ , * pattern .__all__ ,
26
+ * statistic .__all__ , * experimental .__all__ , * prices .__all__ ) if f [0 ].isupper ()]
27
+ __all__ = ['TaLib' ]
11
28
12
29
13
30
# noinspection SpellCheckingInspection
@@ -17,23 +34,21 @@ class TaLib:
17
34
"""
18
35
19
36
_groups_ref = {
20
- 'Cycle Indicators' : 'Cyl' ,
21
- 'Momentum Indicators' : 'Mom' ,
22
- 'Overlap studies' : 'Ovlap' ,
23
- 'Patter Recognition' : 'Pattr' ,
24
- 'Statistic Functions' : 'Stat' ,
25
- 'Volume Indicators' : 'Vol' ,
26
- 'Volatility Indicators' : 'Volat'
37
+ 'cycle' : cycle .__all__ ,
38
+ 'momentum' : momentum .__all__ ,
39
+ 'overlap' : overlap .__all__ ,
40
+ 'patter' : pattern .__all__ ,
41
+ 'statistic' : statistic .__all__ ,
42
+ 'volume' : volatility .__all__ ,
43
+ 'volatility' : experimental .__all__ ,
44
+ 'price' : prices .__all__ ,
45
+ 'experimental' : volume .__all__
27
46
}
28
47
29
- Volat = Volatility
30
- Olap = Overlap
31
- Mom = Momentum
32
- Cycl = Cycle
33
- Vol = Volume
34
- Pattr = Pattern
35
- Stat = Statistic
36
-
48
+ @classmethod
49
+ def calculate_indicator (cls , indicator , * args , ** kwargs ):
50
+ fn = globals ().get (indicator )
51
+ return fn (* args , ** kwargs )
37
52
38
53
@classmethod
39
54
def get_groups (cls ):
@@ -42,11 +57,17 @@ def get_groups(cls):
42
57
43
58
:return: groups names
44
59
"""
45
- groups = OrderedDict ().fromkeys (sorted ([grp for grp in cls .__dict__ if grp [0 ].isupper ()]))
46
- for grp in groups :
47
- groups .update ({grp : [fn for fn in cls .__dict__ [grp ].__dict__ if fn [0 ].isupper ()]})
48
- return groups
49
60
61
+ return sorted ([* cls ._groups_ref ])
62
+
63
+ @classmethod
64
+ def get_talib_groups (cls ):
65
+ """
66
+ Just return groups names
67
+
68
+ :return: groups names
69
+ """
70
+ return sorted ([* talib .get_function_groups ().keys ()])
50
71
51
72
@classmethod
52
73
def get_functions (cls ):
@@ -55,34 +76,18 @@ def get_functions(cls):
55
76
56
77
:return: all functions supported by this lib
57
78
"""
58
- result = list ()
59
- for grp in cls .get_groups ().values ():
60
- result .extend (grp )
61
- return sorted (result )
62
79
80
+ return sorted (sum (cls ._groups_ref .values (), []))
63
81
64
82
@classmethod
65
- def get_function_group (cls , name , display_name = False ):
83
+ def get_talib_functions (cls ):
66
84
"""
67
- Get functions grouped by type
85
+ Return all functions supported by this lib
68
86
69
- :param str name: function name
70
- :param bool display_name: if True, full names will be show instead shorted ones
71
- :return: functions grouped by type
87
+ :return: all functions supported by this lib
72
88
"""
73
- name = str (name ).upper ()
74
- if name in cls .get_functions ():
75
- if name in cls .Pattr .__dict__ :
76
- return cls .Pattr .__name__ if display_name is True else 'Pattr'
77
- elif name in cls .Mom .__dict__ :
78
- return cls .Mom .__name__ if display_name is True else 'Mom'
79
- elif name in cls .Olap .__dict__ :
80
- return cls .Olap .__name__ if display_name is True else 'Olap'
81
- elif name in cls .Vol .__dict__ :
82
- return cls .Vol .__name__ if display_name is True else 'Vol'
83
- elif name in cls .Cycl .__dict__ :
84
- return cls .Cycl .__name__ if display_name is True else 'Cycl'
85
- elif name in cls .Stat .__dict__ :
86
- return cls .Stat .__name__ if display_name is True else 'Stat'
87
- elif name in cls .Volat .__dict__ :
88
- return cls .Volat .__name__ if display_name is True else 'Volat'
89
+ return sorted ([* talib .get_function_groups ().values ()])
90
+
91
+
92
+ if __name__ == '__main__' :
93
+ print (TaLib .get_functions ())
0 commit comments