Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dtype causing future warning to pop up #293

Merged
merged 1 commit into from Apr 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
61 changes: 39 additions & 22 deletions ta/trend.py
Expand Up @@ -36,7 +36,8 @@ def __init__(self, close: pd.Series, window: int = 25, fillna: bool = False):

def _run(self):
min_periods = 0 if self._fillna else self._window
rolling_close = self._close.rolling(self._window, min_periods=min_periods)
rolling_close = self._close.rolling(
self._window, min_periods=min_periods)
self._aroon_up = rolling_close.apply(
lambda x: float(np.argmax(x) + 1) / self._window * 100, raw=True
)
Expand Down Expand Up @@ -315,7 +316,8 @@ def _run(self):
ema1 = _ema(amplitude, self._window_fast, self._fillna)
ema2 = _ema(ema1, self._window_fast, self._fillna)
mass = ema1 / ema2
self._mass = mass.rolling(self._window_slow, min_periods=min_periods).sum()
self._mass = mass.rolling(
self._window_slow, min_periods=min_periods).sum()

def mass_index(self) -> pd.Series:
"""Mass Index (MI)
Expand Down Expand Up @@ -368,11 +370,13 @@ def _run(self):
min_periods_n2 = 0 if self._fillna else self._window2
self._conv = 0.5 * (
self._high.rolling(self._window1, min_periods=min_periods_n1).max()
+ self._low.rolling(self._window1, min_periods=min_periods_n1).min()
+ self._low.rolling(self._window1,
min_periods=min_periods_n1).min()
)
self._base = 0.5 * (
self._high.rolling(self._window2, min_periods=min_periods_n2).max()
+ self._low.rolling(self._window2, min_periods=min_periods_n2).min()
+ self._low.rolling(self._window2,
min_periods=min_periods_n2).min()
)

def ichimoku_conversion_line(self) -> pd.Series:
Expand Down Expand Up @@ -489,7 +493,8 @@ def _run(self):
(
(
self._close
- self._close.shift(self._r1, fill_value=self._close.mean())
- self._close.shift(self._r1,
fill_value=self._close.mean())
)
/ self._close.shift(self._r1, fill_value=self._close.mean())
)
Expand All @@ -500,7 +505,8 @@ def _run(self):
(
(
self._close
- self._close.shift(self._r2, fill_value=self._close.mean())
- self._close.shift(self._r2,
fill_value=self._close.mean())
)
/ self._close.shift(self._r2, fill_value=self._close.mean())
)
Expand All @@ -511,7 +517,8 @@ def _run(self):
(
(
self._close
- self._close.shift(self._r3, fill_value=self._close.mean())
- self._close.shift(self._r3,
fill_value=self._close.mean())
)
/ self._close.shift(self._r3, fill_value=self._close.mean())
)
Expand All @@ -522,7 +529,8 @@ def _run(self):
(
(
self._close
- self._close.shift(self._r4, fill_value=self._close.mean())
- self._close.shift(self._r4,
fill_value=self._close.mean())
)
/ self._close.shift(self._r4, fill_value=self._close.mean())
)
Expand Down Expand Up @@ -649,7 +657,8 @@ def _mad(x):
typical_price = (self._high + self._low + self._close) / 3.0
self._cci = (
typical_price
- typical_price.rolling(self._window, min_periods=min_periods).mean()
- typical_price.rolling(self._window,
min_periods=min_periods).mean()
) / (
self._constant
* typical_price.rolling(self._window, min_periods=min_periods).apply(
Expand Down Expand Up @@ -718,8 +727,10 @@ def _run(self):

self._trs_initial = np.zeros(self._window - 1)
self._trs = np.zeros(len(self._close) - (self._window - 1))
self._trs[0] = diff_directional_movement.dropna()[0 : self._window].sum()
diff_directional_movement = diff_directional_movement.reset_index(drop=True)
self._trs[0] = diff_directional_movement.dropna()[
0: self._window].sum()
diff_directional_movement = diff_directional_movement.reset_index(
drop=True)

for i in range(1, len(self._trs) - 1):
self._trs[i] = (
Expand All @@ -734,7 +745,7 @@ def _run(self):
neg = abs(((diff_down > diff_up) & (diff_down > 0)) * diff_down)

self._dip = np.zeros(len(self._close) - (self._window - 1))
self._dip[0] = pos.dropna()[0 : self._window].sum()
self._dip[0] = pos.dropna()[0: self._window].sum()

pos = pos.reset_index(drop=True)

Expand All @@ -746,7 +757,7 @@ def _run(self):
)

self._din = np.zeros(len(self._close) - (self._window - 1))
self._din[0] = neg.dropna()[0 : self._window].sum()
self._din[0] = neg.dropna()[0: self._window].sum()

neg = neg.reset_index(drop=True)

Expand Down Expand Up @@ -776,11 +787,12 @@ def adx(self) -> pd.Series:
directional_index = 100 * np.abs((dip - din) / (dip + din))

adx_series = np.zeros(len(self._trs))
adx_series[self._window] = directional_index[0 : self._window].mean()
adx_series[self._window] = directional_index[0: self._window].mean()

for i in range(self._window + 1, len(adx_series)):
adx_series[i] = (
(adx_series[i - 1] * (self._window - 1)) + directional_index[i - 1]
(adx_series[i - 1] * (self._window - 1)) +
directional_index[i - 1]
) / float(self._window)

adx_series = np.concatenate((self._trs_initial, adx_series), axis=0)
Expand Down Expand Up @@ -859,8 +871,10 @@ def _run(self):
trn = true_range.rolling(self._window, min_periods=min_periods).sum()
vmp = np.abs(self._high - self._low.shift(1))
vmm = np.abs(self._low - self._high.shift(1))
self._vip = vmp.rolling(self._window, min_periods=min_periods).sum() / trn
self._vin = vmm.rolling(self._window, min_periods=min_periods).sum() / trn
self._vip = vmp.rolling(
self._window, min_periods=min_periods).sum() / trn
self._vin = vmm.rolling(
self._window, min_periods=min_periods).sum() / trn

def vortex_indicator_pos(self):
"""+VI
Expand Down Expand Up @@ -935,8 +949,8 @@ def _run(self): # noqa
down_trend_low = self._low.iloc[0]

