custom.py and all candle indicators fully typed

This commit is contained in:
P S Solanki
2021-12-18 20:10:52 +05:30
parent 61c7971d41
commit 1ea0544f34
6 changed files with 25 additions and 19 deletions
+3 -1
View File
@@ -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
+3 -1
View File
@@ -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
+9 -8
View File
@@ -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
cdl = cdl_pattern # Alias
+3 -2
View File
@@ -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.
+2 -2
View File
@@ -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
+5 -5
View File
@@ -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.