siglab-py 0.5.39__py3-none-any.whl → 0.5.48__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of siglab-py might be problematic. Click here for more details.
- siglab_py/tests/unit/analytic_util_tests.py +4 -2
- siglab_py/tests/unit/simple_math_tests.py +87 -0
- siglab_py/util/analytic_util.py +9 -0
- siglab_py/util/simple_math.py +30 -0
- {siglab_py-0.5.39.dist-info → siglab_py-0.5.48.dist-info}/METADATA +1 -1
- {siglab_py-0.5.39.dist-info → siglab_py-0.5.48.dist-info}/RECORD +8 -6
- {siglab_py-0.5.39.dist-info → siglab_py-0.5.48.dist-info}/WHEEL +0 -0
- {siglab_py-0.5.39.dist-info → siglab_py-0.5.48.dist-info}/top_level.txt +0 -0
|
@@ -45,18 +45,20 @@ class AnalyticUtilTests(unittest.TestCase):
|
|
|
45
45
|
'exchange', 'symbol', 'timestamp_ms',
|
|
46
46
|
'open', 'high', 'low', 'close', 'volume',
|
|
47
47
|
'datetime', 'datetime_utc', 'year', 'month', 'day', 'hour', 'minute', 'dayofweek',
|
|
48
|
-
'pct_chg_on_close', 'candle_height',
|
|
48
|
+
'pct_chg_on_close', 'candle_height', 'candle_body_height',
|
|
49
49
|
'week_of_month', 'apac_trading_hr', 'emea_trading_hr', 'amer_trading_hr',
|
|
50
50
|
'is_green', 'pct_change_close',
|
|
51
51
|
'sma_short_periods', 'sma_long_periods', 'ema_short_periods', 'ema_long_periods', 'ema_close',
|
|
52
52
|
'std', 'std_percent',
|
|
53
53
|
'vwap_short_periods', 'vwap_long_periods',
|
|
54
|
-
'candle_height_percent', 'candle_height_percent_rounded',
|
|
54
|
+
'candle_height_percent', 'candle_height_percent_rounded', 'candle_body_height_percent', 'candle_body_height_percent_rounded',
|
|
55
55
|
'log_return', 'interval_hist_vol', 'annualized_hist_vol',
|
|
56
56
|
'chop_against_ema',
|
|
57
57
|
'ema_volume_short_periods', 'ema_volume_long_periods',
|
|
58
58
|
'ema_cross', 'ema_cross_last', 'ema_bullish_cross_last_id', 'ema_bearish_cross_last_id',
|
|
59
59
|
'max_short_periods', 'max_long_periods', 'idmax_short_periods', 'idmax_long_periods', 'min_short_periods', 'min_long_periods', 'idmin_short_periods', 'idmin_long_periods',
|
|
60
|
+
'max_candle_body_height_percent_long_periods', 'idmax_candle_body_height_percent_long_periods',
|
|
61
|
+
'min_candle_body_height_percent_long_periods', 'idmin_candle_body_height_percent_long_periods',
|
|
60
62
|
'price_swing_short_periods', 'price_swing_long_periods',
|
|
61
63
|
'trend_from_highs_long_periods', 'trend_from_lows_long_periods', 'trend_from_highs_short_periods', 'trend_from_lows_short_periods',
|
|
62
64
|
'h_l', 'h_pc', 'l_pc', 'tr', 'atr', 'atr_avg_short_periods', 'atr_avg_long_periods',
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from typing import List
|
|
3
|
+
|
|
4
|
+
from util.simple_math import generate_rand_nums
|
|
5
|
+
|
|
6
|
+
class SimpleMathTests(unittest.TestCase):
|
|
7
|
+
|
|
8
|
+
def test_generate_rand_nums(self):
|
|
9
|
+
range_min : float = 0
|
|
10
|
+
range_max : float = 1
|
|
11
|
+
size : int = 100
|
|
12
|
+
percentage_in_range : float = 91
|
|
13
|
+
abs_min : float = -0.5
|
|
14
|
+
abs_max : float = 1.1
|
|
15
|
+
|
|
16
|
+
rand_nums : List[float] = generate_rand_nums(
|
|
17
|
+
range_min = range_min,
|
|
18
|
+
range_max = range_max,
|
|
19
|
+
size = size,
|
|
20
|
+
percent_in_range = percentage_in_range,
|
|
21
|
+
abs_min = abs_min,
|
|
22
|
+
abs_max = abs_max
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
assert(len(rand_nums)==size)
|
|
26
|
+
assert(len([x for x in rand_nums if x>=range_min and x<=range_max]) == (percentage_in_range/100) * size)
|
|
27
|
+
assert(len([x for x in rand_nums if x<abs_min or x>abs_max]) == 0)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
range_min = -1
|
|
31
|
+
range_max = 1
|
|
32
|
+
percentage_in_range = 91
|
|
33
|
+
abs_min = -1.5
|
|
34
|
+
abs_max = 1.5
|
|
35
|
+
|
|
36
|
+
rand_nums : List[float] = generate_rand_nums(
|
|
37
|
+
range_min = range_min,
|
|
38
|
+
range_max = range_max,
|
|
39
|
+
size = size,
|
|
40
|
+
percent_in_range = percentage_in_range,
|
|
41
|
+
abs_min = abs_min,
|
|
42
|
+
abs_max = abs_max
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
assert(len(rand_nums)==size)
|
|
46
|
+
assert(len([x for x in rand_nums if x>=range_min and x<=range_max]) == (percentage_in_range/100) * size)
|
|
47
|
+
assert(len([x for x in rand_nums if x<abs_min or x>abs_max]) == 0)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
range_min = 0
|
|
51
|
+
range_max = 100
|
|
52
|
+
percentage_in_range = 91
|
|
53
|
+
abs_min = -150
|
|
54
|
+
abs_max = 150
|
|
55
|
+
|
|
56
|
+
rand_nums : List[float] = generate_rand_nums(
|
|
57
|
+
range_min = range_min,
|
|
58
|
+
range_max = range_max,
|
|
59
|
+
size = size,
|
|
60
|
+
percent_in_range = percentage_in_range,
|
|
61
|
+
abs_min = abs_min,
|
|
62
|
+
abs_max = abs_max
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
assert(len(rand_nums)==size)
|
|
66
|
+
assert(len([x for x in rand_nums if x>=range_min and x<=range_max]) == (percentage_in_range/100) * size)
|
|
67
|
+
assert(len([x for x in rand_nums if x<abs_min or x>abs_max]) == 0)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
range_min = -100
|
|
71
|
+
range_max = 100
|
|
72
|
+
percentage_in_range = 91
|
|
73
|
+
abs_min = -150
|
|
74
|
+
abs_max = 150
|
|
75
|
+
|
|
76
|
+
rand_nums : List[float] = generate_rand_nums(
|
|
77
|
+
range_min = range_min,
|
|
78
|
+
range_max = range_max,
|
|
79
|
+
size = size,
|
|
80
|
+
percent_in_range = percentage_in_range,
|
|
81
|
+
abs_min = abs_min,
|
|
82
|
+
abs_max = abs_max
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
assert(len(rand_nums)==size)
|
|
86
|
+
assert(len([x for x in rand_nums if x>=range_min and x<=range_max]) == (percentage_in_range/100) * size)
|
|
87
|
+
assert(len([x for x in rand_nums if x<abs_min or x>abs_max]) == 0)
|
siglab_py/util/analytic_util.py
CHANGED
|
@@ -121,6 +121,7 @@ def compute_candles_stats(
|
|
|
121
121
|
pypy_compat : bool = True
|
|
122
122
|
):
|
|
123
123
|
pd_candles['candle_height'] = pd_candles['high'] - pd_candles['low']
|
|
124
|
+
pd_candles['candle_body_height'] = pd_candles['close'] - pd_candles['open']
|
|
124
125
|
|
|
125
126
|
'''
|
|
126
127
|
market_data_gizmo inserted dummy lines --> Need exclude those or "TypeError: unorderable types for comparison": pd_btc_candles = pd_btc_candles[pd_btc_candles.close.notnull()]
|
|
@@ -157,6 +158,9 @@ def compute_candles_stats(
|
|
|
157
158
|
pd_candles['candle_height_percent'] = pd_candles['candle_height'] / pd_candles['ema_close'] * 100
|
|
158
159
|
pd_candles['candle_height_percent_rounded'] = pd_candles['candle_height_percent'].round().astype('Int64')
|
|
159
160
|
|
|
161
|
+
pd_candles['candle_body_height_percent'] = pd_candles['candle_body_height'] / pd_candles['ema_close'] * 100
|
|
162
|
+
pd_candles['candle_body_height_percent_rounded'] = pd_candles['candle_body_height_percent'].round().astype('Int64')
|
|
163
|
+
|
|
160
164
|
'''
|
|
161
165
|
To annualize volatility:
|
|
162
166
|
if candle_interval == '1m':
|
|
@@ -235,6 +239,11 @@ def compute_candles_stats(
|
|
|
235
239
|
pd_candles['idmin_short_periods'] = close_short_periods_rolling.apply(lambda x : x.idxmin())
|
|
236
240
|
pd_candles['idmin_long_periods'] = close_long_periods_rolling.apply(lambda x : x.idxmin())
|
|
237
241
|
|
|
242
|
+
pd_candles['max_candle_body_height_percent_long_periods'] = pd_candles['candle_body_height_percent'].rolling(window=sliding_window_how_many_candles).max()
|
|
243
|
+
pd_candles['idmax_candle_body_height_percent_long_periods'] = pd_candles['candle_body_height_percent'].rolling(window=sliding_window_how_many_candles).apply(lambda x : x.idxmax())
|
|
244
|
+
pd_candles['min_candle_body_height_percent_long_periods'] = pd_candles['candle_body_height_percent'].rolling(window=sliding_window_how_many_candles).min()
|
|
245
|
+
pd_candles['idmin_candle_body_height_percent_long_periods'] = pd_candles['candle_body_height_percent'].rolling(window=sliding_window_how_many_candles).apply(lambda x : x.idxmin())
|
|
246
|
+
|
|
238
247
|
pd_candles['price_swing_short_periods'] = np.where(
|
|
239
248
|
pd_candles['idmax_short_periods'] > pd_candles['idmin_short_periods'],
|
|
240
249
|
pd_candles['max_short_periods'] - pd_candles['min_short_periods'], # Up swing
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import random
|
|
2
|
+
from typing import List
|
|
3
|
+
|
|
4
|
+
def generate_rand_nums(
|
|
5
|
+
range_min : float = 0,
|
|
6
|
+
range_max : float = 1,
|
|
7
|
+
size=100, # list size
|
|
8
|
+
percent_in_range : float = 100,
|
|
9
|
+
abs_min : float = 0,
|
|
10
|
+
abs_max : float = 1
|
|
11
|
+
):
|
|
12
|
+
assert(range_min<range_max)
|
|
13
|
+
|
|
14
|
+
if abs_min>range_min:
|
|
15
|
+
abs_min = range_min
|
|
16
|
+
if abs_max<range_max:
|
|
17
|
+
abs_max = range_max
|
|
18
|
+
|
|
19
|
+
result = []
|
|
20
|
+
for _ in range(int(size * percent_in_range/100)):
|
|
21
|
+
result.append(random.uniform(range_min, range_max))
|
|
22
|
+
for _ in range(size - len(result)):
|
|
23
|
+
if random.uniform(0, 1)>0.5:
|
|
24
|
+
result.append(random.uniform(abs_min, range_min))
|
|
25
|
+
else:
|
|
26
|
+
result.append(random.uniform(range_max, abs_max))
|
|
27
|
+
|
|
28
|
+
random.shuffle(result)
|
|
29
|
+
|
|
30
|
+
return result
|
|
@@ -22,18 +22,20 @@ siglab_py/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
22
22
|
siglab_py/tests/integration/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
23
23
|
siglab_py/tests/integration/market_data_util_tests.py,sha256=p-RWIJZLyj0lAdfi4QTIeAttCm_e8mEVWFKh4OWuogU,7189
|
|
24
24
|
siglab_py/tests/unit/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
25
|
-
siglab_py/tests/unit/analytic_util_tests.py,sha256=
|
|
25
|
+
siglab_py/tests/unit/analytic_util_tests.py,sha256=K7jtuKJLynW8EFyNgjOVHA2e2d6Gl2f0ONggFy9tD7g,5780
|
|
26
26
|
siglab_py/tests/unit/market_data_util_tests.py,sha256=A1y83itISmMJdn6wLpfwcr4tGola8wTf1D1xbelMvgw,2026
|
|
27
|
+
siglab_py/tests/unit/simple_math_tests.py,sha256=nM7RZyFGNpMpAXattrO-K5gnlhYXF1trWRbETWRQiqU,3643
|
|
27
28
|
siglab_py/tests/unit/trading_util_tests.py,sha256=9DZmTZlW55lPtNfTCukgDdiyBiMYv9R4mEFWJIJiTNg,3870
|
|
28
29
|
siglab_py/util/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
29
|
-
siglab_py/util/analytic_util.py,sha256=
|
|
30
|
+
siglab_py/util/analytic_util.py,sha256=dlmaf4QZ95JPGNN0LgOG8njpYE9nek4g9QVA51KvM6s,61306
|
|
30
31
|
siglab_py/util/aws_util.py,sha256=KGmjHrr1rpnnxr33nXHNzTul4tvyyxl9p6gpwNv0Ygc,2557
|
|
31
32
|
siglab_py/util/market_data_util.py,sha256=mUXg4uaiX3b6_klgJWIEgnUQU4IUd6CwTOqKLiQWRlU,31307
|
|
32
33
|
siglab_py/util/notification_util.py,sha256=tNZMUkkjz4q1CKqcQq62oEmZgHgNIwz2Iw9J22V22Zw,2668
|
|
33
34
|
siglab_py/util/retry_util.py,sha256=g-UU6pkPouWZZRZEqP99R2Z0lX5xzckYkzjwqqSDpVQ,922
|
|
35
|
+
siglab_py/util/simple_math.py,sha256=LUZVMEl-EA_jMgIYcqOFPgMEDRDJxFU4n_KCN1qznyw,827
|
|
34
36
|
siglab_py/util/slack_notification_util.py,sha256=G27n-adbT3Q6oaHSMvu_Nom794rrda5PprSF-zvmzkM,1912
|
|
35
37
|
siglab_py/util/trading_util.py,sha256=-TGNgJdy4HMDPgq31KQn_lRawFxuXnFU5NnLRb1XM5o,5757
|
|
36
|
-
siglab_py-0.5.
|
|
37
|
-
siglab_py-0.5.
|
|
38
|
-
siglab_py-0.5.
|
|
39
|
-
siglab_py-0.5.
|
|
38
|
+
siglab_py-0.5.48.dist-info/METADATA,sha256=kg-ba09DtS7X-RWGzHjRRhz6xmmjWy-PhS4ZYhdZzoU,829
|
|
39
|
+
siglab_py-0.5.48.dist-info/WHEEL,sha256=lTU6B6eIfYoiQJTZNc-fyaR6BpL6ehTzU3xGYxn2n8k,91
|
|
40
|
+
siglab_py-0.5.48.dist-info/top_level.txt,sha256=AbD4VR9OqmMOGlMJLkAVPGQMtUPIQv0t1BF5xmcLJSk,10
|
|
41
|
+
siglab_py-0.5.48.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|