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

numba now is a mandatory requirement #429

Merged
merged 7 commits into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ on:
branches: [ master ]
pull_request:
branches: [ master ]
concurrency:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

Expand All @@ -21,15 +21,15 @@ jobs:
matrix:
# os: [ubuntu-latest, macos-latest, windows-latest]
os: [ubuntu-latest]
include:
include:
- os: ubuntu-latest
path: ~/.cache/pip
#- os: macos-latest
#- os: macos-latest-xlarge
# path: ~/Library/Caches/pip
#- os: windows-latest
# path: ~\AppData\Local\pip\Cache
python-version: [3.8, 3.9, '3.10']
python-version: [3.8, 3.9, '3.10', 3.11]


steps:
- name: Checkout
Expand Down
1 change: 1 addition & 0 deletions jesse/indicators/alma.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from jesse.helpers import get_candle_source, slice_candles


def alma(candles: np.ndarray, period: int = 9, sigma: float = 6.0, distribution_offset: float = 0.85,
source_type: str = "close", sequential: bool = False) -> Union[
float, np.ndarray]:
Expand Down
2 changes: 1 addition & 1 deletion jesse/indicators/apo.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import Union

import numpy as np
from jesse.indicators.ma import ma

from jesse.helpers import get_candle_source, slice_candles
from jesse.indicators.ma import ma


