diff --git a/release.md b/release.md index 9453f118..31b0616a 100644 --- a/release.md +++ b/release.md @@ -1,5 +1,6 @@ | Date | Version | Comment | | ------------- | ------------- | ------------- | +| 2020/05/11 | 0.5.24 | Adding extra methods for IchimokuIndicator https://github.com/bukosabino/ta/pull/155 | | 2020/05/10 | 0.5.23 | Fixing bug when dataset with timestamp as index https://github.com/bukosabino/ta/pull/154 | | 2020/05/04 | 0.5.22 | 1. Keltner Channel: adding tests; adding n atr input parametr; fixing some minor bug; adding unittests for adx https://github.com/bukosabino/ta/pull/148 | | | | 2. Refactor tests code and speed up the tests https://github.com/bukosabino/ta/pull/149 | diff --git a/setup.py b/setup.py index f5dfb3cd..2e38e4fd 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ setup( name='ta', packages=['ta'], - version='0.5.23', + version='0.5.24', description='Technical Analysis Library in Python', long_description='It is a Technical Analysis library to financial time series datasets. You can use to do feature engineering. It is builded on Python Pandas library.', author='Dario Lopez Padial (Bukosabino)', @@ -16,7 +16,7 @@ 'numpy', 'pandas', ], - download_url='https://github.com/bukosabino/ta/tarball/0.5.23', + download_url='https://github.com/bukosabino/ta/tarball/0.5.24', keywords=['technical analysis', 'python3', 'pandas'], license='The MIT License (MIT)', classifiers=[ diff --git a/ta/trend.py b/ta/trend.py index b7d4f1e5..313fb1c4 100644 --- a/ta/trend.py +++ b/ta/trend.py @@ -285,6 +285,31 @@ def __init__(self, high: pd.Series, low: pd.Series, n1: int = 9, n2: int = 26, n self._n3 = n3 self._visual = visual self._fillna = fillna + self._run() + + def _run(self): + self._conv = 0.5 * ( + self._high.rolling(self._n1, min_periods=0).max() + self._low.rolling(self._n1, min_periods=0).min()) + self._base = 0.5 * ( + self._high.rolling(self._n2, min_periods=0).max() + self._low.rolling(self._n2, min_periods=0).min()) + + def ichimoku_conversion_line(self) -> pd.Series: + """Tenkan-sen (Conversion Line) + + Returns: + pandas.Series: New feature generated. + """ + conversion = self._check_fillna(self._conv, value=-1) + return pd.Series(conversion, name=f'ichimoku_conv_{self._n1}_{self._n2}') + + def ichimoku_base_line(self) -> pd.Series: + """Kijun-sen (Base Line) + + Returns: + pandas.Series: New feature generated. + """ + base = self._check_fillna(self._base, value=-1) + return pd.Series(base, name=f'ichimoku_base_{self._n1}_{self._n2}') def ichimoku_a(self) -> pd.Series: """Senkou Span A (Leading Span A) @@ -292,11 +317,7 @@ def ichimoku_a(self) -> pd.Series: Returns: pandas.Series: New feature generated. """ - conv = 0.5 * (self._high.rolling(self._n1, min_periods=0).max() - + self._low.rolling(self._n1, min_periods=0).min()) - base = 0.5 * (self._high.rolling(self._n2, min_periods=0).max() - + self._low.rolling(self._n2, min_periods=0).min()) - spana = 0.5 * (conv + base) + spana = 0.5 * (self._conv + self._base) spana = spana.shift(self._n2, fill_value=spana.mean()) if self._visual else spana spana = self._check_fillna(spana, value=-1) return pd.Series(spana, name=f'ichimoku_a_{self._n1}_{self._n2}') diff --git a/ta/wrapper.py b/ta/wrapper.py index 8ac5e4aa..d7fae070 100644 --- a/ta/wrapper.py +++ b/ta/wrapper.py @@ -207,6 +207,8 @@ def add_trend_ta(df: pd.DataFrame, high: str, low: str, close: str, fillna: bool # Ichimoku Indicator indicator = IchimokuIndicator(high=df[high], low=df[low], n1=9, n2=26, n3=52, visual=False, fillna=fillna) + df[f'{colprefix}trend_ichimoku_conv'] = indicator.ichimoku_conversion_line() + df[f'{colprefix}trend_ichimoku_base'] = indicator.ichimoku_base_line() df[f'{colprefix}trend_ichimoku_a'] = indicator.ichimoku_a() df[f'{colprefix}trend_ichimoku_b'] = indicator.ichimoku_b() indicator = IchimokuIndicator(high=df[high], low=df[low], n1=9, n2=26, n3=52, visual=True, fillna=fillna)