self._psar = self._close.copy()
self._psar_up = pd.Series(index=self._psar.index)
self._psar_down = pd.Series(index=self._psar.index)
self._psar_up = pd.Series(index=self._psar.index, dtype="float64")
self._psar_down = pd.Series(index=self._psar.index, dtype="float64")

for i in range(2, len(self._close)):
reversal = False
Expand All @@ -946,7 +960,8 @@ def _run(self): # noqa

if up_trend:
self._psar.iloc[i] = self._psar.iloc[i - 1] + (
acceleration_factor * (up_trend_high - self._psar.iloc[i - 1])
acceleration_factor *
(up_trend_high - self._psar.iloc[i - 1])
)

if min_low < self._psar.iloc[i]:
Expand All @@ -969,7 +984,8 @@ def _run(self): # noqa
self._psar.iloc[i] = low1
else:
self._psar.iloc[i] = self._psar.iloc[i - 1] - (
acceleration_factor * (self._psar.iloc[i - 1] - down_trend_low)
acceleration_factor *
(self._psar.iloc[i - 1] - down_trend_low)
)

if max_high > self._psar.iloc[i]:
Expand Down Expand Up @@ -1104,7 +1120,8 @@ def _run(self):

_stoch_d_min = _stoch_d.rolling(window=self._cycle).min()
_stoch_d_max = _stoch_d.rolling(window=self._cycle).max()
_stoch_kd = 100 * (_stoch_d - _stoch_d_min) / (_stoch_d_max - _stoch_d_min)
_stoch_kd = 100 * (_stoch_d - _stoch_d_min) / \
(_stoch_d_max - _stoch_d_min)
self._stc = _ema(_stoch_kd, self._smooth2, self._fillna)

def stc(self):
Expand Down