Calcul 2020-2025 4015$ profit
This commit is contained in:
@@ -209,37 +209,7 @@ 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)
|
||||
|
||||
# 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
|
||||
# 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
|
||||
# B2 27.5 27.9 32.3 33.2 61.9 67.1 70.8 79.5 81.3 73.6 81.9
|
||||
# B1 35.0 26.5 24.4 34.9 50.0 59.2 69.4 72.8 79.8 77.4 69.5
|
||||
# N0 30.6 19.9 23.6 30.8 41.9 59.2 67.5 70.6 74.0 63.0 75.0
|
||||
# H1 25.2 28.7 28.6 25.8 35.9 44.2 60.1 68.8 67.7 69.6 80.9
|
||||
# H2 29.8 20.8 23.9 30.4 34.4 37.5 52.7 66.1 69.8 67.5 62.9
|
||||
# H3 25.7 29.4 22.7 29.8 37.7 47.1 59.9 68.5 66.5 68.6 66.4
|
||||
# H4 30.6 27.5 25.1 22.6 30.8 34.1 50.9 59.8 57.0 68.6 63.7
|
||||
# H5 14.8 21.6 22.2 35.3 19.3 31.6 38.3 59.6 65.2 56.8 59.6
|
||||
|
||||
# Données sous forme de dictionnaire
|
||||
# smooth_smadiff_matrice = {
|
||||
# 'B5': [41.2, 41.9, 35.3, 29.5, 26.6, 32.7, 28.8, 30.4, 25.3, 20.2, 14.6],
|
||||
# 'B4': [45.2, 40.1, 38.6, 31.2, 30.1, 29.5, 27.1, 24.2, 24.7, 21.6, 18.4],
|
||||
# 'B3': [46.7, 41.6, 37.3, 33.4, 27.3, 28.6, 28.8, 24.6, 24.2, 24.8, 23.2],
|
||||
# 'B2': [49.4, 47.9, 45.9, 39.8, 34.6, 28.6, 26.2, 28.9, 24.7, 29.7, 28.5],
|
||||
# 'B1': [74.1, 61.7, 61.7, 58.2, 50.2, 43.5, 38.1, 32.5, 33.9, 32.8, 25.3],
|
||||
# 'N0': [67.8, 58.3, 67.8, 61.7, 58.0, 56.2, 46.7, 42.2, 44.4, 39.7, 30.3],
|
||||
# 'H1': [72.6, 66.2, 70.8, 69.1, 70.8, 65.3, 56.3, 51.2, 52.6, 53.9, 48.1],
|
||||
# 'H2': [77.2, 78.7, 81.0, 75.9, 73.6, 73.0, 65.4, 63.3, 63.8, 56.9, 52.8],
|
||||
# 'H3': [78.8, 76.6, 78.8, 81.2, 76.7, 71.9, 69.2, 67.8, 66.1, 61.3, 58.1],
|
||||
# 'H4': [75.5, 79.0, 78.0, 78.5, 73.6, 66.4, 71.2, 63.8, 67.0, 62.6, 59.3],
|
||||
# 'H5': [75.1, 78.6, 81.0, 72.3, 70.0, 71.4, 67.8, 66.0, 66.2, 64.5, 59.9]
|
||||
# }
|
||||
|
||||
smooth_smadiff_matrice = {
|
||||
data = {
|
||||
"B5": [41.0, 41.2, 34.1, 27.5, 35.0, 30.6, 25.2, 29.8, 25.7, 30.6, 14.8],
|
||||
"B4": [47.2, 35.8, 39.7, 27.9, 26.5, 19.9, 28.7, 20.8, 29.4, 27.5, 21.6],
|
||||
"B3": [48.1, 48.4, 42.8, 32.3, 24.4, 23.6, 28.6, 23.9, 22.7, 25.1, 22.2],
|
||||
@@ -254,33 +224,7 @@ class Zeus_8_3_2_B_4_2(IStrategy):
|
||||
}
|
||||
|
||||
index_labels = ['B5', 'B4', 'B3', 'B2', 'B1', 'N0', 'H1', 'H2', 'H3', 'H4', 'H5']
|
||||
smooth_smadiff_matrice_df = pd.DataFrame(smooth_smadiff_matrice, index=index_labels)
|
||||
# Récupération des labels ordonnés
|
||||
ordered_labels = ['B5', 'B4', 'B3', 'B2', 'B1', 'N0', 'H1', 'H2', 'H3', 'H4', 'H5']
|
||||
label_to_index = {label: i for i, label in enumerate(ordered_labels)}
|
||||
# Extraction de la matrice numérique
|
||||
smooth_smadiff_numeric_matrice = smooth_smadiff_matrice_df.reindex(index=ordered_labels, columns=ordered_labels).values
|
||||
|
||||
smooth_pct_max_hour_matrice = {
|
||||
'B5': [43.5, 52.7, 62.3, 65.5, 86.9, 63.1, 81.5, 86.7, 90.2, 90.1, 93.0],
|
||||
'B4': [34.9, 46.3, 53.6, 60.4, 75.8, 83.3, 81.5, 83.0, 86.4, 86.9, 91.1],
|
||||
'B3': [20.5, 35.4, 43.7, 54.5, 69.7, 71.6, 80.4, 84.7, 86.7, 84.9, 85.9],
|
||||
'B2': [11.5, 25.4, 36.4, 47.9, 62.3, 65.7, 76.5, 82.0, 81.8, 82.8, 77.7],
|
||||
'B1': [3.6, 14.9, 26.8, 41.1, 55.6, 71.4, 74.3, 79.8, 80.8, 82.3, 75.1],
|
||||
'N0': [0.0, 6.9, 18.3, 32.0, 47.2, 62.1, 69.1, 74.8, 78.3, 76.6, 71.6],
|
||||
'H1': [0.7, 3.8, 9.4, 24.2, 40.6, 59.7, 67.8, 70.9, 73.4, 72.1, 70.0],
|
||||
'H2': [0.0, 0.6, 6.5, 13.6, 33.6, 51.7, 64.9, 70.2, 68.4, 67.8, 65.8],
|
||||
'H3': [1.4, 0.6, 2.6, 6.6, 23.3, 50.2, 56.2, 63.6, 65.7, 64.5, 64.7],
|
||||
'H4': [1.6, 0.3, 3.0, 3.2, 11.4, 32.7, 44.0, 54.9, 61.7, 60.6, 63.6],
|
||||
'H5': [1.8, 2.6, 0.6, 1.1, 9.7, 12.9, 26.2, 44.5, 52.6, 54.5, 56.2],
|
||||
}
|
||||
|
||||
smooth_pct_max_hour_matrice_df = pd.DataFrame(smooth_pct_max_hour_matrice, index=index_labels)
|
||||
# Récupération des labels ordonnés
|
||||
# ordered_labels = ['B5', 'B4', 'B3', 'B2', 'B1', 'N0', 'H1', 'H2', 'H3', 'H4', 'H5']
|
||||
# label_to_index = {label: i for i, label in enumerate(ordered_labels)}
|
||||
# Extraction de la matrice numérique
|
||||
smooth_smadiff_numeric_matrice = smooth_pct_max_hour_matrice_df.reindex(index=ordered_labels, columns=ordered_labels).values
|
||||
matrix_df = pd.DataFrame(data, index=index_labels)
|
||||
|
||||
|
||||
def confirm_trade_entry(self, pair: str, order_type: str, amount: float, rate: float, time_in_force: str,
|
||||
@@ -288,7 +232,7 @@ class Zeus_8_3_2_B_4_2(IStrategy):
|
||||
|
||||
minutes = 0
|
||||
if self.pairs[pair]['last_date'] != 0:
|
||||
minutes = round(int((current_time - self.pairs[pair]['last_date']).total_seconds() / 60))
|
||||
minutes = round((current_time - self.pairs[pair]['last_date']).total_seconds() / 60,0)
|
||||
|
||||
dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)
|
||||
last_candle = dataframe.iloc[-1].squeeze()
|
||||
@@ -302,7 +246,7 @@ class Zeus_8_3_2_B_4_2(IStrategy):
|
||||
mid_smooth_label = self.get_mid_smooth_label(last_candle['mid_smooth_deriv1_1h']) # ex. 'B2'
|
||||
sma24_diff_label = self.get_sma24_diff_label(last_candle['sma24_diff_1h'])
|
||||
|
||||
val = self.approx_val_from_bins(matrice=self.smooth_smadiff_matrice_df, row_label=sma24_diff_label, col_label=mid_smooth_label)
|
||||
val = self.approx_val_from_bins(row_label=sma24_diff_label, col_label=mid_smooth_label)
|
||||
|
||||
# allow_to_buy = True #(not self.stop_all) #& (not self.all_down)
|
||||
allow_to_buy = not self.pairs[pair]['stop'] and val > 50 #not last_candle['tendency'] in ('B-', 'B--') # (rate <= float(limit)) | (entry_tag == 'force_entry')
|
||||
@@ -410,13 +354,6 @@ class Zeus_8_3_2_B_4_2(IStrategy):
|
||||
if (last_candle['tendency'] in ('H++', 'H+')) and (last_candle['rsi'] < 80):
|
||||
return None
|
||||
|
||||
# mid_smooth_label = self.get_mid_smooth_label(last_candle['mid_smooth_deriv1_1h']) # ex. 'B2'
|
||||
# sma24_diff_label = self.get_sma24_diff_label(last_candle['sma24_diff_1h'])
|
||||
#
|
||||
# val = self.approx_val_from_bins(matrice=self.smooth_smadiff_matrice_df, row_label=sma24_diff_label, col_label=mid_smooth_label)
|
||||
# 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): #last_candle['min_max200'] / 3):
|
||||
@@ -563,6 +500,7 @@ class Zeus_8_3_2_B_4_2(IStrategy):
|
||||
dataframe['haclose'] = heikinashi['close']
|
||||
dataframe['hapercent'] = (dataframe['haclose'] - dataframe['haopen']) / dataframe['haclose']
|
||||
|
||||
dataframe['pct_change'] = dataframe['close'].pct_change(5)
|
||||
dataframe = self.calculateTendency(dataframe)
|
||||
|
||||
dataframe['min'] = talib.MIN(dataframe['close'], timeperiod=200)
|
||||
@@ -714,10 +652,6 @@ class Zeus_8_3_2_B_4_2(IStrategy):
|
||||
# dataframe['amount'] = amount
|
||||
print(f"amount= {amount}")
|
||||
|
||||
dataframe['percent_with_previous_day'] = 100 * (dataframe['close'] - dataframe['close_1d']) / dataframe['close']
|
||||
dataframe['percent_with_max_hour'] = 100 * (dataframe['close'] - dataframe['max12_1h']) / dataframe['close']
|
||||
|
||||
|
||||
dataframe['futur_percent_1h'] = 100 * (dataframe['close'].shift(-12) - dataframe['close']) / dataframe['close']
|
||||
dataframe['futur_percent_3h'] = 100 * (dataframe['close'].shift(-36) - dataframe['close']) / dataframe['close']
|
||||
dataframe['futur_percent_5h'] = 100 * (dataframe['close'].shift(-60) - dataframe['close']) / dataframe['close']
|
||||
@@ -773,8 +707,10 @@ class Zeus_8_3_2_B_4_2(IStrategy):
|
||||
(
|
||||
(dataframe['max200_diff'] >= 0.01)
|
||||
& (dataframe['percent12'] < -0.002)
|
||||
# & (dataframe['pct_change'] < 0)
|
||||
& (dataframe['open'] < dataframe['average_line_288_099'])
|
||||
& (dataframe['open'] < dataframe['average_line_50'])
|
||||
# & (dataframe['percent'] >= -0.0005)
|
||||
& (dataframe['min12'].shift(2) == dataframe['min12'])
|
||||
& (dataframe['up_count'] > 0)
|
||||
& (dataframe["bb_width"] > 0.01)
|
||||
@@ -819,16 +755,14 @@ class Zeus_8_3_2_B_4_2(IStrategy):
|
||||
# pd.set_option('display.max_columns', None)
|
||||
|
||||
# Colonnes à traiter
|
||||
# futur_cols = ['futur_percent_1h', 'futur_percent_3h', 'futur_percent_5h', 'futur_percent_12h']
|
||||
futur_cols = ['futur_percent_3h']
|
||||
futur_cols = ['futur_percent_1h', 'futur_percent_3h', 'futur_percent_5h', 'futur_percent_12h']
|
||||
|
||||
# Tranches équitables par quantiles
|
||||
# Exemple pour 10 quantiles
|
||||
labels = ['B5', 'B4', 'B3', 'B2', 'B1', 'N0', 'H1', 'H2', 'H3', 'H4', 'H5']
|
||||
|
||||
indic_1 = 'mid_smooth_deriv1_1h'
|
||||
# indic_2 = 'sma24_diff_1h'
|
||||
indic_2 = 'percent_with_max_hour'
|
||||
indic_2 = 'sma24_diff_1h'
|
||||
|
||||
df[f"{indic_1}_bin"], bins_1h = pd.qcut(df[f"{indic_1}"], q=11, labels=labels, retbins=True, duplicates='drop')
|
||||
df[f"{indic_2}_bin"], bins_1d = pd.qcut(df[f"{indic_2}"], q=11, labels=labels, retbins=True, duplicates='drop')
|
||||
@@ -836,9 +770,9 @@ class Zeus_8_3_2_B_4_2(IStrategy):
|
||||
pd.set_option('display.max_columns', None)
|
||||
pd.set_option('display.width', 300) # largeur max affichage
|
||||
|
||||
# Affichage formaté pour code Python
|
||||
print(f"Bornes des quantiles pour {indic_1} : [{', '.join([f'{b:.4f}' for b in bins_1h])}]")
|
||||
print(f"Bornes des quantiles pour {indic_2} : [{', '.join([f'{b:.4f}' for b in bins_1d])}]")
|
||||
# Afficher les bornes
|
||||
print(f"Bornes des quantiles pour {indic_1} :", bins_1h)
|
||||
print(f"Bornes des quantiles pour {indic_2} :", bins_1d)
|
||||
|
||||
# Agrégation
|
||||
grouped = df.groupby([f"{indic_2}_bin", f"{indic_1}_bin"], observed=True)[futur_cols].agg(['mean', 'count'])
|
||||
@@ -859,16 +793,6 @@ class Zeus_8_3_2_B_4_2(IStrategy):
|
||||
with pd.option_context('display.max_rows', None, 'display.max_columns', None):
|
||||
print((proba_up * 100).round(1))
|
||||
|
||||
# Affichage formaté des valeurs comme tableau Python
|
||||
with pd.option_context('display.max_rows', None, 'display.max_columns', None):
|
||||
df_formatted = (proba_up * 100).round(1)
|
||||
|
||||
print("data = {")
|
||||
for index, row in df_formatted.iterrows():
|
||||
row_values = ", ".join([f"{val:.1f}" for val in row])
|
||||
print(f"'{index}': [{row_values}], ")
|
||||
print("}")
|
||||
|
||||
return dataframe
|
||||
|
||||
def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||
@@ -916,6 +840,17 @@ class Zeus_8_3_2_B_4_2(IStrategy):
|
||||
return None
|
||||
|
||||
count_of_buys = trade.nr_of_successful_entries
|
||||
|
||||
# if (days_since_first_buy >= 5 and count_of_buys >= 4 and last_candle['sma5_pct_1d'] < 0):
|
||||
# # print(f"waiting day increase pair {pair}")
|
||||
# return None
|
||||
|
||||
# if 'buy' in last_candle:
|
||||
# condition = (last_candle['buy'] == 1)
|
||||
# else:
|
||||
# condition = False
|
||||
# self.protection_nb_buy_lost.value
|
||||
|
||||
current_time_utc = current_time.astimezone(timezone.utc)
|
||||
open_date = trade.open_date.astimezone(timezone.utc)
|
||||
days_since_open = (current_time_utc - open_date).days
|
||||
@@ -938,7 +873,7 @@ class Zeus_8_3_2_B_4_2(IStrategy):
|
||||
mid_smooth_label = self.get_mid_smooth_label(last_candle['mid_smooth_deriv1_1h']) # ex. 'B2'
|
||||
sma24_diff_label = self.get_sma24_diff_label(last_candle['sma24_diff_1h'])
|
||||
|
||||
val = self.approx_val_from_bins(matrice=self.smooth_smadiff_matrice_df, row_label=sma24_diff_label, col_label=mid_smooth_label)
|
||||
val = self.approx_val_from_bins(row_label=sma24_diff_label, col_label=mid_smooth_label)
|
||||
# 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):
|
||||
@@ -1005,14 +940,6 @@ class Zeus_8_3_2_B_4_2(IStrategy):
|
||||
# Calculer le minimum des 14 derniers jours
|
||||
base_stake_amount = self.config.get('stake_amount', 100) # Montant de base configuré
|
||||
|
||||
# if (self.pairs[pair]['count_of_buys'] == 0):
|
||||
# mid_smooth_label = self.get_mid_smooth_label(last_candle['mid_smooth_deriv1_1h']) # ex. 'B2'
|
||||
# percent_with_max_hour = self.get_sma24_diff_label(last_candle['percent_with_max_hour'])
|
||||
#
|
||||
# val = self.approx_val_from_bins(matrice=self.smooth_pct_max_hour_matrice_df, row_label=percent_with_max_hour, col_label=mid_smooth_label)
|
||||
#
|
||||
# base_stake_amount = base_stake_amount * (1 + val / 500)
|
||||
|
||||
first_price = self.pairs[pair]['first_buy']
|
||||
if (first_price == 0):
|
||||
first_price = last_candle['close']
|
||||
@@ -1140,6 +1067,9 @@ class Zeus_8_3_2_B_4_2(IStrategy):
|
||||
return labels[i]
|
||||
return labels[-1]
|
||||
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
|
||||
def interpolated_val_from_bins(self, row_pos, col_pos):
|
||||
"""
|
||||
Renvoie une approximation interpolée (bilinéaire) d'une valeur dans la matrice
|
||||
@@ -1163,7 +1093,7 @@ class Zeus_8_3_2_B_4_2(IStrategy):
|
||||
return np.nan
|
||||
|
||||
# Conversion des labels -> matrice
|
||||
matrix = self.smooth_smadiff_matrice_df.reindex(index=labels, columns=labels).values
|
||||
matrix = self.matrix_df.reindex(index=labels, columns=labels).values
|
||||
|
||||
# Coordonnées entières (inférieures)
|
||||
i = int(np.floor(row_pos))
|
||||
@@ -1192,7 +1122,7 @@ class Zeus_8_3_2_B_4_2(IStrategy):
|
||||
)
|
||||
return interpolated
|
||||
|
||||
def approx_val_from_bins(self, matrice, row_label, col_label):
|
||||
def approx_val_from_bins(self, row_label, col_label):
|
||||
"""
|
||||
Renvoie une approximation de la valeur à partir des labels binaires (e.g. B5, H1)
|
||||
en utilisant une interpolation simple basée sur les indices.
|
||||
@@ -1207,15 +1137,22 @@ class Zeus_8_3_2_B_4_2(IStrategy):
|
||||
"""
|
||||
|
||||
# Vérification des labels
|
||||
if row_label not in matrice.index or col_label not in matrice.columns:
|
||||
if row_label not in self.matrix_df.index or col_label not in self.matrix_df.columns:
|
||||
return np.nan
|
||||
|
||||
# Récupération des labels ordonnés
|
||||
ordered_labels = ['B5', 'B4', 'B3', 'B2', 'B1', 'N0', 'H1', 'H2', 'H3', 'H4', 'H5']
|
||||
label_to_index = {label: i for i, label in enumerate(ordered_labels)}
|
||||
|
||||
# Index correspondant
|
||||
row_idx = self.label_to_index.get(row_label)
|
||||
col_idx = self.label_to_index.get(col_label)
|
||||
row_idx = label_to_index.get(row_label)
|
||||
col_idx = label_to_index.get(col_label)
|
||||
|
||||
# Extraction de la matrice numérique
|
||||
numeric_matrix = self.matrix_df.reindex(index=ordered_labels, columns=ordered_labels).values
|
||||
|
||||
# Approximation directe (aucune interpolation complexe ici, juste une lecture)
|
||||
return self.smooth_smadiff_numeric_matrice[row_idx, col_idx]
|
||||
return numeric_matrix[row_idx, col_idx]
|
||||
|
||||
|
||||
# @property
|
||||
|
||||
Reference in New Issue
Block a user