def apo(candles: np.ndarray, fast_period: int = 12, slow_period: int = 26, matype: int = 0, source_type: str = "close",
Expand Down
11 changes: 4 additions & 7 deletions jesse/indicators/bandpass.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
from collections import namedtuple

import numpy as np
try:
from numba import njit
except ImportError:
njit = lambda a : a

from .high_pass import high_pass_fast
from numba import njit

from jesse.helpers import get_candle_source, slice_candles

from .high_pass import high_pass_fast

BandPass = namedtuple('BandPass', ['bp', 'bp_normalized', 'signal', 'trigger'])


Expand Down Expand Up @@ -49,7 +46,7 @@ def bandpass(candles: np.ndarray, period: int = 20, bandwidth: float = 0.3, sou
return BandPass(bp[-1], bp_normalized[-1], signal[-1], trigger[-1])


@njit
@njit(cache=True)
def bp_fast(source, hp, alpha, beta): # Function is compiled to machine code when called the first time

bp = np.copy(hp)
Expand Down
4 changes: 2 additions & 2 deletions jesse/indicators/bollinger_bands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import numpy as np
import talib

from jesse.helpers import get_candle_source, slice_candles
from jesse.indicators.ma import ma
from jesse.indicators.mean_ad import mean_ad
from jesse.indicators.median_ad import median_ad

from jesse.helpers import get_candle_source, slice_candles

BollingerBands = namedtuple('BollingerBands', ['upperband', 'middleband', 'lowerband'])


Expand Down
4 changes: 2 additions & 2 deletions jesse/indicators/bollinger_bands_width.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import numpy as np
import talib

from jesse.helpers import get_candle_source, slice_candles
from jesse.indicators.ma import ma
from jesse.indicators.mean_ad import mean_ad
from jesse.indicators.median_ad import median_ad

from jesse.helpers import get_candle_source, slice_candles


def bollinger_bands_width(candles: np.ndarray, period: int = 20, devup: float = 2, devdn: float = 2, matype: int = 0,
devtype: int = 0,
Expand Down
3 changes: 1 addition & 2 deletions jesse/indicators/cfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import numpy as np
import talib

from jesse.helpers import get_candle_source
from jesse.helpers import slice_candles
from jesse.helpers import get_candle_source, slice_candles


def cfo(candles: np.ndarray, period: int = 14, scalar: float = 100, source_type: str = "close",
Expand Down
7 changes: 2 additions & 5 deletions jesse/indicators/cg.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
from typing import Union

import numpy as np
try:
from numba import njit
except ImportError:
njit = lambda a : a
from numba import njit

from jesse.helpers import get_candle_source, same_length, slice_candles

Expand All @@ -29,7 +26,7 @@ def cg(candles: np.ndarray, period: int = 10, source_type: str = "close", sequen
return same_length(candles, res) if sequential else res[-1]


@njit
@njit(cache=True)
def go_fast(source, period): # Function is compiled to machine code when called the first time
res = np.full_like(source, fill_value=np.nan)
for i in range(source.size):
Expand Down
1 change: 0 additions & 1 deletion jesse/indicators/cksp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from jesse.helpers import slice_candles


CKSP = namedtuple('CKSP', ['long', 'short'])

def cksp(candles: np.ndarray, p: int = 10, x: float = 1.0, q: int = 9, sequential: bool = False) -> CKSP:
Expand Down
3 changes: 1 addition & 2 deletions jesse/indicators/cmo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import numpy as np
import talib

from jesse.helpers import get_candle_source
from jesse.helpers import slice_candles
from jesse.helpers import get_candle_source, slice_candles


def cmo(candles: np.ndarray, period: int = 14, source_type: str = "close", sequential: bool = False) -> Union[
Expand Down
7 changes: 2 additions & 5 deletions jesse/indicators/correlation_cycle.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
from collections import namedtuple

import numpy as np
try:
from numba import njit
except ImportError:
njit = lambda a : a
from numba import njit

from jesse.helpers import get_candle_source, np_shift, slice_candles

Expand Down Expand Up @@ -42,7 +39,7 @@ def correlation_cycle(candles: np.ndarray, period: int = 20, threshold: int = 9,
return CC(realPart[-1], imagPart[-1], angle[-1], state[-1])


@njit
@njit(cache=True)
def go_fast(source, period): # Function is compiled to machine code when called the first time
# Correlation Cycle Function
PIx2 = 4.0 * np.arcsin(1.0)
Expand Down
2 changes: 1 addition & 1 deletion jesse/indicators/cvi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
import tulipy as ti

from jesse.helpers import slice_candles, same_length
from jesse.helpers import same_length, slice_candles


def cvi(candles: np.ndarray, period: int = 5, sequential: bool = False) -> Union[float, np.ndarray]:
Expand Down
10 changes: 3 additions & 7 deletions jesse/indicators/cwma.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
from typing import Union
import numpy as np


try:
from numba import njit
except ImportError:
njit = lambda a : a
import numpy as np
from numba import njit

from jesse.helpers import get_candle_source, slice_candles

Expand Down Expand Up @@ -35,7 +31,7 @@ def cwma(candles: np.ndarray, period: int = 14, source_type: str = "close", sequ
return res if sequential else res[-1]


@njit
@njit(cache=True)
def vpwma_fast(source, period):
newseries = np.copy(source)
for j in range(period + 1, source.shape[0]):
Expand Down
10 changes: 3 additions & 7 deletions jesse/indicators/damiani_volatmeter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@

import numpy as np
import talib
try:
from numba import njit
except ImportError:
njit = lambda a : a
from numba import njit

from jesse.helpers import get_candle_source
from jesse.helpers import slice_candles
from jesse.helpers import get_candle_source, slice_candles

DamianiVolatmeter = namedtuple('DamianiVolatmeter', ['vol', 'anti'])

Expand Down Expand Up @@ -46,7 +42,7 @@ def damiani_volatmeter(candles: np.ndarray, vis_atr: int = 13, vis_std: int = 20
return DamianiVolatmeter(vol[-1], t[-1])


@njit
@njit(cache=True)
def damiani_volatmeter_fast(source, sed_std, atrvis, atrsed, vis_std,
threshold): # Function is compiled to machine code when called the first time
lag_s = 0.5
Expand Down
1 change: 1 addition & 0 deletions jesse/indicators/dec_osc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import numpy as np

from jesse.helpers import get_candle_source, slice_candles

from .high_pass_2_pole import high_pass_2_pole_fast


Expand Down
1 change: 1 addition & 0 deletions jesse/indicators/decycler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import numpy as np

from jesse.helpers import get_candle_source, slice_candles

from .high_pass_2_pole import high_pass_2_pole_fast


Expand Down
4 changes: 2 additions & 2 deletions jesse/indicators/devstop.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import numpy as np
import talib
from jesse.indicators.mean_ad import mean_ad
from jesse.indicators.median_ad import median_ad

from jesse.helpers import slice_candles
from jesse.indicators.mean_ad import mean_ad
from jesse.indicators.median_ad import median_ad


def devstop(candles: np.ndarray, period: int = 20, mult: float = 0, devtype: int = 0, direction: str = "long",
Expand Down
8 changes: 2 additions & 6 deletions jesse/indicators/edcf.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
from typing import Union

import numpy as np

try:
from numba import njit
except ImportError:
njit = lambda a: a
from numba import njit

from jesse.helpers import get_candle_source, slice_candles

Expand Down Expand Up @@ -35,7 +31,7 @@ def edcf(candles: np.ndarray, period: int = 15, source_type: str = "hl2", sequen
return res if sequential else res[-1]


@njit
@njit(cache=True)
def edcf_fast(source, period):
newseries = np.full_like(source, np.nan)

Expand Down
7 changes: 2 additions & 5 deletions jesse/indicators/efi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import numpy as np
import talib
try:
from numba import njit
except ImportError:
njit = lambda a : a
from numba import njit

from jesse.helpers import get_candle_source, same_length, slice_candles

Expand Down Expand Up @@ -34,7 +31,7 @@ def efi(candles: np.ndarray, period: int = 13, source_type: str = "close", seque
return res_with_nan if sequential else res_with_nan[-1]


@njit
@njit(cache=True)
def efi_fast(source, volume):
dif = np.zeros(source.size - 1)
for i in range(1, source.size):
Expand Down
9 changes: 3 additions & 6 deletions jesse/indicators/emd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import numpy as np
import talib
try:
from numba import njit
except ImportError:
njit = lambda a : a
from numba import njit

from jesse.helpers import slice_candles

Expand Down Expand Up @@ -42,7 +39,7 @@ def emd(candles: np.ndarray, period: int = 20, delta=0.5, fraction=0.1, sequenti
return EMD(avg_peak[-1], mean[-1], avg_valley[-1])


@njit
@njit(cache=True)
def bp_fast(price, period, delta):
# bandpass filter
beta = np.cos(2 * np.pi / period)
Expand All @@ -58,7 +55,7 @@ def bp_fast(price, period, delta):
return bp


@njit
@njit(cache=True)
def peak_valley_fast(bp, price):
peak = np.copy(bp)
valley = np.copy(bp)
Expand Down
2 changes: 1 addition & 1 deletion jesse/indicators/emv.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
import tulipy as ti

from jesse.helpers import slice_candles, same_length
from jesse.helpers import same_length, slice_candles


def emv(candles: np.ndarray, sequential: bool = False) -> Union[float, np.ndarray]:
Expand Down
10 changes: 3 additions & 7 deletions jesse/indicators/epma.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
from typing import Union
import numpy as np


try:
from numba import njit
except ImportError:
njit = lambda a : a
import numpy as np
from numba import njit

from jesse.helpers import get_candle_source, slice_candles

Expand Down Expand Up @@ -36,7 +32,7 @@ def epma(candles: np.ndarray, period: int = 11, offset: int = 4, source_type: st
return res if sequential else res[-1]


@njit
@njit(cache=True)
def epma_fast(source, period, offset):
newseries = np.copy(source)
for j in range(period + offset + 1 , source.shape[0]):
Expand Down
2 changes: 1 addition & 1 deletion jesse/indicators/er.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
from numpy.lib.stride_tricks import sliding_window_view

from jesse.helpers import get_candle_source, slice_candles, same_length
from jesse.helpers import get_candle_source, same_length, slice_candles


def er(candles: np.ndarray, period: int = 5, source_type: str = "close", sequential: bool = False) -> Union[
Expand Down
2 changes: 1 addition & 1 deletion jesse/indicators/eri.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from collections import namedtuple

import numpy as np
from jesse.indicators.ma import ma

from jesse.helpers import get_candle_source, slice_candles
from jesse.indicators.ma import ma

ERI = namedtuple('ERI', ['bull', 'bear'])

Expand Down
2 changes: 1 addition & 1 deletion jesse/indicators/fisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
import tulipy as ti

from jesse.helpers import slice_candles, same_length
from jesse.helpers import same_length, slice_candles

FisherTransform = namedtuple('FisherTransform', ['fisher', 'signal'])

Expand Down
Loading
Loading