Skip to content

Commit

Permalink
Merge pull request #3 from krypt0ra/develop
Browse files Browse the repository at this point in the history
Merging dev into master
  • Loading branch information
alkhachatryan authored Feb 14, 2024
2 parents bc54039 + 58eaf46 commit 7802789
Show file tree
Hide file tree
Showing 30 changed files with 236 additions and 190 deletions.
25 changes: 0 additions & 25 deletions .github/workflows/pylint.yml

This file was deleted.

21 changes: 15 additions & 6 deletions app/analyzers/crossover.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,24 @@ def analyze(self, key_indicator, key_signal, key_indicator_index,
new_key_indicator = key_indicator.copy(deep=True)
for column in new_key_indicator:
column_indexed_name = '{}_{}'.format(column, key_indicator_index)
new_key_indicator.rename(columns={column: column_indexed_name}, inplace=True)
new_key_indicator.rename(
columns={
column: column_indexed_name},
inplace=True)

crossed_indicator_name = '{}_{}'.format(crossed_signal, crossed_indicator_index)
crossed_indicator_name = '{}_{}'.format(
crossed_signal, crossed_indicator_index)
new_crossed_indicator = crossed_indicator.copy(deep=True)
for column in new_crossed_indicator:
column_indexed_name = '{}_{}'.format(column, crossed_indicator_index)
new_crossed_indicator.rename(columns={column: column_indexed_name}, inplace=True)

combined_data = pandas.concat([new_key_indicator, new_crossed_indicator], axis=1)
column_indexed_name = '{}_{}'.format(
column, crossed_indicator_index)
new_crossed_indicator.rename(
columns={
column: column_indexed_name},
inplace=True)

combined_data = pandas.concat(
[new_key_indicator, new_crossed_indicator], axis=1)
combined_data.dropna(how='any', inplace=True)

combined_data['is_hot'] = combined_data[key_indicator_name] > combined_data[crossed_indicator_name]
Expand Down
23 changes: 12 additions & 11 deletions app/analyzers/indicators/adx.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@


class Adx(IndicatorUtils):
def analyze(self, historical_data, signal=["adx"], period_count=14, hot_thresh=None, cold_thresh=None):
def analyze(self, historical_data, signal=[
"adx"], period_count=14, hot_thresh=None, cold_thresh=None):
"""
strength of a trend
ADX > 25 = strength
Expand Down Expand Up @@ -114,8 +115,8 @@ def DM(self, high, low, pdm, ndm):
"""

for index in range(1, high.shape[0]):
up_move = high[index] - high[index-1]
down_move = low[index-1] - low[index]
up_move = high[index] - high[index - 1]
down_move = low[index - 1] - low[index]

if up_move > down_move and up_move > 0:
pdm[index] = up_move
Expand All @@ -139,13 +140,13 @@ def DMsmooth(self, pdm, ndm, pdm_smooth, ndm_smooth, period_count):
:return: pdm_smooth, ndm_smooth
"""

pdm_smooth[period_count-1] = pdm[0:period_count].sum() / period_count
pdm_smooth[period_count - 1] = pdm[0:period_count].sum() / period_count
ndm_smooth[period_count - 1] = ndm[0:period_count].sum() / period_count
for index in range(period_count, pdm.shape[0]):
pdm_smooth[index] = (
pdm[index-1] - (pdm_smooth[index-1]/period_count)) + pdm_smooth[index-1]
pdm[index - 1] - (pdm_smooth[index - 1] / period_count)) + pdm_smooth[index - 1]
ndm_smooth[index] = (
ndm[index - 1] - (ndm_smooth[index-1] / period_count)) + ndm_smooth[index-1]
ndm[index - 1] - (ndm_smooth[index - 1] / period_count)) + ndm_smooth[index - 1]

return pdm_smooth, ndm_smooth

Expand Down Expand Up @@ -178,9 +179,9 @@ def ATR(self, tr, atr, period_count):
:return: atr
"""

atr[period_count-1] = tr[0:period_count].sum() / period_count
atr[period_count - 1] = tr[0:period_count].sum() / period_count
for index in range(period_count, tr.shape[0]):
atr[index] = ((atr[index-1] * (period_count - 1)) +
atr[index] = ((atr[index - 1] * (period_count - 1)) +
tr[index]) / period_count

return atr
Expand All @@ -200,11 +201,11 @@ def ADX(self, pdi, ndi, dx, adx, period_count):
dx[index] = ((abs(pdi[index] - ndi[index])) /
(abs(pdi[index] + ndi[index]))) * 100

period_count2 = period_count*2
adx[period_count2-1] = dx[period_count:period_count2].sum() / \
period_count2 = period_count * 2
adx[period_count2 - 1] = dx[period_count:period_count2].sum() / \
period_count
for index in range(period_count2, dx.shape[0]):
adx[index] = ((adx[index-1] * (period_count - 1)) +
adx[index] = ((adx[index - 1] * (period_count - 1)) +
dx[index]) / period_count

return dx, adx
11 changes: 6 additions & 5 deletions app/analyzers/indicators/aroon_oscillator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@


class Aroon_oscillator(IndicatorUtils):
def analyze(self, historical_data, sma_vol_period, period_count=25, signal=["aroon"], hot_thresh=None, cold_thresh=None):
def analyze(self, historical_data, sma_vol_period, period_count=25,
signal=["aroon"], hot_thresh=None, cold_thresh=None):
"""Performs an aroon oscillator analysis on the historical data
Args:
Expand Down Expand Up @@ -39,18 +40,18 @@ def analyze(self, historical_data, sma_vol_period, period_count=25, signal=["aro
index=dataframe.index
)

for index in range(0, dataframe.shape[0]-24):
id = dataframe.shape[0]-index
for index in range(0, dataframe.shape[0] - 24):
id = dataframe.shape[0] - index
id_period = id - period_count
high_date = dataframe['high'].iloc[id_period:id].idxmax()
low_date = dataframe['low'].iloc[id_period:id].idxmin()

periods_since_high = id - dataframe.index.get_loc(high_date) - 1
periods_since_low = id - dataframe.index.get_loc(low_date) - 1
aroon_values['aroon_up'][id-1] = 100 * \
aroon_values['aroon_up'][id - 1] = 100 * \
((25 - periods_since_high) / 25)

aroon_values['aroon_down'][id-1] = 100 * \
aroon_values['aroon_down'][id - 1] = 100 * \
((25 - periods_since_low) / 25)

aroon_values['aroon'] = aroon_values['aroon_up'] - \
Expand Down
7 changes: 4 additions & 3 deletions app/analyzers/indicators/bbp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

"""
"""
Bollinger Bands indicator
"""

Expand All @@ -13,7 +13,8 @@

class BBP(IndicatorUtils):

def analyze(self, historical_data, signal=['bbp'], hot_thresh=0, cold_thresh=0.8, period_count=20, std_dev=2):
def analyze(self, historical_data, signal=[
'bbp'], hot_thresh=0, cold_thresh=0.8, period_count=20, std_dev=2):
"""Check when close price cross the Upper/Lower bands.
Args:
Expand All @@ -23,7 +24,7 @@ def analyze(self, historical_data, signal=['bbp'], hot_thresh=0, cold_thresh=0.8
hot_thresh (float, optional): Defaults to 0. The threshold at which this might be
good to purchase.
cold_thresh (float, optional): Defaults to 0.8. The threshold at which this might be
good to sell.
good to sell.
std_dev (int, optional): number of std dev to use. Common values are 2 or 1
Returns:
Expand Down
5 changes: 3 additions & 2 deletions app/analyzers/indicators/bollinger.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

"""
"""
Bollinger Bands indicator
"""

Expand All @@ -13,7 +13,8 @@

class Bollinger(IndicatorUtils):

def analyze(self, historical_data, signal=['close'], hot_thresh=None, cold_thresh=None, period_count=20, std_dev=2):
def analyze(self, historical_data, signal=[
'close'], hot_thresh=None, cold_thresh=None, period_count=20, std_dev=2):
"""Check when close price cross the Upper/Lower bands.
Args:
Expand Down
3 changes: 2 additions & 1 deletion app/analyzers/indicators/candle_recognition.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@


class Candle_recognition(IndicatorUtils):
def analyze(self, historical_data, signal, notification='hot', candle_check=1, hot_thresh=None, cold_thresh=None):
def analyze(self, historical_data, signal, notification='hot',
candle_check=1, hot_thresh=None, cold_thresh=None):
"""Performs an candle pattern analysis on the historical data
Args:
Expand Down
52 changes: 32 additions & 20 deletions app/analyzers/indicators/ichimoku.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def analyze(self, historical_data, tenkansen_period, kijunsen_period, senkou_spa
tenkansen_period (int, optional)
kijunsen_period (int, optional)
senkou_span_b_period (int, optional)
custom_strategy (string, optional): Defaults to None. Name of the custom strategy. The file name and class name
should have the same name as the custom strategy.
custom_strategy (string, optional): Defaults to None. Name of the custom strategy. The file name and class name
should have the same name as the custom strategy.
Returns:
pandas.DataFrame: A dataframe containing the indicators and hot/cold values.
Expand All @@ -42,7 +42,7 @@ def analyze(self, historical_data, tenkansen_period, kijunsen_period, senkou_spa
'kijunsen': [numpy.nan] * dataframe.index.shape[0],
'leading_span_a': [numpy.nan] * dataframe.index.shape[0],
'leading_span_b': [numpy.nan] * dataframe.index.shape[0],
'chikou_span' : [numpy.nan] * dataframe.index.shape[0]
'chikou_span': [numpy.nan] * dataframe.index.shape[0]
}

ichimoku_values = pandas.DataFrame(ichimoku_columns,
Expand All @@ -60,7 +60,8 @@ def analyze(self, historical_data, tenkansen_period, kijunsen_period, senkou_spa
window=senkou_span_b_period).max()

chikou_span_delay = 26
ichimoku_values['chikou_span'] = dataframe['close'].shift(-chikou_span_delay)
ichimoku_values['chikou_span'] = dataframe['close'].shift(
-chikou_span_delay)
ichimoku_values['tenkansen'] = (low_tenkansen + high_tenkansen) / 2
ichimoku_values['kijunsen'] = (low_kijunsen + high_kijunsen) / 2
ichimoku_values['leading_span_a'] = (
Expand All @@ -79,21 +80,23 @@ def analyze(self, historical_data, tenkansen_period, kijunsen_period, senkou_spa
newindex = pandas.date_range(last_time + timedelta,
freq=timedelta,
periods=cloud_displacement)
ichimoku_values = pd.concat([ichimoku_values, pandas.DataFrame(index=newindex)])
ichimoku_values = pd.concat(
[ichimoku_values, pandas.DataFrame(index=newindex)])
# cloud offset
ichimoku_values['leading_span_a'] = ichimoku_values['leading_span_a'].shift(
cloud_displacement)
ichimoku_values['leading_span_b'] = ichimoku_values['leading_span_b'].shift(
cloud_displacement)
if chart == None:
if custom_strategy == None:

if chart is None:
if custom_strategy is None:
leading_span_hot = False
leading_span_cold = False
tk_cross_hot = False
tk_cross_cold = False
tk_cross_enabled = (('tenkansen' and 'kijunsen') in signal)
leading_span_enabled = (('leading_span_a' and 'leading_span_b') in signal)
leading_span_enabled = (
('leading_span_a' and 'leading_span_b') in signal)
date = dataframe.index[-1]
leading_span_date = ichimoku_values.index[-1]

Expand All @@ -102,19 +105,25 @@ def analyze(self, historical_data, tenkansen_period, kijunsen_period, senkou_spa
tk_cross_cold = ichimoku_values['tenkansen'][date] < ichimoku_values['kijunsen'][date]

if leading_span_enabled:
leading_span_hot = ichimoku_values['leading_span_a'][leading_span_date] > ichimoku_values['leading_span_b'][leading_span_date]
leading_span_cold = ichimoku_values['leading_span_a'][leading_span_date] < ichimoku_values['leading_span_b'][leading_span_date]
leading_span_hot = ichimoku_values['leading_span_a'][
leading_span_date] > ichimoku_values['leading_span_b'][leading_span_date]
leading_span_cold = ichimoku_values['leading_span_a'][
leading_span_date] < ichimoku_values['leading_span_b'][leading_span_date]

if hot_thresh:
ichimoku_values.at[date, 'is_hot'] = tk_cross_hot or leading_span_hot
ichimoku_values.at[date,
'is_hot'] = tk_cross_hot or leading_span_hot

if cold_thresh:
ichimoku_values.at[date, 'is_cold'] = tk_cross_cold or leading_span_cold
ichimoku_values.at[date,
'is_cold'] = tk_cross_cold or leading_span_cold
else:
module = import_module("user_data.strategies." + custom_strategy)
attr = getattr(module, custom_strategy)
module = import_module(
"user_data.strategies." + custom_strategy)
attr = getattr(module, custom_strategy)

custom_hot, custom_cold = attr.analyze(ichimoku_values, dataframe)
custom_hot, custom_cold = attr.analyze(
ichimoku_values, dataframe)
date = dataframe.index[-1]

if hot_thresh:
Expand All @@ -123,11 +132,14 @@ def analyze(self, historical_data, tenkansen_period, kijunsen_period, senkou_spa
if cold_thresh:
ichimoku_values.at[date, 'is_cold'] = custom_cold

# Undo shifting in order to have the values aligned for displaying
# Undo shifting in order to have the values aligned for
# displaying
ichimoku_values['chikou_span'] = dataframe['close']
ichimoku_values['leading_span_a'] = ichimoku_values['leading_span_a'].shift(-cloud_displacement)
ichimoku_values['leading_span_b'] = ichimoku_values['leading_span_b'].shift(-cloud_displacement)

ichimoku_values['leading_span_a'] = ichimoku_values['leading_span_a'].shift(
-cloud_displacement)
ichimoku_values['leading_span_b'] = ichimoku_values['leading_span_b'].shift(
-cloud_displacement)

ichimoku_values.dropna(how='any', inplace=True)

except Exception as e:
Expand Down
5 changes: 3 additions & 2 deletions app/analyzers/indicators/iiv.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@


class IIV(IndicatorUtils):
def analyze(self, historical_data, signal=['iiv'], hot_thresh=10, cold_thresh=0):
def analyze(self, historical_data, signal=[
'iiv'], hot_thresh=10, cold_thresh=0):
"""Performs an analysis about the increase in volumen on the historical data
Args:
historical_data (list): A matrix of historical OHCLV data.
signal (list, optional): Defaults to iiv. The indicator line to check hot against.
hot_thresh (float, optional): Defaults to 10.
hot_thresh (float, optional): Defaults to 10.
cold_thresh: Unused
Expand Down
Loading

0 comments on commit 7802789

Please sign in to comment.