Skip to content

Commit

Permalink
BUG scalar fix ENH numba inside bar
Browse files Browse the repository at this point in the history
  • Loading branch information
twopirllc committed Sep 11, 2023
1 parent a4094f7 commit aaffdbe
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ $ pip install pandas_ta[full]

Development Version
-------------------
The _development_ version, _0.4.1b_, includes _numerous_ bug fixes, speed improvements and better documentation since release, _0.3.14b_.
The _development_ version, _0.4.2b_, includes _numerous_ bug fixes, speed improvements and better documentation since release, _0.3.14b_.
```sh
$ pip install -U git+https://github.com/twopirllc/pandas-ta.git@development
```
Expand Down
27 changes: 19 additions & 8 deletions pandas_ta/candles/cdl_inside.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
# -*- coding: utf-8 -*-
from numpy import roll, where
from numba import njit
from pandas import Series
from pandas_ta._typing import DictLike, Int, IntFloat
from pandas_ta.utils import candle_color, v_offset, v_scalar, v_series
from pandas_ta._typing import Array, DictLike, Int, IntFloat
from pandas_ta.utils import v_bool, v_offset, v_offset, v_scalar, v_series


@njit(cache=True)
def np_cdl_inside(high: Array, low: Array):
"""Inside Bar"""
hdiff = where(high - roll(high, 1) < 0, 1, 0)
ldiff = where(low - roll(low, 1) > 0, 1, 0)
return hdiff & ldiff


def cdl_inside(
open_: Series, high: Series, low: Series, close: Series,
asbool: bool = False, scalar: IntFloat = None,
asbool: bool = None, scalar: IntFloat = None,
offset: Int = None, **kwargs: DictLike
) -> Series:
"""Candle Type: Inside Bar
Expand Down Expand Up @@ -48,16 +58,17 @@ def cdl_inside(
if open_ is None or high is None or low is None or close is None:
return

offset = v_offset(offset)
asbool = v_bool(asbool, False)
scalar = v_scalar(scalar, 100)
offset = v_offset(offset)

# Calculate
# TODO: Return if high or low has nan
inside = (high.diff() < 0) & (low.diff() > 0)
inside = inside.apply(lambda x: 100 if x else -100)
np_high, np_low = high.values, low.values
np_inside = np_cdl_inside(np_high, np_low)
inside = Series(np_inside, index=close.index, dtype=bool)

if not asbool:
inside = scalar * inside * candle_color(open_, close)
inside = scalar * inside.astype(int)

# Offset
if offset != 0:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"pandas_ta.volatility",
"pandas_ta.volume"
],
version=".".join(("0", "4", "1b")),
version=".".join(("0", "4", "2b")),
description=long_description,
long_description=long_description,
author="Kevin Johnson",
Expand Down

0 comments on commit aaffdbe

Please sign in to comment.