Skip to content

Commit

Permalink
Merge pull request bukosabino#94 from bukosabino/feature/doc5
Browse files Browse the repository at this point in the history
Feature/doc5
  • Loading branch information
bukosabino authored Nov 14, 2019
2 parents 2c5fd56 + fbd9f47 commit 6886f3c
Show file tree
Hide file tree
Showing 5 changed files with 295 additions and 9 deletions.
50 changes: 50 additions & 0 deletions ta/momentum.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ def _run(self):
self._rsi = 100 * emaup / (emaup + emadn)

def rsi(self) -> pd.Series:
"""Relative Strength Index (RSI)
Returns:
pandas.Series: New feature generated.
"""
rsi = self.check_fillna(self._rsi, value=50)
return pd.Series(rsi, name='rsi')

Expand Down Expand Up @@ -102,6 +107,11 @@ def _run(self):
self._mr = (100 - (100 / (1 + mr)))

def money_flow_index(self) -> pd.Series:
"""Money Flow Index (MFI)
Returns:
pandas.Series: New feature generated.
"""
mr = self.check_fillna(self._mr, value=50)
return pd.Series(mr, name=f'mfi_{self._n}')

Expand Down Expand Up @@ -135,6 +145,11 @@ def _run(self):
self._tsi *= 100

def tsi(self) -> pd.Series:
"""True strength index (TSI)
Returns:
pandas.Series: New feature generated.
"""
tsi = self.check_fillna(self._tsi, value=0)
return pd.Series(tsi, name='tsi')

Expand Down Expand Up @@ -203,6 +218,11 @@ def _run(self):
/ (self._ws + self._wm + self._wl))

def uo(self) -> pd.Series:
"""Ultimate Oscillator
Returns:
pandas.Series: New feature generated.
"""
uo = self.check_fillna(self._uo, value=50)
return pd.Series(uo, name='uo')

Expand Down Expand Up @@ -247,10 +267,20 @@ def _run(self):
self._stoch_k = 100 * (self._close - smin) / (smax - smin)

def stoch(self) -> pd.Series:
"""Stochastic Oscillator
Returns:
pandas.Series: New feature generated.
"""
stoch_k = self.check_fillna(self._stoch_k, value=50)
return pd.Series(stoch_k, name='stoch_k')

def stoch_signal(self) -> pd.Series:
"""Signal Stochastic Oscillator
Returns:
pandas.Series: New feature generated.
"""
stoch_d = self._stoch_k.rolling(self._d_n, min_periods=0).mean()
stoch_d = self.check_fillna(stoch_d, value=50)
return pd.Series(stoch_d, name='stoch_k_signal')
Expand Down Expand Up @@ -309,6 +339,11 @@ def _run(self):
self._kama[i] = self._kama[i-1] + sc[i] * (close_values[i] - self._kama[i-1])

def kama(self) -> pd.Series:
"""Kaufman's Adaptive Moving Average (KAMA)
Returns:
pandas.Series: New feature generated.
"""
kama = pd.Series(self._kama, index=self._close.index)
kama = self.check_fillna(kama, value=self._close)
return pd.Series(kama, name='kama')
Expand Down Expand Up @@ -348,6 +383,11 @@ def _run(self):
self._roc = ((self._close - self._close.shift(self._n)) / self._close.shift(self._n)) * 100

def roc(self) -> pd.Series:
"""Rate of Change (ROC)
Returns:
pandas.Series: New feature generated.
"""
roc = self.check_fillna(self._roc)
return pd.Series(roc, name='roc')

Expand Down Expand Up @@ -399,6 +439,11 @@ def _run(self):
self._ao = mp.rolling(self._s, min_periods=0).mean() - mp.rolling(self._len, min_periods=0).mean()

def ao(self) -> pd.Series:
"""Awesome Oscillator
Returns:
pandas.Series: New feature generated.
"""
ao = self.check_fillna(self._ao, value=0)
return pd.Series(ao, name='ao')

Expand Down Expand Up @@ -454,6 +499,11 @@ def _run(self):
self._wr = -100 * (hh - self._close) / (hh - ll)

def wr(self) -> pd.Series:
"""Williams %R
Returns:
pandas.Series: New feature generated.
"""
wr = self.check_fillna(self._wr, value=-50)
return pd.Series(wr, name='wr')

Expand Down
15 changes: 15 additions & 0 deletions ta/others.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ def _run(self):
self._dr *= 100

def daily_return(self) -> pd.Series:
"""Daily Return (DR)
Returns:
pandas.Series: New feature generated.
"""
dr = self.check_fillna(self._dr, value=0)
return pd.Series(dr, name='d_ret')

Expand All @@ -53,6 +58,11 @@ def _run(self):
self._dr *= 100

def daily_log_return(self) -> pd.Series:
"""Daily Log Return (DLR)
Returns:
pandas.Series: New feature generated.
"""
dr = self.check_fillna(self._dr, value=0)
return pd.Series(dr, name='d_logret')

Expand All @@ -75,6 +85,11 @@ def _run(self):
self._cr *= 100

def cumulative_return(self) -> pd.Series:
"""Cumulative Return (CR)
Returns:
pandas.Series: New feature generated.
"""
cr = self.check_fillna(self._cr, method='backfill')
return pd.Series(cr, name='cum_ret')

Expand Down
Loading

0 comments on commit 6886f3c

Please sign in to comment.