Calcul 20250101-20250714 482 269 max 11

This commit is contained in:
Jérôme Delacotte
2025-07-22 18:00:20 +02:00
parent 27847fea95
commit 23fa2f7765
2 changed files with 938 additions and 4411 deletions

View File

@@ -62,7 +62,7 @@ class Zeus_8_3_2_B_4_2(IStrategy):
"2814": 0.12,
"7675": 0
}
stakes = 50 # days
stakes = 40
# Stoploss:
stoploss = -1 # 0.256
@@ -165,12 +165,12 @@ class Zeus_8_3_2_B_4_2(IStrategy):
pairs = {
pair: {
"first_buy": 0,
"last_buy": 0.0,
"last_min": 999999999999999.5,
"last_max": 0,
"trade_info": {},
"max_touch": 0.0,
"last_min": 999999999999999.5,
"last_sell": 0.0,
"last_buy": 0.0,
'count_of_buys': 0,
'current_profit': 0,
'expected_profit': 0,
@@ -212,37 +212,60 @@ class Zeus_8_3_2_B_4_2(IStrategy):
protection_fibo = IntParameter(1, 10, default=2, space='protection')
sell_allow_decrease = DecimalParameter(0.005, 0.02, default=0.2, decimals=2, space='sell', optimize=True, load=True)
labels = ['B5', 'B4', 'B3', 'B2', 'B1', 'N0', 'H1', 'H2', 'H3', 'H4', 'H5']
index_labels = ['B5', 'B4', 'B3', 'B2', 'B1', 'N0', 'H1', 'H2', 'H3', 'H4', 'H5']
# Récupération des labels ordonnés
ordered_labels = ['B5', 'B4', 'B3', 'B2', 'B1', 'N0', 'H1', 'H2', 'H3', 'H4', 'H5']
# labels = ['B5', 'B4', 'B3', 'B2', 'B1', 'N0', 'H1', 'H2', 'H3', 'H4', 'H5']
# index_labels = ['B5', 'B4', 'B3', 'B2', 'B1', 'N0', 'H1', 'H2', 'H3', 'H4', 'H5']
# ordered_labels = ['B5', 'B4', 'B3', 'B2', 'B1', 'N0', 'H1', 'H2', 'H3', 'H4', 'H5']
labels = ['B3', 'B2', 'B1', 'N0', 'H1', 'H2', 'H3']
index_labels = ['B3', 'B2', 'B1', 'N0', 'H1', 'H2', 'H3']
ordered_labels = ['B3', 'B2', 'B1', 'N0', 'H1', 'H2', 'H3']
label_to_index = {label: i for i, label in enumerate(ordered_labels)}
# # =========================================================================
# # variables pour probabilité
# # Bornes des quantiles pour
# ema_volume = [-8.9178, -0.0196, -0.0096, -0.0053, -0.0026, -0.0007, 0.0009, 0.0029, 0.0056, 0.0101, 0.0200, 3.8009]
# # Bornes des quantiles pour
# mid_smooth_1h_deriv1 = [-1.0482, -0.0571, -0.0336, -0.0206, -0.0113, -0.0033, 0.0044, 0.0127, 0.0225, 0.0356, 0.0591, 0.8335]
#
# ema_volume_mid_smooth_1h_deriv1_matrice = {
# 'B5': [28.0, 32.8, 33.6, 36.4, 35.5, 35.6, 40.1, 40.9, 45.9, 49.7, 52.2],
# 'B4': [33.9, 37.2, 38.6, 40.7, 39.7, 43.0, 46.2, 47.1, 51.9, 55.9, 61.1],
# 'B3': [36.4, 41.3, 39.1, 41.8, 44.6, 46.1, 50.3, 47.9, 47.6, 57.0, 58.5],
# 'B2': [40.7, 40.6, 40.9, 44.6, 48.0, 48.4, 48.5, 53.5, 53.0, 54.8, 53.3],
# 'B1': [37.5, 41.4, 48.0, 46.3, 48.5, 49.1, 53.7, 53.4, 56.4, 56.7, 62.8],
# 'N0': [47.0, 44.3, 45.6, 47.0, 52.9, 52.2, 55.7, 53.0, 57.6, 58.1, 63.4],
# 'H1': [44.1, 46.2, 49.4, 49.3, 52.2, 53.7, 58.2, 57.1, 59.0, 61.6, 61.3],
# 'H2': [51.0, 44.7, 49.4, 51.3, 54.9, 57.9, 56.7, 58.1, 60.3, 60.6, 65.6],
# 'H3': [50.5, 48.3, 49.9, 60.4, 57.8, 56.3, 60.2, 61.9, 62.2, 65.3, 68.3],
# 'H4': [43.1, 53.6, 58.1, 61.4, 58.7, 62.6, 61.3, 65.4, 67.5, 68.2, 71.4],
# 'H5': [56.6, 56.2, 57.7, 63.8, 64.8, 64.7, 66.5, 68.8, 70.9, 72.8, 76.6],
#
# }
#
# ema_volume_mid_smooth_1h_deriv1_matrice_df = pd.DataFrame(ema_volume_mid_smooth_1h_deriv1_matrice, index=index_labels)
# # Extraction de la matrice numérique
# ema_volume_mid_smooth_1h_deriv1_numeric_matrice = ema_volume_mid_smooth_1h_deriv1_matrice_df.reindex(index=ordered_labels, columns=ordered_labels).values
# =========================================================================
# variables pour probabilité
# Bornes des quantiles pour
ema_volume = [-8.9178, -0.0196, -0.0096, -0.0053, -0.0026, -0.0007, 0.0009, 0.0029, 0.0056, 0.0101, 0.0200, 3.8009]
# Bornes des quantiles pour
mid_smooth_1h_deriv1 = [-1.0482, -0.0571, -0.0336, -0.0206, -0.0113, -0.0033, 0.0044, 0.0127, 0.0225, 0.0356, 0.0591, 0.8335]
ema_volume_mid_smooth_1h_deriv1_matrice = {
'B5': [28.0, 32.8, 33.6, 36.4, 35.5, 35.6, 40.1, 40.9, 45.9, 49.7, 52.2],
'B4': [33.9, 37.2, 38.6, 40.7, 39.7, 43.0, 46.2, 47.1, 51.9, 55.9, 61.1],
'B3': [36.4, 41.3, 39.1, 41.8, 44.6, 46.1, 50.3, 47.9, 47.6, 57.0, 58.5],
'B2': [40.7, 40.6, 40.9, 44.6, 48.0, 48.4, 48.5, 53.5, 53.0, 54.8, 53.3],
'B1': [37.5, 41.4, 48.0, 46.3, 48.5, 49.1, 53.7, 53.4, 56.4, 56.7, 62.8],
'N0': [47.0, 44.3, 45.6, 47.0, 52.9, 52.2, 55.7, 53.0, 57.6, 58.1, 63.4],
'H1': [44.1, 46.2, 49.4, 49.3, 52.2, 53.7, 58.2, 57.1, 59.0, 61.6, 61.3],
'H2': [51.0, 44.7, 49.4, 51.3, 54.9, 57.9, 56.7, 58.1, 60.3, 60.6, 65.6],
'H3': [50.5, 48.3, 49.9, 60.4, 57.8, 56.3, 60.2, 61.9, 62.2, 65.3, 68.3],
'H4': [43.1, 53.6, 58.1, 61.4, 58.7, 62.6, 61.3, 65.4, 67.5, 68.2, 71.4],
'H5': [56.6, 56.2, 57.7, 63.8, 64.8, 64.7, 66.5, 68.8, 70.9, 72.8, 76.6],
# paliers dérivées jour sma5
sma5_deriv1 = [-1.1726, -0.2131, -0.1012, -0.0330, 0.0169, 0.0815, 0.2000, 4.0335]
sma5_deriv2 = [-1.9190, -0.1388, -0.0644, -0.0202, 0.0209, 0.0646, 0.1377, 4.2987]
sma5_derive1_2_matrice = {
'B3': [8.6, 10.8, 34.6, 35.0, 58.8, 61.9, 91.2],
'B2': [0.0, 12.5, 9.1, 57.1, 63.3, 79.3, 89.5],
'B1': [6.1, 12.5, 22.0, 46.8, 61.5, 70.0, 100.0],
'N0': [0.0, 10.7, 37.0, 43.5, 75.0, 75.9, 100.0],
'H1': [0.0, 18.5, 32.4, 35.9, 76.8, 82.9, 92.0],
'H2': [0.0, 21.9, 16.0, 39.5, 69.7, 83.3, 100.0],
'H3': [9.5, 29.2, 41.2, 57.9, 53.8, 86.8, 92.3],
}
ema_volume_mid_smooth_1h_deriv1_matrice_df = pd.DataFrame(ema_volume_mid_smooth_1h_deriv1_matrice, index=index_labels)
sma5_derive1_2_matrice_df = pd.DataFrame(sma5_derive1_2_matrice, index=index_labels)
# Extraction de la matrice numérique
ema_volume_mid_smooth_1h_deriv1_numeric_matrice = ema_volume_mid_smooth_1h_deriv1_matrice_df.reindex(index=ordered_labels, columns=ordered_labels).values
sma5_derive1_2_numeric_matrice = sma5_derive1_2_matrice_df.reindex(index=ordered_labels, columns=ordered_labels).values
# paliers = {}
@@ -295,6 +318,9 @@ class Zeus_8_3_2_B_4_2(IStrategy):
self.pairs[pair]['count_of_buys'] = 1
self.pairs[pair]['current_profit'] = 0
self.pairs[pair]['last_palier_index'] = -1
self.pairs[pair]['last_max'] = max(last_candle['haclose'], self.pairs[pair]['last_max'])
self.pairs[pair]['last_min'] = min(last_candle['haclose'], self.pairs[pair]['last_min'])
dispo = round(self.wallets.get_available_stake_amount())
self.printLineLog()
@@ -477,8 +503,8 @@ class Zeus_8_3_2_B_4_2(IStrategy):
return
if self.columns_logged % 30 == 0:
self.printLog(
f"| {'Date':<16} | {'Action':<10} |{'Pair':<5}| {'Trade Type':<18} |{'Rate':>8} | {'Dispo':>6} | {'Profit':>8} | {'Pct':>6} | {'max_touch':>11} | {'last_lost':>12} | {'last_max':>7}|{'Buys':>5}| {'Stake':>5} |"
f"Tdc|{'val':>6}|Distmax|s201d|s5_1d|smt1h|smt2h|"
f"| {'Date':<16} | {'Action':<10} |{'Pair':<5}| {'Trade Type':<18} |{'Rate':>8} | {'Dispo':>6} | {'Profit':>8} | {'Pct':>6} | {'max_touch':>11} | {'last_lost':>12} | {'last_max':>7}| {'last_max':>7}|{'Buys':>5}| {'Stake':>5} |"
f"Tdc|{'val':>6}|Distmax|s201d|s5_1d|s5_2d|smt1h|smt2h|"
)
self.printLineLog()
df = pd.DataFrame.from_dict(self.pairs, orient='index')
@@ -536,32 +562,38 @@ class Zeus_8_3_2_B_4_2(IStrategy):
# val144 = self.getProbaHausse144(last_candle)
# val1h = self.getProbaHausse1h(last_candle)
val = self.getProbaHausse(last_candle)
val = self.getProbaHausseSma5d(last_candle)
pct60 = round(100 * self.getPct60D(pair, last_candle), 2)
color = GREEN if profit > 0 else RED
color_sma20 = GREEN if last_candle['sma20_deriv1_1d'] > 0 else RED
color_sma5 = GREEN if last_candle['sma5_deriv1_1d'] > 0 else RED
color_sma5_2 = GREEN if last_candle['sma5_deriv2_1d'] > 0 else RED
color_smooth_1h = GREEN if last_candle['mid_smooth_1h_deriv1'] > 0 else RED
color_smooth2_1h = GREEN if last_candle['mid_smooth_1h_deriv2'] > 0 else RED
last_max = int(self.pairs[pair]['last_max']) if self.pairs[pair]['last_max'] > 1 else round(self.pairs[pair]['last_max'],3)
last_min = int(self.pairs[pair]['last_min']) if self.pairs[pair]['last_min'] > 1 else round(self.pairs[pair]['last_min'], 3)
self.printLog(
f"| {date:<16} |{action:<10} | {pair[0:3]:<3} | {trade_type or '-':<18} |{rate or '-':>9}| {dispo or '-':>6} "
f"| {color}{profit or '-':>8}{RESET} | {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} |{total_counts or '-':>5}|{stake or '-':>7}"
f"| {last_max or '-':>7} | {last_min or '-':>7} |{total_counts or '-':>5}|{stake or '-':>7}"
f"|{last_candle['tendency_12'] or '-':>3}|" # {last_candle['tendency_1h'] or '-':>3}|{last_candle['tendency_1d'] or '-':>3}"
# f"|{round(last_candle['mid_smooth_24_deriv1'],3) or '-':>6}|{round(last_candle['mid_smooth_1h_deriv1'],3) or '-':>6}|{round(last_candle['mid_smooth_deriv1_1d'],3) or '-' :>6}|"
# f"{round(last_candle['mid_smooth_24_deriv2'],3) or '-' :>6}|{round(last_candle['mid_smooth_1h_deriv2'],3) or '-':>6}|{round(last_candle['mid_smooth_deriv2_1d'],3) or '-':>6}|"
f"{round(val, 1) or '-' :>6}|"
f"{dist_max:>7}|{color_sma20}{round(last_candle['sma20_deriv1_1d'],2):>5}{RESET}|{color_sma5}{round(last_candle['sma5_deriv1_1d'],2):>5}{RESET}"
f"{dist_max:>7}|{color_sma20}{round(last_candle['sma20_deriv1_1d'],2):>5}{RESET}"
f"|{color_sma5}{round(last_candle['sma5_deriv1_1d'],2):>5}{RESET}|{color_sma5_2}{round(last_candle['sma5_deriv2_1d'],2):>5}{RESET}"
f"|{color_smooth_1h}{round(last_candle['mid_smooth_1h_deriv1'],2):>5}{RESET}|{color_smooth2_1h}{round(last_candle['mid_smooth_1h_deriv2'],2):>5}{RESET}"
f"|{last_candle['min60_1d']}|{last_candle['max60_1d']}"
)
def printLineLog(self):
# f"sum1h|sum1d|Tdc|Tdh|Tdd| drv1 |drv_1h|drv_1d|"
self.printLog(
f"+{'-' * 18}+{'-' * 12}+{'-' * 5}+{'-' * 20}+{'-' * 9}+{'-' * 8}+{'-' * 10}+{'-' * 8}+{'-' * 13}+{'-' * 14}+{'-' * 9}+{'-' * 5}+{'-' * 7}+"
f"+{'-' * 18}+{'-' * 12}+{'-' * 5}+{'-' * 20}+{'-' * 9}+{'-' * 8}+{'-' * 10}+{'-' * 8}+{'-' * 13}+{'-' * 14}+{'-' * 9}{'-' * 9}+{'-' * 5}+{'-' * 7}+"
f"{'-' * 3}"
# "+{'-' * 3}+{'-' * 3}
f"+{'-' * 6}+{'-' * 7}+{'-' * 5}+{'-' * 5}+{'-' * 5}+{'-' * 5}+"
@@ -713,11 +745,11 @@ class Zeus_8_3_2_B_4_2(IStrategy):
# poly_func, x_future, y_future, count = self.polynomial_forecast(informative['sma5_deriv1_1d'], window=24, degree=4)
# informative['futur_percent_3'] = 100 * ((informative['sma5'].shift(-3) - informative['sma5']) / informative['sma5'])
# informative['futur_percent_3'] = 100 * ((informative['sma5'].shift(-1) - informative['sma5']) / informative['sma5'])
# futur_cols = ['futur_percent_3']
# indic_1 = 'sma5_deriv1'
# indic_2 = 'sma20_deriv1'
#
# indic_2 = 'sma5_deriv2'
# self.calculateProbabilite2Index(informative, futur_cols, indic_1, indic_2)
dataframe = merge_informative_pair(dataframe, informative, self.timeframe, "1d", ffill=True)
@@ -834,7 +866,13 @@ class Zeus_8_3_2_B_4_2(IStrategy):
# self.calculateProbabilite2Index(dataframe, futur_cols=['futur_percent_3h'], indic_1='ema_volume',
# indic_2='mid_smooth_1h_deriv1')
dataframe['proba_hausse'] = dataframe.apply(lambda row: self.getProbaHausse(row), axis=1)
# dataframe['proba_hausse'] = dataframe.apply(lambda row: self.getProbaHausseEmaVolume(row), axis=1)
# dataframe['futur_percent_3'] = 100 * ((dataframe['sma5'].shift(-1) - dataframe['sma5']) / dataframe['sma5'])
# futur_cols = ['futur_percent_3']
# indic_1 = 'mid_smooth_1h_deriv1'
# indic_2 = 'mid_smooth_1h_deriv2'
# self.calculateProbabilite2Index(dataframe, futur_cols, indic_1, indic_2)
return dataframe
@@ -1065,6 +1103,7 @@ class Zeus_8_3_2_B_4_2(IStrategy):
# lim = - (0.012 + 0.001 * (count_of_buys - 1) + (0.002 * count_of_buys if count_of_buys > 10 else 0.001 * count_of_buys if count_of_buys > 5 else 0))
else:
# lim = self.calculatePctSliding(pair, last_candle)
pct = 0.025
# lim = - pct - (count_of_buys * 0.001)
lim = self.getLimitBuy(pair, last_candle, pct)
@@ -1315,13 +1354,27 @@ class Zeus_8_3_2_B_4_2(IStrategy):
return lim
def getProbaHausse(self, last_candle):
value_1 = self.getValuesFromTable(self.ema_volume, last_candle['ema_volume'])
value_2 = self.getValuesFromTable(self.mid_smooth_1h_deriv1, last_candle['mid_smooth_1h_deriv1'])
# def getProbaHausseEmaVolume(self, last_candle):
# value_1 = self.getValuesFromTable(self.ema_volume, last_candle['ema_volume'])
# value_2 = self.getValuesFromTable(self.mid_smooth_1h_deriv1, last_candle['mid_smooth_1h_deriv1'])
#
# val = self.approx_val_from_bins(
# matrice=self.ema_volume_mid_smooth_1h_deriv1_matrice_df,
# numeric_matrice=self.ema_volume_mid_smooth_1h_deriv1_numeric_matrice,
# row_label=value_2,
# col_label=value_1
# )
# return val
def getProbaHausseSma5d(self, last_candle):
value_1 = self.getValuesFromTable(self.sma5_deriv1, last_candle['sma5_deriv1_1d'])
value_2 = self.getValuesFromTable(self.sma5_deriv2, last_candle['sma5_deriv2_1d'])
# print(f"{last_candle['sma5_deriv1_1d']} => {value_1} / {last_candle['sma5_deriv2_1d']} => {value_2}")
val = self.approx_val_from_bins(
matrice=self.ema_volume_mid_smooth_1h_deriv1_matrice_df,
numeric_matrice=self.ema_volume_mid_smooth_1h_deriv1_numeric_matrice,
matrice=self.sma5_derive1_2_matrice_df,
numeric_matrice=self.sma5_derive1_2_numeric_matrice,
row_label=value_2,
col_label=value_1
)
@@ -1341,31 +1394,51 @@ class Zeus_8_3_2_B_4_2(IStrategy):
adjusted_stake_amount = base_stake_amount * ecart
# if not pair in ('BTC/USDT', 'BTC/USDC'):
# # factors = [1, 1.2, 1.3, 1.4]
# adjusted_stake_amount = base_stake_amount
# else :
# # full = self.wallets.get_total_stake_amount()
# # base_stake_amount = min(100, full / self.stakes)
#
# first_price = self.pairs[pair]['first_buy']
# if (first_price == 0):
# first_price = last_candle['close']
#
# last_max = last_candle['max12_1d']
# pct = 5
# if last_max > 0:
# pct = 100 * (last_max - first_price) / last_max
#
# factor = self.multi_step_interpolate(pct, self.thresholds, self.factors)
# adjusted_stake_amount = base_stake_amount * factor # max(base_stake_amount, min(100, base_stake_amount * percent_4))
# pct = 100 * abs(self.getPctFirstBuy(pair, last_candle))
#
# factor = self.multi_step_interpolate(pct, self.thresholds, self.factors)
return adjusted_stake_amount
def calculateAmountSliding(self, pair, last_candle):
val = last_candle['close']
min_sliding = min(last_candle['min60_1d'], val)
max_sliding = max(last_candle['max60_1d'], val)
min_abs = self.pairs[pair]['last_min']
max_abs = self.pairs[pair]['last_max']
full = self.wallets.get_total_stake_amount()
stake = full / self.stakes
out_min = stake / 2
out_max = stake * 2
# Clamp sliding range within absolute bounds
min_sliding = max(min_sliding, min_abs)
max_sliding = min(max_sliding, max_abs)
# Avoid division by zero
if max_sliding == min_sliding:
return out_max # Or midpoint, or default value
# Inverse linear interpolation
position = (val - min_sliding) / (max_sliding - min_sliding)
return out_max - position * (out_max - out_min)
def calculatePctSliding(self, pair, last_candle):
val = last_candle['close']
min_sliding = last_candle['min60_1d']
max_sliding = last_candle['max60_1d']
min_abs = self.pairs[pair]['last_min']
max_abs = self.pairs[pair]['last_max']
out_min = 0.025
out_max = 0.08
# Clamp sliding range within absolute bounds
min_sliding = max(min_sliding, min_abs)
max_sliding = min(max_sliding, max_abs)
# Avoid division by zero
if max_sliding == min_sliding:
return out_max # Or midpoint, or default value
# Inverse linear interpolation
position = (val - min_sliding) / (max_sliding - min_sliding)
return out_max - position * (out_max - out_min)
def expectedProfit(self, pair: str, last_candle: DataFrame):
pct_to_max = 0.004
max_60 = last_candle['max60_1d']
@@ -1894,7 +1967,7 @@ class Zeus_8_3_2_B_4_2(IStrategy):
return True # BTC toujours autorisé
# Filtrer les paires non-BTC
non_btc_pairs = [p for p in self.pairs] # if not p.startswith('BTC')]
non_btc_pairs = [p for p in self.pairs if not p.startswith('BTC')]
# Compter les positions actives sur les paires non-BTC
max_nb_trades = 0
@@ -1920,7 +1993,21 @@ class Zeus_8_3_2_B_4_2(IStrategy):
self.should_enter_trade_count = 0
# if last_candle['mid_smooth_1h_deriv1'] < -0.15 and last_candle['mid_smooth_1h_deriv2'] <= -0.15:
# return False
#
# if last_candle['sma20_deriv1_1d'] < -0.08 and last_candle['sma5_deriv1_1d'] <= -0.1:
# return False
#
# if (self.pairs[pair]['count_of_buys'] >= 5):
# val = self.getProbaHausseSma5d(last_candle)
# if (val < 30):
# return False
if last_candle['sma5_deriv1_1d'] < -0.1:
return False
if max_pair != '' :
return (max_pair == pair and self.pairs[pair]['count_of_buys'] <= 5) or pct_max < - 0.1
return max_pair == pair
else:
return True