diff --git a/Zeus_8_3_2_B_4_2.py b/Zeus_8_3_2_B_4_2.py index f8c5083..5703edd 100644 --- a/Zeus_8_3_2_B_4_2.py +++ b/Zeus_8_3_2_B_4_2.py @@ -205,7 +205,7 @@ class Zeus_8_3_2_B_4_2(IStrategy): # Probabilité de hausse pour futur_percent_3h (en %): # mid_smooth_deriv1_1h_bin B5 B4 B3 B2 B1 N0 H1 H2 H3 H4 H5 - # sma24_diff_1h_bin + # sma24_deriv1_1h_bin # B5 41.0 47.2 48.1 45.6 74.0 65.9 66.5 83.8 77.8 72.1 81.0 # B4 41.2 35.8 48.4 46.5 59.9 60.2 75.8 79.4 84.6 83.0 78.5 # B3 34.1 39.7 42.8 47.0 63.3 64.5 71.5 80.4 82.0 86.6 76.6 @@ -225,8 +225,27 @@ class Zeus_8_3_2_B_4_2(IStrategy): # Données sous forme de dictionnaire # Bornes des quantiles pour - mid_smooth_deriv1_24_bins = [-13.5716, -0.2332, -0.1108, -0.0566, -0.0246, -0.0014, 0.0096, 0.0340, 0.0675, 0.1214, 0.2468, 8.5702] - sma144_diff_bins = [-0.2592, -0.0166, -0.0091, -0.0051, -0.0025, -0.0005, 0.0012, 0.0034, 0.0062, 0.0105, 0.0183, 0.2436] + mid_smooth_deriv1_24_bins = [-37.4852, -0.7541, -0.4233, -0.2510, -0.1338, -0.0389, 0.0496, 0.1464, 0.2660, 0.4384, 0.7697, 48.2985] + sma144_deriv1_bins = [-0.2592, -0.0166, -0.0091, -0.0051, -0.0025, -0.0005, 0.0012, 0.0034, 0.0062, 0.0105, 0.0183, 0.2436] + + smooth24_sma144_deriv1_matrice = { + 'B5': [8.2, 4.1, 3.1, 3.4, 3.5, 3.0, 2.9, 2.8, 2.5, 3.0, 4.1], + 'B4': [24.9, 13.5, 11.8, 11.0, 9.0, 9.3, 9.1, 8.9, 8.1, 7.8, 11.4], + 'B3': [39.8, 24.7, 20.4, 18.8, 17.4, 16.0, 16.2, 14.7, 15.4, 15.5, 15.9], + 'B2': [54.8, 40.6, 32.7, 28.3, 25.9, 24.3, 23.1, 24.0, 23.4, 24.2, 21.1], + 'B1': [65.1, 52.9, 46.6, 44.7, 38.8, 37.7, 35.4, 33.6, 32.2, 33.1, 27.4], + 'N0': [73.1, 62.9, 61.1, 59.0, 56.1, 52.4, 49.5, 48.5, 42.7, 39.9, 35.3], + 'H1': [79.7, 72.5, 73.1, 72.6, 71.6, 69.8, 66.9, 63.8, 58.0, 53.2, 41.9], + 'H2': [81.7, 79.8, 79.6, 80.8, 79.3, 80.1, 78.1, 76.7, 72.5, 65.7, 52.8], + 'H3': [86.1, 87.7, 87.4, 87.8, 87.2, 86.5, 84.5, 84.4, 82.7, 78.8, 65.4], + 'H4': [92.6, 93.4, 94.0, 93.4, 94.3, 94.0, 93.8, 93.7, 92.7, 89.6, 79.9], + 'H5': [97.1, 97.5, 97.9, 98.2, 97.5, 98.2, 98.1, 98.2, 97.7, 97.4, 93.5], + } + + smooth24_sma144_deriv1_matrice_df = pd.DataFrame(smooth24_sma144_deriv1_matrice, index=index_labels) + # Extraction de la matrice numérique + smooth24_sma144_deriv1_numeric_matrice = smooth24_sma144_deriv1_matrice_df.reindex(index=ordered_labels, columns=ordered_labels).values + # Bornes des quantiles pour mid_smooth_deriv2_24_bins = [-10.2968, -0.2061, -0.0996, -0.0559, -0.0292, -0.0093, 0.0083, 0.0281, 0.0550, 0.0999, 0.2072, 10.2252] @@ -234,7 +253,7 @@ class Zeus_8_3_2_B_4_2(IStrategy): # ========================================================================= # variables pour probabilité 144 bougies mid_smooth_1h_bins = [-2.0622, -0.1618, -0.0717, -0.0353, -0.0135, 0.0, 0.0085, 0.0276, 0.0521, 0.0923, 0.1742, 2.3286] - sma24_diff_1h_bins = [-0.84253877, -0.13177195, -0.07485074, -0.04293497, -0.02033502, -0.00215711, + sma24_deriv1_1h_bins = [-0.84253877, -0.13177195, -0.07485074, -0.04293497, -0.02033502, -0.00215711, 0.01411933, 0.03308264, 0.05661652, 0.09362708, 0.14898214, 0.50579505] smooth_smadiff_matrice = { "B5": [41.0, 41.2, 34.1, 27.5, 35.0, 30.6, 25.2, 29.8, 25.7, 30.6, 14.8], @@ -304,7 +323,7 @@ class Zeus_8_3_2_B_4_2(IStrategy): # Bornes des quantiles pour mid_smooth_deriv1_1h_1d_bins = [-11.5091, -0.4887, -0.1902, -0.0823, -0.0281, -0.0008, 0.0110, 0.0439, 0.1066, 0.2349, 0.5440, 14.7943] # Bornes des quantiles pour - sma24_diff_1h_1d_bins = [-2.1101, -0.1413, -0.0768, -0.0433, -0.0196, -0.0028, 0.0120, 0.0304, 0.0560, 0.0933, 0.1568, 0.7793] + sma24_deriv1_1h_1d_bins = [-2.1101, -0.1413, -0.0768, -0.0433, -0.0196, -0.0028, 0.0120, 0.0304, 0.0560, 0.0933, 0.1568, 0.7793] smooth_1d_sma_2_diff_1d_matrice = { 'B5': [42.5, 47.8, 52.7, 48.5, 54.2, 64.6, 70.8, 69.2, 72.3, 71.2, 79.9], @@ -448,16 +467,6 @@ class Zeus_8_3_2_B_4_2(IStrategy): if (last_candle['tendency'] in ('H++', 'H+')) and (last_candle['rsi'] < 80): return None - # val144 = self.getProbaHausse144(last_candle) - # val1h = self.getProbaHausse1h(last_candle) - # - # if (val144 * val1h > 3600) : - # return None - - # val = self.getProbaHausse144(last_candle) - # if val > 50: - # return None - baisse = self.pairs[pair]['max_profit'] - current_profit mx = self.pairs[pair]['max_profit'] / 5 if (baisse > mx) & (current_profit > expected_profit): @@ -561,8 +570,8 @@ class Zeus_8_3_2_B_4_2(IStrategy): f"| {profit or '-':>8} | {pct_max or '-':>6} | {round(self.pairs[pair]['max_touch'], 2) or '-':>11} | {last_lost or '-':>12} " f"| {int(self.pairs[pair]['last_max']) or '-':>7} |{buys or '-':>4}|{stake or '-':>7}" f"|{last_candle['tendency'] or '-':>3}|{last_candle['tendency_1h'] or '-':>3}|{last_candle['tendency_1d'] or '-':>3}" - f"|{round(last_candle['mid_smooth_deriv1'],3) or '-':>6}|{round(last_candle['mid_smooth_deriv1_1h'],3) or '-':>6}|{round(last_candle['mid_smooth_deriv1_1d'],3) or '-' :>6}|" - f"{round(last_candle['mid_smooth_deriv2'],3) or '-' :>6}|{round(last_candle['mid_smooth_deriv2_1h'],3) or '-':>6}|{round(last_candle['mid_smooth_deriv2_1d'],3) or '-':>6}|" + f"|{round(last_candle['mid_smooth_deriv1_24'],3) or '-':>6}|{round(last_candle['mid_smooth_deriv1_1h'],3) or '-':>6}|{round(last_candle['mid_smooth_deriv1_1d'],3) or '-' :>6}|" + f"{round(last_candle['mid_smooth_deriv2_24'],3) or '-' :>6}|{round(last_candle['mid_smooth_deriv2_1h'],3) or '-':>6}|{round(last_candle['mid_smooth_deriv2_1d'],3) or '-':>6}|" f"{round(val144, 1) or '-' :>6}|{round(val1h, 1) or '-':>6}|" ) @@ -623,15 +632,15 @@ class Zeus_8_3_2_B_4_2(IStrategy): dataframe['sma20'] = talib.SMA(dataframe, timeperiod=20) dataframe['sma20_pct'] = 100 * dataframe['sma20'].diff() / dataframe['sma20'] dataframe['sma144'] = talib.SMA(dataframe, timeperiod=144) - dataframe['sma144_diff'] = 100 * dataframe['sma144'].diff() / dataframe['sma144'] + dataframe['sma144_deriv1'] = 100 * dataframe['sma144'].diff() / dataframe['sma144'] dataframe["percent"] = (dataframe["close"] - dataframe["open"]) / dataframe["open"] dataframe["percent3"] = (dataframe["close"] - dataframe["open"].shift(3)) / dataframe["open"].shift(3) dataframe["percent5"] = (dataframe["close"] - dataframe["open"].shift(5)) / dataframe["open"].shift(5) dataframe["percent12"] = (dataframe["close"] - dataframe["open"].shift(12)) / dataframe["open"].shift(12) - dataframe = self.calculateTendency(dataframe, window=12) - dataframe = self.calculateTendency(dataframe, window=24, suffixe="_24", factor_1=1000, factor_2=10) + dataframe = self.calculateDerivation(dataframe, window=12) + dataframe = self.calculateDerivation(dataframe, window=24, suffixe="_24", factor_1=1000, factor_2=10) # print(metadata['pair']) dataframe['rsi'] = talib.RSI(dataframe['close'], timeperiod=14) @@ -663,7 +672,7 @@ class Zeus_8_3_2_B_4_2(IStrategy): self.calculateDownAndUp(dataframe, limit=0.0001) dataframe = self.calculateRegression(dataframe, column='mid_smooth', window=24, degree=4, future_offset=12) - dataframe = self.calculateRegression(dataframe, column='mid_smooth_24', window=144, degree=4, future_offset=12) + dataframe = self.calculateRegression(dataframe, column='mid_smooth_24', window=24, degree=4, future_offset=12) ################### INFORMATIVE 1h informative = self.dp.get_pair_dataframe(pair=metadata['pair'], timeframe="1h") @@ -672,7 +681,7 @@ class Zeus_8_3_2_B_4_2(IStrategy): informative['haclose'] = heikinashi['close'] informative['hapercent'] = (informative['haclose'] - informative['haopen']) / informative['haclose'] - informative = self.calculateTendency(informative, window=12) + informative = self.calculateDerivation(informative, window=12) # informative = self.apply_regression_derivatives(informative, column='mid', window=5, degree=4) # informative['volatility'] = talib.STDDEV(informative['close'], timeperiod=14) / informative['close'] # informative['atr'] = (talib.ATR(informative['high'], informative['low'], informative['close'], timeperiod=14)) / informative['close'] @@ -685,7 +694,7 @@ class Zeus_8_3_2_B_4_2(IStrategy): informative['sma5'] = talib.SMA(informative, timeperiod=5) informative['sma5_diff'] = 100 * informative['sma5'].diff() / informative['sma5'] informative['sma24'] = talib.SMA(informative, timeperiod=24) - informative['sma24_diff'] = 100 * informative['sma24'].rolling(7).mean().diff() / informative['sma24'] + informative['sma24_deriv1'] = 100 * informative['sma24'].rolling(7).mean().diff() / informative['sma24'] self.calculateDownAndUp(informative, limit=0.0012) @@ -693,7 +702,7 @@ class Zeus_8_3_2_B_4_2(IStrategy): ################### INFORMATIVE 1d informative = self.dp.get_pair_dataframe(pair=metadata['pair'], timeframe="1d") - informative = self.calculateTendency(informative, window=5, factor_1=10000, factor_2=1000) + informative = self.calculateDerivation(informative, window=5, factor_1=10000, factor_2=1000) # informative['volatility'] = talib.STDDEV(informative['close'], timeperiod=14) / informative['close'] # informative['atr'] = (talib.ATR(informative['high'], informative['low'], informative['close'], timeperiod=14)) / informative['close'] @@ -759,7 +768,7 @@ class Zeus_8_3_2_B_4_2(IStrategy): dataframe['sma5_1h'] = dataframe['sma5_1h'].rolling(window=horizon_h).mean() dataframe['sma5_diff_1h'] = dataframe['sma5_diff_1h'].rolling(window=horizon_h).mean() dataframe['sma24_1h'] = dataframe['sma24_1h'].rolling(window=horizon_h).mean() - dataframe['sma24_diff_1h'] = dataframe['sma24_diff_1h'].rolling(window=horizon_h).mean() + dataframe['sma24_deriv1_1h'] = dataframe['sma24_deriv1_1h'].rolling(window=horizon_h).mean() dataframe = self.calculateRegression(dataframe, column='mid_smooth_1h', window=horizon_h * 12, degree=4, future_offset=24) @@ -772,7 +781,7 @@ class Zeus_8_3_2_B_4_2(IStrategy): dataframe['sma5_1d'] = dataframe['sma5_1d'].rolling(window=horizon_d * 5).mean() dataframe['sma5_diff_1d'] = dataframe['sma5_diff_1d'].rolling(window=horizon_d).mean() # dataframe['sma24_1d'] = dataframe['sma24_1d'].rolling(window=horizon_d).mean() - # dataframe['sma24_diff_1d'] = dataframe['sma24_diff_1d'].rolling(window=horizon_d).mean() + # dataframe['sma24_deriv1_1d'] = dataframe['sma24_deriv1_1d'].rolling(window=horizon_d).mean() # dataframe = self.calculateRegression(dataframe, column='mid_smooth_1d', window=24, degree=4, future_offset=12) dataframe['percent_with_previous_day'] = 100 * (dataframe['close'] - dataframe['close_1d']) / dataframe['close'] @@ -786,7 +795,7 @@ class Zeus_8_3_2_B_4_2(IStrategy): # dataframe['futur_percent_1d'] = 100 * (dataframe['close'].shift(-1) - dataframe['close']) / dataframe['close'] # dataframe['futur_percent_3d'] = 100 * (dataframe['close'].shift(-3) - dataframe['close']) / dataframe['close'] - self.calculateProbabilite2Index(dataframe, ['futur_percent_12h'], 'mid_smooth_deriv1_1d', 'sma24_diff_1h') + self.calculateProbabilite2Index(dataframe, ['futur_percent_12h'], 'mid_smooth_deriv1_1d', 'sma24_deriv1_1h') return dataframe @@ -801,16 +810,15 @@ class Zeus_8_3_2_B_4_2(IStrategy): dataframe['down_pct'] = self.calculateUpDownPct(dataframe, 'down_count') dataframe['up_pct'] = self.calculateUpDownPct(dataframe, 'up_count') - def calculateTendency(self, dataframe, window=12, suffixe='', factor_1=100, factor_2=10): + def calculateDerivation(self, dataframe, window=12, suffixe='', factor_1=100, factor_2=10): dataframe['mid'] = dataframe['open'] + (dataframe['close'] - dataframe['open']) / 2 # 1. Calcul du lissage par moyenne mobile médiane - dataframe[f"mid_smooth{suffixe}"] = dataframe['close'].rolling(window=window).median().rolling( - int(window / 4)).mean() + dataframe[f"mid_smooth{suffixe}"] = dataframe['close'].rolling(window=window).mean() # 2. Dérivée première = différence entre deux bougies successives - dataframe[f"mid_smooth_deriv1{suffixe}"] = round(factor_1 * dataframe[f"mid_smooth{suffixe}"].diff() / dataframe[f"mid_smooth{suffixe}"], 4) + dataframe[f"mid_smooth_deriv1{suffixe}"] = round(factor_1 * dataframe[f"mid_smooth{suffixe}"].rolling(window=3).mean().diff() / dataframe[f"mid_smooth{suffixe}"], 4) # 3. Dérivée seconde = différence de la dérivée première - dataframe[f"mid_smooth_deriv2{suffixe}"] = round(factor_2 * dataframe[f"mid_smooth_deriv1{suffixe}"].rolling(int(window / 4)).mean().diff(), 4) + dataframe[f"mid_smooth_deriv2{suffixe}"] = round(factor_2 * dataframe[f"mid_smooth_deriv1{suffixe}"].rolling(window=3).mean().diff(), 4) dataframe = self.add_tendency_column(dataframe, suffixe) return dataframe @@ -848,9 +856,12 @@ class Zeus_8_3_2_B_4_2(IStrategy): dataframe.loc[ ( - # (dataframe['down_count'].shift(1) < - 1) - # & (dataframe['down_count'] == 0) - (dataframe['mid_smooth_deriv1'] > 0) + (dataframe['mid_smooth_deriv1_1h'] >= -0.01) + & (dataframe['mid_smooth_deriv1_1h'] >= dataframe['mid_smooth_deriv1_1h'].shift(1)) + & (dataframe['mid_smooth_deriv2_1h'] >= dataframe['mid_smooth_deriv2_1h'].shift(1)) + # & (dataframe['mid_smooth_deriv1'] >= dataframe['mid_smooth_deriv1'].shift(1)) + # & (dataframe['mid_smooth_deriv1_24'] >= dataframe['mid_smooth_deriv1_24'].shift(1)) # avant pente positive + # & (dataframe['mid_smooth_deriv1_24'].shift(1) <= dataframe['mid_smooth_deriv1_24'].shift(2)) # accélération haussière ), ['enter_long', 'enter_tag']] = (1, 'down') dataframe.loc[ @@ -874,8 +885,8 @@ class Zeus_8_3_2_B_4_2(IStrategy): # Tranches équitables par quantiles - indic_1 = 'mid_smooth_deriv1_1h' - indic_2 = 'sma24_diff_1h' + indic_1 = 'mid_smooth_deriv1_24' + indic_2 = 'sma144_deriv1' #indic_2 = 'percent_with_max_hour' # indic_1 = 'mid_smooth_deriv1_1h' # indic_2 = 'sma5_diff_1d' @@ -1012,16 +1023,6 @@ class Zeus_8_3_2_B_4_2(IStrategy): # val144 = self.getProbaHausse144(last_candle) # val1h = self.getProbaHausse1h(last_candle) val = self.getProbaHausse144(last_candle) - # if hours_since_first_buy < 12: - # val = self.getProbaHausse144(last_candle) - # else: - # val = self.getProbaHausse1h(last_candle) - # # if (days_since_open < 2): - # # val = self.getProbaHausse1h(last_candle) - # # else: - # # val = self.getProbaHausse1d(last_candle) - - # print(f"Valeur approximée pour B3 / H2 : {val:.2f}") # if (days_since_open > count_of_buys) & (0 < count_of_buys <= max_buys) & (current_rate <= limit) & (last_candle['enter_long'] == 1): limit_buy = 20 @@ -1085,15 +1086,18 @@ class Zeus_8_3_2_B_4_2(IStrategy): def getProbaHausse144(self, last_candle): value_1 = self.getValuesFromTable(self.mid_smooth_deriv1_24_bins, last_candle['mid_smooth_deriv1_24']) - value_2 = self.getValuesFromTable(self.sma144_diff_bins, last_candle['sma144_diff']) + value_2 = self.getValuesFromTable(self.sma144_deriv1_bins, last_candle['sma144_deriv1']) - val = self.approx_val_from_bins(matrice=self.smooth_sma_24_diff_matrice_df, numeric_matrice=self.smooth_sma_24_diff_numeric_matrice, row_label=value_2, - col_label=value_1) + val = self.approx_val_from_bins( + matrice=self.smooth24_sma144_deriv1_matrice_df, + numeric_matrice=self.smooth24_sma144_deriv1_numeric_matrice, + row_label=value_1, + col_label=value_2) return val def getProbaHausse1h(self, last_candle): value_1 = self.getValuesFromTable(self.mid_smooth_1h_bins, last_candle['mid_smooth_deriv1_1h']) - value_2 = self.getValuesFromTable(self.sma24_diff_1h_bins, last_candle['sma24_diff_1h']) + value_2 = self.getValuesFromTable(self.sma24_deriv1_1h_bins, last_candle['sma24_deriv1_1h']) val = self.approx_val_from_bins(matrice=self.smooth_smadiff_matrice_df, numeric_matrice=self.smooth_smadiff_numeric_matrice, row_label=value_2, col_label=value_1) @@ -1101,7 +1105,7 @@ class Zeus_8_3_2_B_4_2(IStrategy): def getProbaHausse1d(self, last_candle): value_1 = self.getValuesFromTable(self.mid_smooth_1h_bins, last_candle['mid_smooth_deriv1_1d']) - value_2 = self.getValuesFromTable(self.sma24_diff_1h_bins, last_candle['sma5_diff_1d']) + value_2 = self.getValuesFromTable(self.sma24_deriv1_1h_bins, last_candle['sma5_diff_1d']) val = self.approx_val_from_bins(matrice=self.smooth_smadiff_matrice_df, numeric_matrice=self.smooth_smadiff_numeric_matrice, row_label=value_2, col_label=value_1) diff --git a/tools/statistique/vue_3d.py b/tools/statistique/vue_3d.py index f4931a0..79828ed 100644 --- a/tools/statistique/vue_3d.py +++ b/tools/statistique/vue_3d.py @@ -8,17 +8,17 @@ y_labels = ['B5', 'B4', 'B3', 'B2', 'B1', 'N0', 'H1', 'H2', 'H3', 'H4', 'H5'] # Data data = np.array([ - [40.3, 52.1, 60.2, 68.6, 86.3, 76.5, 75.1, 83.5, 88.7, 96.3, 91.6], - [26.6, 39.4, 48.1, 57.0, 76.7, 82.4, 79.6, 82.4, 91.8, 86.6, 87.8], - [21.5, 27.7, 42.7, 53.2, 70.9, 76.6, 80.8, 79.4, 88.3, 88.0, 87.8], - [15.1, 20.8, 32.9, 46.9, 59.1, 79.6, 82.5, 79.6, 80.8, 87.0, 85.5], - [15.7, 15.4, 21.9, 29.4, 48.3, 66.6, 76.4, 77.8, 80.8, 83.5, 81.4], - [15.0, 10.5, 20.1, 24.5, 36.9, 59.9, 68.8, 74.1, 77.7, 83.0, 75.7], - [14.8, 10.7, 15.1, 21.0, 30.1, 47.3, 59.2, 70.4, 76.1, 82.7, 82.6], - [7.9, 8.6, 13.6, 20.6, 27.0, 39.5, 55.2, 68.9, 69.0, 78.4, 83.4], - [9.2, 6.2, 12.6, 21.7, 23.6, 33.1, 42.3, 57.8, 66.0, 71.9, 81.9], - [4.8, 13.1, 16.3, 14.5, 19.5, 26.4, 35.6, 49.2, 63.2, 68.2, 71.6], - [17.9, 25.7, 20.8, 17.8, 8.7, 18.5, 32.3, 37.7, 49.3, 59.8, 61.7] + [8.2, 4.1, 3.1, 3.4, 3.5, 3.0, 2.9, 2.8, 2.5, 3.0, 4.1], + [24.9, 13.5, 11.8, 11.0, 9.0, 9.3, 9.1, 8.9, 8.1, 7.8, 11.4], + [39.8, 24.7, 20.4, 18.8, 17.4, 16.0, 16.2, 14.7, 15.4, 15.5, 15.9], + [54.8, 40.6, 32.7, 28.3, 25.9, 24.3, 23.1, 24.0, 23.4, 24.2, 21.1], + [65.1, 52.9, 46.6, 44.7, 38.8, 37.7, 35.4, 33.6, 32.2, 33.1, 27.4], + [73.1, 62.9, 61.1, 59.0, 56.1, 52.4, 49.5, 48.5, 42.7, 39.9, 35.3], + [79.7, 72.5, 73.1, 72.6, 71.6, 69.8, 66.9, 63.8, 58.0, 53.2, 41.9], + [81.7, 79.8, 79.6, 80.8, 79.3, 80.1, 78.1, 76.7, 72.5, 65.7, 52.8], + [86.1, 87.7, 87.4, 87.8, 87.2, 86.5, 84.5, 84.4, 82.7, 78.8, 65.4], + [92.6, 93.4, 94.0, 93.4, 94.3, 94.0, 93.8, 93.7, 92.7, 89.6, 79.9], + [97.1, 97.5, 97.9, 98.2, 97.5, 98.2, 98.1, 98.2, 97.7, 97.4, 93.5] ]) # Meshgrid for 3D plotting