From 1ea0544f34a9a426eeeed52a41483bf07c84d645 Mon Sep 17 00:00:00 2001 From: P S Solanki Date: Sat, 18 Dec 2021 20:10:52 +0530 Subject: [PATCH] custom.py and all candle indicators fully typed --- pandas_ta/candles/cdl_doji.py | 4 +++- pandas_ta/candles/cdl_inside.py | 4 +++- pandas_ta/candles/cdl_pattern.py | 17 +++++++++-------- pandas_ta/candles/cdl_z.py | 5 +++-- pandas_ta/candles/ha.py | 4 ++-- pandas_ta/custom.py | 10 +++++----- 6 files changed, 25 insertions(+), 19 deletions(-) diff --git a/pandas_ta/candles/cdl_doji.py b/pandas_ta/candles/cdl_doji.py index 6d41dee..336df04 100644 --- a/pandas_ta/candles/cdl_doji.py +++ b/pandas_ta/candles/cdl_doji.py @@ -2,9 +2,11 @@ from pandas_ta.overlap import sma from pandas_ta.utils import get_offset, high_low_range, is_percent from pandas_ta.utils import real_body, verify_series +from pandas import Series -def cdl_doji(open_, high, low, close, length=None, factor=None, scalar=None, asint=True, offset=None, **kwargs): +def cdl_doji(open_: Series, high: Series, low: Series, close: Series, length: int = None, factor: float = None, + scalar: float = None, asint: bool = True, offset: int = None, **kwargs) -> Series: """Candle Type: Doji A candle body is Doji, when it's shorter than 10% of the diff --git a/pandas_ta/candles/cdl_inside.py b/pandas_ta/candles/cdl_inside.py index 1ade4c0..5b7c966 100644 --- a/pandas_ta/candles/cdl_inside.py +++ b/pandas_ta/candles/cdl_inside.py @@ -1,9 +1,11 @@ # -*- coding: utf-8 -*- from pandas_ta.utils import candle_color, get_offset from pandas_ta.utils import verify_series +from pandas import Series -def cdl_inside(open_, high, low, close, asbool=False, offset=None, **kwargs): +def cdl_inside(open_: Series, high: Series, low: Series, close: Series, asbool: bool = False, + offset: int = None, **kwargs) -> Series: """Candle Type: Inside Bar An Inside Bar is a bar that is engulfed by the prior highs and lows of it's diff --git a/pandas_ta/candles/cdl_pattern.py b/pandas_ta/candles/cdl_pattern.py index f806c35..b83f750 100644 --- a/pandas_ta/candles/cdl_pattern.py +++ b/pandas_ta/candles/cdl_pattern.py @@ -24,13 +24,13 @@ ALL_PATTERNS = [ def cdl_pattern( - open_, - high, - low, - close, - name: Union[str, Sequence[str]]="all", - scalar=None, - offset=None, + open_: Series, + high: Series, + low: Series, + close: Series, + name: Union[str, Sequence[str]] = "all", + scalar: float = None, + offset: int = None, **kwargs ) -> DataFrame: """TA Lib Candle Patterns @@ -121,4 +121,5 @@ def cdl_pattern( df.category = "candles" return df -cdl = cdl_pattern # Alias \ No newline at end of file + +cdl = cdl_pattern # Alias diff --git a/pandas_ta/candles/cdl_z.py b/pandas_ta/candles/cdl_z.py index b15cc4c..3b227b5 100644 --- a/pandas_ta/candles/cdl_z.py +++ b/pandas_ta/candles/cdl_z.py @@ -1,10 +1,11 @@ # -*- coding: utf-8 -*- -from pandas import DataFrame +from pandas import DataFrame, Series from pandas_ta.statistics import zscore from pandas_ta.utils import get_offset, verify_series -def cdl_z(open_, high, low, close, length=None, full=None, ddof=None, offset=None, **kwargs): +def cdl_z(open_: Series, high: Series, low: Series, close: Series, length: int = None, full: bool = None, + ddof=None, offset: int = None, **kwargs) -> DataFrame: """Candle Type: Z Normalizes OHLC Candles with a rolling Z Score. diff --git a/pandas_ta/candles/ha.py b/pandas_ta/candles/ha.py index 6473a6c..3cf0dc0 100644 --- a/pandas_ta/candles/ha.py +++ b/pandas_ta/candles/ha.py @@ -1,9 +1,9 @@ # -*- coding: utf-8 -*- -from pandas import DataFrame +from pandas import DataFrame, Series from pandas_ta.utils import get_offset, verify_series -def ha(open_, high, low, close, offset=None, **kwargs): +def ha(open_: Series, high: Series, low: Series, close: Series, offset: int = None, **kwargs) -> DataFrame: """Heikin Ashi Candles (HA) The Heikin-Ashi technique averages price data to create a Japanese diff --git a/pandas_ta/custom.py b/pandas_ta/custom.py index 4af5cc5..94aaac2 100644 --- a/pandas_ta/custom.py +++ b/pandas_ta/custom.py @@ -11,7 +11,7 @@ import pandas_ta from pandas_ta import AnalysisIndicators -def bind(function_name, function, method): +def bind(function_name: str, function: types.FunctionType, method: types.MethodType): """ Helper function to bind the function and class method defined in a custom indicator module to the active pandas_ta instance. @@ -25,7 +25,7 @@ def bind(function_name, function, method): setattr(AnalysisIndicators, function_name, method) -def create_dir(path, create_categories=True, verbose=True): +def create_dir(path: str, create_categories: bool = True, verbose: bool = True): """ Helper function to setup a suitable folder structure for working with custom indicators. You only need to call this once whenever you want to @@ -57,7 +57,7 @@ def create_dir(path, create_categories=True, verbose=True): print(f"[i] Created an empty sub-directory '{dirname}'.") -def get_module_functions(module): +def get_module_functions(module: types.ModuleType) -> dict: """ Helper function to get the functions of an imported module as a dictionary. @@ -80,7 +80,7 @@ def get_module_functions(module): return module_functions -def import_dir(path, verbose=True): +def import_dir(path: str, verbose: bool = True): # ensure that the passed directory exists / is readable if not exists(path): print(f"[X] Unable to read the directory '{path}'.") @@ -202,7 +202,7 @@ like all other native indicators in pandas_ta, including help functions. """ -def load_indicator_module(name): +def load_indicator_module(name: str) -> dict: """ Helper function to (re)load an indicator module.