Skip to content

Commit

Permalink
Merge pull request #156 from bukosabino/develop
Browse files Browse the repository at this point in the history
adding Tenkan-sen and Kijun-sen methods for IchimokuIndicator
  • Loading branch information
bukosabino authored May 11, 2020
2 parents a62ea5b + 6a724e0 commit 7b3857f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
1 change: 1 addition & 0 deletions release.md
Original file line number Diff line number Diff line change
@@ -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 |
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)',
Expand All @@ -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=[
Expand Down
31 changes: 26 additions & 5 deletions ta/trend.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,18 +285,39 @@ 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)
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}')
Expand Down
2 changes: 2 additions & 0 deletions ta/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7b3857f

Please sign in to comment.