From 178c2c8375e04b3b5b2b80de4ecbca97dd00394c Mon Sep 17 00:00:00 2001 From: Groni3000 <72792408+Groni3000@users.noreply.github.com> Date: Fri, 3 Nov 2023 20:51:13 +0200 Subject: [PATCH 1/2] speed_up true range --- ta/utils.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ta/utils.py b/ta/utils.py index 9f93bab..cae06ed 100644 --- a/ta/utils.py +++ b/ta/utils.py @@ -39,11 +39,12 @@ def _check_fillna(self, series: pd.Series, value: int = 0) -> pd.Series: def _true_range( high: pd.Series, low: pd.Series, prev_close: pd.Series ) -> pd.Series: - tr1 = high - low - tr2 = (high - prev_close).abs() - tr3 = (low - prev_close).abs() - true_range = pd.DataFrame(data={"tr1": tr1, "tr2": tr2, "tr3": tr3}).max(axis=1) - return true_range + h, l, c = high.values, low.values, prev_close.values + tmp = np.max([h-l, np.abs(h-c), np.abs(l-c)], axis=0) + tmp[0] = h[0] - l[0] # dunno about it. + + return pd.Series(tmp, index=high.index, name='TR') + def dropna(df: pd.DataFrame) -> pd.DataFrame: From 488bfbe11597a26a1a02627c7ff61ac6e8ec13f9 Mon Sep 17 00:00:00 2001 From: Groni3000 <72792408+Groni3000@users.noreply.github.com> Date: Fri, 3 Nov 2023 21:06:35 +0200 Subject: [PATCH 2/2] speed_up --- ta/utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ta/utils.py b/ta/utils.py index cae06ed..ee50dc4 100644 --- a/ta/utils.py +++ b/ta/utils.py @@ -42,7 +42,6 @@ def _true_range( h, l, c = high.values, low.values, prev_close.values tmp = np.max([h-l, np.abs(h-c), np.abs(l-c)], axis=0) tmp[0] = h[0] - l[0] # dunno about it. - return pd.Series(tmp, index=high.index, name='TR')