diff --git a/src/naiback/indicators/__init__.py b/src/naiback/indicators/__init__.py index dce2a17..42d5bec 100644 --- a/src/naiback/indicators/__init__.py +++ b/src/naiback/indicators/__init__.py @@ -2,3 +2,5 @@ from .ema import EMA from .rsi import RSI from .intradaybarnumber import IntradayBarNumber +from .highest import Highest,HighestValue +from .lowest import Lowest,LowestValue diff --git a/src/naiback/indicators/highest.py b/src/naiback/indicators/highest.py new file mode 100644 index 0000000..4ae3ae1 --- /dev/null +++ b/src/naiback/indicators/highest.py @@ -0,0 +1,19 @@ + +import numpy as np + +def Highest(data, period): + result = np.zeros(len(data)) + if len(result) == 0: + return result + result[0] = data[0] + for i in range(1, len(data)): + result[i] = max(data[max(0, i - period):(i+1)]) + + return result + +def HighestValue(data, index, period): + if len(data) == 0 or index >= len(data): + return None + if index == 0: + return data[0] + return max(data[max(0, index - period):(index+1)]) diff --git a/src/naiback/indicators/lowest.py b/src/naiback/indicators/lowest.py new file mode 100644 index 0000000..f387a1c --- /dev/null +++ b/src/naiback/indicators/lowest.py @@ -0,0 +1,19 @@ + +import numpy as np + +def Lowest(data, period): + result = np.zeros(len(data)) + if len(result) == 0: + return result + result[0] = data[0] + for i in range(1, len(data)): + result[i] = min(data[max(0, i - period):(i+1)]) + + return result + +def LowestValue(data, index, period): + if len(data) == 0 or index >= len(data): + return None + if index == 0: + return data[0] + return min(data[max(0, index - period):(index+1)])