Skip to content

Commit

Permalink
Merge pull request #434 from kakulukia/fixed-beta-indicator
Browse files Browse the repository at this point in the history
Fixed beta indicator
  • Loading branch information
saleh-mir authored Apr 13, 2024
2 parents 200085e + bed8465 commit 666a8bc
Show file tree
Hide file tree
Showing 5 changed files with 2,663 additions and 2,055 deletions.
1 change: 0 additions & 1 deletion jesse/indicators/bandpass.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def bandpass(candles: np.ndarray, period: int = 20, bandwidth: float = 0.3, sou

source = get_candle_source(candles, source_type=source_type)


hp = high_pass_fast(source, 4 * period / bandwidth)

beta = np.cos(2 * np.pi / period)
Expand Down
8 changes: 5 additions & 3 deletions jesse/indicators/beta.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@
from jesse.helpers import slice_candles


def beta(candles: np.ndarray, period: int = 5, sequential: bool = False) -> Union[float, np.ndarray]:
def beta(candles: np.ndarray, benchmark_candles: np.ndarray, period: int = 5, sequential: bool = False) -> Union[float, np.ndarray]:
"""
BETA - Beta
BETA - compares the given candles close price to its benchmark (should be in the same time frame)
:param candles: np.ndarray
:param benchmark_candles: np.ndarray
:param period: int - default: 5
:param sequential: bool - default: False
:return: float | np.ndarray
"""
candles = slice_candles(candles, sequential)
benchmark_candles = slice_candles(benchmark_candles, sequential)

res = talib.BETA(candles[:, 3], candles[:, 4], timeperiod=period)
res = talib.BETA(candles[:, 2], benchmark_candles[:, 2], timeperiod=period)

return res if sequential else res[-1]
4 changes: 2 additions & 2 deletions jesse/indicators/ttm_trend.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


def ttm_trend(candles: np.ndarray, period: int = 5, source_type: str = "hl2", sequential: bool = False) -> Union[
float, np.ndarray]:
bool, np.ndarray]:
"""
TTM Trend
Expand All @@ -23,6 +23,6 @@ def ttm_trend(candles: np.ndarray, period: int = 5, source_type: str = "hl2", se
source = get_candle_source(candles, source_type=source_type)
swv = sliding_window_view(source, window_shape=period)
trend_avg = np.mean(swv, axis=-1)
res = np.greater(candles[:, 2], same_length(source,trend_avg))
res = np.greater(candles[:, 2], same_length(source, trend_avg))

return res if sequential else res[-1]
Loading

0 comments on commit 666a8bc

Please sign in to comment.