Commit intermédiaire
This commit is contained in:
@@ -145,12 +145,6 @@ class Zeus_8_3_2_B_4_2(IStrategy):
|
|||||||
# }
|
# }
|
||||||
# },
|
# },
|
||||||
"smooth": {
|
"smooth": {
|
||||||
'sma5_diff_sum_1h': {
|
|
||||||
"color": "green"
|
|
||||||
},
|
|
||||||
'sma5_diff2_sum_1h': {
|
|
||||||
"color": "blue"
|
|
||||||
},
|
|
||||||
'mid_smooth_deriv1_1d': {
|
'mid_smooth_deriv1_1d': {
|
||||||
"color": "blue"
|
"color": "blue"
|
||||||
},
|
},
|
||||||
@@ -223,8 +217,23 @@ class Zeus_8_3_2_B_4_2(IStrategy):
|
|||||||
# H3 25.7 29.4 22.7 29.8 37.7 47.1 59.9 68.5 66.5 68.6 66.4
|
# 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
|
# 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
|
# H5 14.8 21.6 22.2 35.3 19.3 31.6 38.3 59.6 65.2 56.8 59.6
|
||||||
|
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']
|
||||||
|
label_to_index = {label: i for i, label in enumerate(ordered_labels)}
|
||||||
|
|
||||||
# Données sous forme de dictionnaire
|
# Données sous forme de dictionnaire
|
||||||
|
# Bornes des quantiles pour
|
||||||
|
mid_smooth_deriv1_144_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]
|
||||||
|
|
||||||
|
# Bornes des quantiles pour
|
||||||
|
mid_smooth_deriv2_144_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]
|
||||||
|
|
||||||
|
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,
|
||||||
|
0.01411933, 0.03308264, 0.05661652, 0.09362708, 0.14898214, 0.50579505]
|
||||||
smooth_smadiff_matrice = {
|
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],
|
"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],
|
"B4": [47.2, 35.8, 39.7, 27.9, 26.5, 19.9, 28.7, 20.8, 29.4, 27.5, 21.6],
|
||||||
@@ -238,12 +247,7 @@ class Zeus_8_3_2_B_4_2(IStrategy):
|
|||||||
"H4": [72.1, 83.0, 86.6, 73.6, 77.4, 63.0, 69.6, 67.5, 68.6, 68.6, 56.8],
|
"H4": [72.1, 83.0, 86.6, 73.6, 77.4, 63.0, 69.6, 67.5, 68.6, 68.6, 56.8],
|
||||||
"H5": [81.0, 78.5, 76.6, 81.9, 69.5, 75.0, 80.9, 62.9, 66.4, 63.7, 59.6]
|
"H5": [81.0, 78.5, 76.6, 81.9, 69.5, 75.0, 80.9, 62.9, 66.4, 63.7, 59.6]
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
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
|
# Extraction de la matrice numérique
|
||||||
smooth_smadiff_numeric_matrice = smooth_smadiff_matrice_df.reindex(index=ordered_labels, columns=ordered_labels).values
|
smooth_smadiff_numeric_matrice = smooth_smadiff_matrice_df.reindex(index=ordered_labels, columns=ordered_labels).values
|
||||||
|
|
||||||
@@ -262,13 +266,9 @@ class Zeus_8_3_2_B_4_2(IStrategy):
|
|||||||
}
|
}
|
||||||
|
|
||||||
smooth_pct_max_hour_matrice_df = pd.DataFrame(smooth_pct_max_hour_matrice, index=index_labels)
|
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
|
# Extraction de la matrice numérique
|
||||||
smooth_pct_max_hour_numeric_matrice = smooth_pct_max_hour_matrice_df.reindex(index=ordered_labels, columns=ordered_labels).values
|
smooth_pct_max_hour_numeric_matrice = smooth_pct_max_hour_matrice_df.reindex(index=ordered_labels, columns=ordered_labels).values
|
||||||
|
|
||||||
|
|
||||||
# Données sous forme de dictionnaire
|
# Données sous forme de dictionnaire
|
||||||
smooth_sma_144_diff_matrice = {
|
smooth_sma_144_diff_matrice = {
|
||||||
"B5":[40.3, 52.1, 60.2, 68.6, 86.3, 76.5, 75.1, 83.5, 88.7, 96.3, 91.6],
|
"B5":[40.3, 52.1, 60.2, 68.6, 86.3, 76.5, 75.1, 83.5, 88.7, 96.3, 91.6],
|
||||||
@@ -288,6 +288,14 @@ class Zeus_8_3_2_B_4_2(IStrategy):
|
|||||||
# Extraction de la matrice numérique
|
# Extraction de la matrice numérique
|
||||||
smooth_sma_144_diff_numeric_matrice = smooth_sma_144_diff_matrice_df.reindex(index=ordered_labels, columns=ordered_labels).values
|
smooth_sma_144_diff_numeric_matrice = smooth_sma_144_diff_matrice_df.reindex(index=ordered_labels, columns=ordered_labels).values
|
||||||
|
|
||||||
|
# Bornes des quantiles pour
|
||||||
|
mid_smooth_deriv1_1h = [-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
|
||||||
|
mid_smooth_deriv2_1h = [-6.2109, -0.2093, -0.0900, -0.0416, -0.0171, -0.0035, 0.0033, 0.0168, 0.0413, 0.0904, 0.2099, 6.2109]
|
||||||
|
|
||||||
|
buy_val = IntParameter(1, 10, default=50, space='buy')
|
||||||
|
buy_val_adjust = IntParameter(1, 10, default=50, space='buy')
|
||||||
|
|
||||||
def confirm_trade_entry(self, pair: str, order_type: str, amount: float, rate: float, time_in_force: str,
|
def confirm_trade_entry(self, pair: str, order_type: str, amount: float, rate: float, time_in_force: str,
|
||||||
current_time: datetime, entry_tag: Optional[str], **kwargs) -> bool:
|
current_time: datetime, entry_tag: Optional[str], **kwargs) -> bool:
|
||||||
|
|
||||||
@@ -299,15 +307,10 @@ class Zeus_8_3_2_B_4_2(IStrategy):
|
|||||||
last_candle = dataframe.iloc[-1].squeeze()
|
last_candle = dataframe.iloc[-1].squeeze()
|
||||||
last_candle_2 = dataframe.iloc[-2].squeeze()
|
last_candle_2 = dataframe.iloc[-2].squeeze()
|
||||||
last_candle_3 = dataframe.iloc[-3].squeeze()
|
last_candle_3 = dataframe.iloc[-3].squeeze()
|
||||||
# last_candle_12 = dataframe.iloc[-13].squeeze()
|
|
||||||
# if (last_candle['close'] < self.pairs[pair]['last_sell'] * 0.99 or minutes > 60 * 5) & (self.pairs[pair]['stop']):
|
|
||||||
# print(f"restart {pair} last_sell={self.pairs[pair]['last_sell'] * 0.99} minutes={minutes}")
|
|
||||||
# self.pairs[pair]['stop'] = False
|
|
||||||
|
|
||||||
val = self.getProbaHausse144(last_candle)
|
val = self.getProbaHausse144(last_candle)
|
||||||
|
|
||||||
# allow_to_buy = True #(not self.stop_all) #& (not self.all_down)
|
# 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')
|
allow_to_buy = not self.pairs[pair]['stop'] and val > self.buy_val.value #not last_candle['tendency'] in ('B-', 'B--') # (rate <= float(limit)) | (entry_tag == 'force_entry')
|
||||||
|
|
||||||
if allow_to_buy:
|
if allow_to_buy:
|
||||||
self.trades = list()
|
self.trades = list()
|
||||||
@@ -412,6 +415,12 @@ class Zeus_8_3_2_B_4_2(IStrategy):
|
|||||||
if (last_candle['tendency'] in ('H++', 'H+')) and (last_candle['rsi'] < 80):
|
if (last_candle['tendency'] in ('H++', 'H+')) and (last_candle['rsi'] < 80):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
# val144 = self.getProbaHausse144(last_candle)
|
||||||
|
# val1h = self.getProbaHausse1h(last_candle)
|
||||||
|
#
|
||||||
|
# if (val144 * val1h > 3600) :
|
||||||
|
# return None
|
||||||
|
|
||||||
# val = self.getProbaHausse144(last_candle)
|
# val = self.getProbaHausse144(last_candle)
|
||||||
# if val > 50:
|
# if val > 50:
|
||||||
# return None
|
# return None
|
||||||
@@ -466,14 +475,14 @@ class Zeus_8_3_2_B_4_2(IStrategy):
|
|||||||
# Afficher les colonnes une seule fois
|
# Afficher les colonnes une seule fois
|
||||||
if self.config.get('runmode') == 'hyperopt':
|
if self.config.get('runmode') == 'hyperopt':
|
||||||
return
|
return
|
||||||
if self.columns_logged % 30 == 0:
|
if self.columns_logged > 30 == 0:
|
||||||
self.printLog(
|
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':>4}| {'Stake':>5} |"
|
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':>4}| {'Stake':>5} |"
|
||||||
f"sum_1h|sum_1d|Tdc|Tdh|Tdd| drv1 |drv_1h|drv_1d|"
|
f"Tdc|Tdh|Tdd| drv1 |drv_1h|drv_1d| drv2 |drv_2h|drv_2d|val144|val1h |"
|
||||||
)
|
)
|
||||||
self.printLineLog()
|
self.printLineLog()
|
||||||
|
|
||||||
self.columns_logged += 1
|
self.columns_logged += 1
|
||||||
date = str(date)[:16] if date else "-"
|
date = str(date)[:16] if date else "-"
|
||||||
limit = None
|
limit = None
|
||||||
# if buys is not None:
|
# if buys is not None:
|
||||||
@@ -511,21 +520,24 @@ class Zeus_8_3_2_B_4_2(IStrategy):
|
|||||||
+ " " + str(int(last_candle['rsi_1h'])) \
|
+ " " + str(int(last_candle['rsi_1h'])) \
|
||||||
+ " " + str(int(last_candle['rsi_diff_1h']))
|
+ " " + str(int(last_candle['rsi_diff_1h']))
|
||||||
|
|
||||||
|
val144 = self.getProbaHausse144(last_candle)
|
||||||
|
val1h = self.getProbaHausse1h(last_candle)
|
||||||
|
|
||||||
self.printLog(
|
self.printLog(
|
||||||
f"| {date:<16} | {action:<10} | {pair[0:3]:<3} | {trade_type or '-':<18} |{rate or '-':>9}| {dispo or '-':>6} "
|
f"| {date:<16} | {action:<10} | {pair[0:3]:<3} | {trade_type or '-':<18} |{rate or '-':>9}| {dispo or '-':>6} "
|
||||||
f"| {profit or '-':>8} | {pct_max or '-':>6} | {round(self.pairs[pair]['max_touch'], 2) or '-':>11} | {last_lost or '-':>12} "
|
f"| {profit or '-':>8} | {pct_max or '-':>6} | {round(self.pairs[pair]['max_touch'], 2) or '-':>11} | {last_lost or '-':>12} "
|
||||||
f"| {round(self.pairs[pair]['last_max'], 0) or '-':>7} |{buys or '-':>4}|{stake or '-':>7}"
|
f"| {round(self.pairs[pair]['last_max'], 0) or '-':>7} |{buys or '-':>4}|{stake or '-':>7}"
|
||||||
f"|{round(last_candle['sma5_diff_sum_1h'], 2) or '-':>6}|{round(last_candle['sma5_diff_sum_1d'], 2) or '-':>6}"
|
|
||||||
f"|{last_candle['tendency'] or '-':>3}|{last_candle['tendency_1h'] or '-':>3}|{last_candle['tendency_1d'] or '-':>3}"
|
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_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']) or '-' :>3 }|{round(last_candle['mid_smooth_deriv2_1h']) or '-':>5}|{round(last_candle['mid_smooth_deriv2_1d']) or '-':>5}"
|
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(val144, 1) or '-' :>6}|{round(val1h, 1) or '-':>6}|"
|
||||||
)
|
)
|
||||||
|
|
||||||
def printLineLog(self):
|
def printLineLog(self):
|
||||||
# f"sum1h|sum1d|Tdc|Tdh|Tdd| drv1 |drv_1h|drv_1d|"
|
# f"sum1h|sum1d|Tdc|Tdh|Tdd| drv1 |drv_1h|drv_1d|"
|
||||||
self.printLog(
|
self.printLog(
|
||||||
f"+{'-' * 18}+{'-' * 12}+{'-' * 5}+{'-' * 20}+{'-' * 9}+{'-' * 8}+{'-' * 10}+{'-' * 8}+{'-' * 13}+{'-' * 14}+{'-' * 9}+{'-' * 4}+{'-' * 7}+"
|
f"+{'-' * 18}+{'-' * 12}+{'-' * 5}+{'-' * 20}+{'-' * 9}+{'-' * 8}+{'-' * 10}+{'-' * 8}+{'-' * 13}+{'-' * 14}+{'-' * 9}+{'-' * 4}+{'-' * 7}+"
|
||||||
f"{'-' * 6}+{'-' * 6}+{'-' * 3}+{'-' * 3}+{'-' * 3}+{'-' * 6}+{'-' * 6}+{'-' * 6}+"
|
f"{'-' * 3}+{'-' * 3}+{'-' * 3}+{'-' * 6}+{'-' * 6}+{'-' * 6}+"
|
||||||
)
|
)
|
||||||
|
|
||||||
def printLog(self, str):
|
def printLog(self, str):
|
||||||
@@ -617,7 +629,7 @@ class Zeus_8_3_2_B_4_2(IStrategy):
|
|||||||
# Compter les baisses consécutives
|
# Compter les baisses consécutives
|
||||||
self.calculateDownAndUp(dataframe, limit=0.0001)
|
self.calculateDownAndUp(dataframe, limit=0.0001)
|
||||||
|
|
||||||
dataframe = self.apply_regression_derivatives(dataframe, column='mid_smooth_144', window=144, degree=3, future_offset=12)
|
dataframe = self.calculateRegression(dataframe, column='mid_smooth_144', window=144, degree=3, future_offset=12)
|
||||||
|
|
||||||
################### INFORMATIVE 1h
|
################### INFORMATIVE 1h
|
||||||
informative = self.dp.get_pair_dataframe(pair=metadata['pair'], timeframe="1h")
|
informative = self.dp.get_pair_dataframe(pair=metadata['pair'], timeframe="1h")
|
||||||
@@ -626,7 +638,7 @@ class Zeus_8_3_2_B_4_2(IStrategy):
|
|||||||
informative['haclose'] = heikinashi['close']
|
informative['haclose'] = heikinashi['close']
|
||||||
informative['hapercent'] = (informative['haclose'] - informative['haopen']) / informative['haclose']
|
informative['hapercent'] = (informative['haclose'] - informative['haopen']) / informative['haclose']
|
||||||
|
|
||||||
informative = self.calculateTendency(informative, 12)
|
informative = self.calculateTendency(informative, window=12)
|
||||||
# informative = self.apply_regression_derivatives(informative, column='mid', window=5, degree=3)
|
# informative = self.apply_regression_derivatives(informative, column='mid', window=5, degree=3)
|
||||||
# informative['volatility'] = talib.STDDEV(informative['close'], timeperiod=14) / informative['close']
|
# informative['volatility'] = talib.STDDEV(informative['close'], timeperiod=14) / informative['close']
|
||||||
# informative['atr'] = (talib.ATR(informative['high'], informative['low'], informative['close'], timeperiod=14)) / informative['close']
|
# informative['atr'] = (talib.ATR(informative['high'], informative['low'], informative['close'], timeperiod=14)) / informative['close']
|
||||||
@@ -641,10 +653,7 @@ class Zeus_8_3_2_B_4_2(IStrategy):
|
|||||||
informative['sma5'] = talib.SMA(informative, timeperiod=5)
|
informative['sma5'] = talib.SMA(informative, timeperiod=5)
|
||||||
informative['sma5_diff'] = 100 * informative['sma5'].diff() / informative['sma5']
|
informative['sma5_diff'] = 100 * informative['sma5'].diff() / informative['sma5']
|
||||||
informative['sma24'] = talib.SMA(informative, timeperiod=24)
|
informative['sma24'] = talib.SMA(informative, timeperiod=24)
|
||||||
informative['sma24_diff'] = 100 * informative['sma24'].diff() / informative['sma24']
|
informative['sma24_diff'] = 100 * informative['sma24'].rolling(7).mean().diff() / informative['sma24']
|
||||||
informative['sma5_pct'] = 100 * (informative['sma5'] - informative['sma5'].shift(1)) / informative['sma5']
|
|
||||||
informative['sma5_diff_sum'] = (informative['sma5_pct'].rolling(5).sum()) / 5
|
|
||||||
informative['sma5_diff2_sum'] = informative['sma5_diff_sum'].diff()
|
|
||||||
|
|
||||||
self.calculateDownAndUp(informative, limit=0.0012)
|
self.calculateDownAndUp(informative, limit=0.0012)
|
||||||
|
|
||||||
@@ -652,7 +661,7 @@ class Zeus_8_3_2_B_4_2(IStrategy):
|
|||||||
|
|
||||||
################### INFORMATIVE 1d
|
################### INFORMATIVE 1d
|
||||||
informative = self.dp.get_pair_dataframe(pair=metadata['pair'], timeframe="1d")
|
informative = self.dp.get_pair_dataframe(pair=metadata['pair'], timeframe="1d")
|
||||||
informative = self.calculateTendency(informative, 7)
|
informative = self.calculateTendency(informative, window=7)
|
||||||
# informative['volatility'] = talib.STDDEV(informative['close'], timeperiod=14) / informative['close']
|
# informative['volatility'] = talib.STDDEV(informative['close'], timeperiod=14) / informative['close']
|
||||||
# informative['atr'] = (talib.ATR(informative['high'], informative['low'], informative['close'], timeperiod=14)) / informative['close']
|
# informative['atr'] = (talib.ATR(informative['high'], informative['low'], informative['close'], timeperiod=14)) / informative['close']
|
||||||
|
|
||||||
@@ -668,9 +677,10 @@ class Zeus_8_3_2_B_4_2(IStrategy):
|
|||||||
informative['rsi_diff_2'] = informative['rsi_diff'].diff()
|
informative['rsi_diff_2'] = informative['rsi_diff'].diff()
|
||||||
|
|
||||||
informative['sma5'] = talib.SMA(informative, timeperiod=5)
|
informative['sma5'] = talib.SMA(informative, timeperiod=5)
|
||||||
informative['sma5_pct'] = 100 * (informative['sma5'] - informative['sma5'].shift(1)) / informative['sma5']
|
informative['sma5_diff'] = 100 * (informative['sma5'].rolling(5).mean().diff()) / informative['sma5']
|
||||||
informative['sma5_diff_sum'] = (informative['sma5_pct'].rolling(5).sum()) / 5
|
|
||||||
informative['sma5_diff2_sum'] = informative['sma5_diff_sum'].diff()
|
informative['futur_percent_1d'] = 100 * (informative['close'].shift(-1) - informative['close']) / informative['close']
|
||||||
|
informative['futur_percent_3d'] = 100 * (informative['close'].shift(-3) - informative['close']) / informative['close']
|
||||||
|
|
||||||
dataframe = merge_informative_pair(dataframe, informative, self.timeframe, "1d", ffill=True)
|
dataframe = merge_informative_pair(dataframe, informative, self.timeframe, "1d", ffill=True)
|
||||||
|
|
||||||
@@ -713,6 +723,15 @@ class Zeus_8_3_2_B_4_2(IStrategy):
|
|||||||
dataframe["mid_smooth_deriv1_1h"] = dataframe["mid_smooth_1h"].rolling(12).mean().diff() / 12
|
dataframe["mid_smooth_deriv1_1h"] = dataframe["mid_smooth_1h"].rolling(12).mean().diff() / 12
|
||||||
dataframe["mid_smooth_deriv2_1h"] = 12 * dataframe["mid_smooth_deriv1_1h"].rolling(12).mean().diff()
|
dataframe["mid_smooth_deriv2_1h"] = 12 * dataframe["mid_smooth_deriv1_1h"].rolling(12).mean().diff()
|
||||||
|
|
||||||
|
dataframe['sma5_1h'] = dataframe['sma5_1h'].rolling(window=12, center=True).mean()
|
||||||
|
dataframe['sma5_diff_1h'] = dataframe['sma5_diff_1h'].rolling(window=12, center=True).mean()
|
||||||
|
dataframe['sma24_1h'] = dataframe['sma24_1h'].rolling(window=12, center=True).mean()
|
||||||
|
dataframe['sma24_diff_1h'] = dataframe['sma24_diff_1h'].rolling(window=12, center=True).mean()
|
||||||
|
|
||||||
|
# dataframe['sma5_1d'] = dataframe['sma5_1d'].interpolate(method='linear')
|
||||||
|
|
||||||
|
# dataframe['sma5_1d'] = dataframe['sma5_1d'].interpolate(method='linear')
|
||||||
|
|
||||||
dataframe['percent_with_previous_day'] = 100 * (dataframe['close'] - dataframe['close_1d']) / dataframe['close']
|
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['percent_with_max_hour'] = 100 * (dataframe['close'] - dataframe['max12_1h']) / dataframe['close']
|
||||||
|
|
||||||
@@ -741,6 +760,7 @@ class Zeus_8_3_2_B_4_2(IStrategy):
|
|||||||
int(window / 4)).mean()
|
int(window / 4)).mean()
|
||||||
# 2. Dérivée première = différence entre deux bougies successives
|
# 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}"].diff() / dataframe[f"mid_smooth{suffixe}"], 4)
|
||||||
|
|
||||||
# 3. Dérivée seconde = différence de la dérivée première
|
# 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(int(window / 4)).mean().diff(), 4)
|
||||||
dataframe = self.add_tendency_column(dataframe, suffixe)
|
dataframe = self.add_tendency_column(dataframe, suffixe)
|
||||||
@@ -815,62 +835,66 @@ class Zeus_8_3_2_B_4_2(IStrategy):
|
|||||||
#
|
#
|
||||||
# pd.set_option('display.width', 200) # largeur max affichage
|
# pd.set_option('display.width', 200) # largeur max affichage
|
||||||
# pd.set_option('display.max_columns', None)
|
# 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']
|
|
||||||
|
|
||||||
# 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_1 = 'mid_smooth_deriv1_144'
|
|
||||||
indic_2 = 'mid_smooth_deriv2_144'
|
|
||||||
|
|
||||||
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')
|
|
||||||
|
|
||||||
pd.set_option('display.max_columns', None)
|
pd.set_option('display.max_columns', None)
|
||||||
pd.set_option('display.width', 300) # largeur max affichage
|
pd.set_option('display.width', 300) # largeur max affichage
|
||||||
|
|
||||||
# Affichage formaté pour code Python
|
# Colonnes à traiter
|
||||||
print(f"Bornes des quantiles pour {indic_1} : [{', '.join([f'{b:.4f}' for b in bins_1h])}]")
|
# futur_cols = ['futur_percent_1h', 'futur_percent_3h', 'futur_percent_5h', 'futur_percent_12h']
|
||||||
print(f"Bornes des quantiles pour {indic_2} : [{', '.join([f'{b:.4f}' for b in bins_1d])}]")
|
futur_cols = ['futur_percent_1h']
|
||||||
|
|
||||||
# Agrégation
|
# Tranches équitables par quantiles
|
||||||
grouped = df.groupby([f"{indic_2}_bin", f"{indic_1}_bin"], observed=True)[futur_cols].agg(['mean', 'count'])
|
|
||||||
|
|
||||||
# Affichage
|
indic_1 = 'mid_smooth_deriv1_1h'
|
||||||
|
indic_2 = 'sma24_diff_1h'
|
||||||
|
#indic_2 = 'percent_with_max_hour'
|
||||||
|
# indic_1 = 'mid_smooth_deriv1_1h'
|
||||||
|
# indic_2 = 'sma5_diff_1d'
|
||||||
|
|
||||||
with pd.option_context('display.max_rows', None, 'display.max_columns', None):
|
self.calculateProbabilite2Index(df, futur_cols, indic_1, indic_2)
|
||||||
print(grouped.round(4))
|
|
||||||
|
|
||||||
# Ajout des probabilités de hausse
|
|
||||||
for col in futur_cols:
|
|
||||||
df[f"{col}_is_up"] = df[col] > 0
|
|
||||||
|
|
||||||
# Calcul de la proba de hausse
|
|
||||||
proba_up = df.groupby([f"{indic_2}_bin", f"{indic_1}_bin"], observed=True)[f"{col}_is_up"].mean().unstack()
|
|
||||||
|
|
||||||
print(f"\nProbabilité de hausse pour {col} (en %):")
|
|
||||||
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
|
return dataframe
|
||||||
|
|
||||||
|
def calculateProbabilite2Index(self, df, futur_cols, indic_1, indic_2):
|
||||||
|
# nettoyage
|
||||||
|
series = df[f"{indic_2}"].dropna()
|
||||||
|
unique_vals = df[f"{indic_2}"].nunique()
|
||||||
|
# print(unique_vals)
|
||||||
|
# print(df[f"{indic_2}"])
|
||||||
|
n = len(self.labels)
|
||||||
|
|
||||||
|
df[f"{indic_1}_bin"], bins_1h = pd.qcut(df[f"{indic_1}"], q=n, labels=self.labels, retbins=True,
|
||||||
|
duplicates='drop')
|
||||||
|
df[f"{indic_2}_bin"], bins_1d = pd.qcut(df[f"{indic_2}"], q=n, labels=self.labels, retbins=True,
|
||||||
|
duplicates='drop')
|
||||||
|
# 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])}]")
|
||||||
|
# Agrégation
|
||||||
|
grouped = df.groupby([f"{indic_2}_bin", f"{indic_1}_bin"], observed=True)[futur_cols].agg(['mean', 'count'])
|
||||||
|
# Affichage
|
||||||
|
with pd.option_context('display.max_rows', None, 'display.max_columns', None):
|
||||||
|
print(grouped.round(4))
|
||||||
|
# Ajout des probabilités de hausse
|
||||||
|
for col in futur_cols:
|
||||||
|
df[f"{col}_is_up"] = df[col] > 0
|
||||||
|
|
||||||
|
# Calcul de la proba de hausse
|
||||||
|
proba_up = df.groupby([f"{indic_2}_bin", f"{indic_1}_bin"], observed=True)[f"{col}_is_up"].mean().unstack()
|
||||||
|
|
||||||
|
print(f"\nProbabilité de hausse pour {col} (en %):")
|
||||||
|
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("}")
|
||||||
|
|
||||||
def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||||
# dataframe.loc[
|
# dataframe.loc[
|
||||||
# (
|
# (
|
||||||
@@ -899,6 +923,7 @@ class Zeus_8_3_2_B_4_2(IStrategy):
|
|||||||
current_time = current_time.astimezone(timezone.utc)
|
current_time = current_time.astimezone(timezone.utc)
|
||||||
open_date = trade.open_date.astimezone(timezone.utc)
|
open_date = trade.open_date.astimezone(timezone.utc)
|
||||||
dispo = round(self.wallets.get_available_stake_amount())
|
dispo = round(self.wallets.get_available_stake_amount())
|
||||||
|
hours_since_first_buy = (current_time - trade.open_date_utc).seconds / 3600.0
|
||||||
days_since_first_buy = (current_time - trade.open_date_utc).days
|
days_since_first_buy = (current_time - trade.open_date_utc).days
|
||||||
hours = (current_time - trade.date_last_filled_utc).total_seconds() / 3600.0
|
hours = (current_time - trade.date_last_filled_utc).total_seconds() / 3600.0
|
||||||
|
|
||||||
@@ -935,14 +960,25 @@ class Zeus_8_3_2_B_4_2(IStrategy):
|
|||||||
lim = - pct - (count_of_buys * 0.001)
|
lim = - pct - (count_of_buys * 0.001)
|
||||||
# print(f"{trade.pair} current_profit={current_profit} count_of_buys={count_of_buys} pct_max={pct_max:.3f} lim={lim:.3f} rsi_diff_1f={last_candle['rsi_diff_1h']}")
|
# print(f"{trade.pair} current_profit={current_profit} count_of_buys={count_of_buys} pct_max={pct_max:.3f} lim={lim:.3f} rsi_diff_1f={last_candle['rsi_diff_1h']}")
|
||||||
|
|
||||||
val = self.getProbaHausse144(last_candle)
|
# val144 = self.getProbaHausse144(last_candle)
|
||||||
|
# val1h = self.getProbaHausse1h(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}")
|
# 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):
|
# if (days_since_open > count_of_buys) & (0 < count_of_buys <= max_buys) & (current_rate <= limit) & (last_candle['enter_long'] == 1):
|
||||||
limit_buy = 20
|
limit_buy = 20
|
||||||
if (count_of_buys < limit_buy) \
|
if (count_of_buys < limit_buy) \
|
||||||
and (last_candle['enter_long'] == 1) \
|
and (last_candle['enter_long'] == 1) \
|
||||||
and (pct_max < lim and val > 50 and last_candle['mid_smooth_deriv1_1d'] > - 1):
|
and (pct_max < lim and val > self.buy_val_adjust.value and last_candle['mid_smooth_deriv1_1d'] > - 1):
|
||||||
try:
|
try:
|
||||||
|
|
||||||
max_amount = self.config.get('stake_amount', 100) * 2.5
|
max_amount = self.config.get('stake_amount', 100) * 2.5
|
||||||
@@ -998,17 +1034,25 @@ class Zeus_8_3_2_B_4_2(IStrategy):
|
|||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def getProbaHausse144(self, last_candle, indic_1='mid_smooth_deriv1_144', indic_2='sma144_diff'):
|
def getProbaHausse144(self, last_candle):
|
||||||
value_1 = self.get_mid_smooth_label(last_candle[indic_1]) # ex. 'B2'
|
value_1 = self.getValuesFromTable(self.mid_smooth_deriv1_144_bins, last_candle['mid_smooth_deriv1_144'])
|
||||||
value_2 = self.get_sma24_diff_label(last_candle[indic_2])
|
value_2 = self.getValuesFromTable(self.sma144_diff_bins, last_candle['sma144_diff'])
|
||||||
|
|
||||||
val = self.approx_val_from_bins(matrice=self.smooth_sma_144_diff_matrice_df, numeric_matrice=self.smooth_sma_144_diff_numeric_matrice, row_label=value_2,
|
val = self.approx_val_from_bins(matrice=self.smooth_sma_144_diff_matrice_df, numeric_matrice=self.smooth_sma_144_diff_numeric_matrice, row_label=value_2,
|
||||||
col_label=value_1)
|
col_label=value_1)
|
||||||
return val
|
return val
|
||||||
|
|
||||||
def getProbaHausse(self, last_candle, indic_1='mid_smooth_deriv1_1h', indic_2='sma24_diff_1h'):
|
def getProbaHausse1h(self, last_candle):
|
||||||
value_1 = self.get_mid_smooth_label(last_candle[indic_1]) # ex. 'B2'
|
value_1 = self.getValuesFromTable(self.mid_smooth_1h_bins, last_candle['mid_smooth_deriv1_1h'])
|
||||||
value_2 = self.get_sma24_diff_label(last_candle[indic_2])
|
value_2 = self.getValuesFromTable(self.sma24_diff_1h_bins, last_candle['sma24_diff_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)
|
||||||
|
return val
|
||||||
|
|
||||||
|
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'])
|
||||||
|
|
||||||
val = self.approx_val_from_bins(matrice=self.smooth_smadiff_matrice_df, numeric_matrice=self.smooth_smadiff_numeric_matrice, row_label=value_2,
|
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)
|
col_label=value_1)
|
||||||
@@ -1018,14 +1062,6 @@ class Zeus_8_3_2_B_4_2(IStrategy):
|
|||||||
# Calculer le minimum des 14 derniers jours
|
# Calculer le minimum des 14 derniers jours
|
||||||
base_stake_amount = self.config.get('stake_amount', 100) # Montant de base configuré
|
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']
|
first_price = self.pairs[pair]['first_buy']
|
||||||
if (first_price == 0):
|
if (first_price == 0):
|
||||||
first_price = last_candle['close']
|
first_price = last_candle['close']
|
||||||
@@ -1083,7 +1119,7 @@ class Zeus_8_3_2_B_4_2(IStrategy):
|
|||||||
#
|
#
|
||||||
# Filtrer les signaux: ne prendre un signal haussier que si dérivée1 > 0 et dérivée2 > 0.
|
# Filtrer les signaux: ne prendre un signal haussier que si dérivée1 > 0 et dérivée2 > 0.
|
||||||
# Détecter les zones de retournement: quand dérivée1 ≈ 0 et que dérivée2 change de signe.
|
# Détecter les zones de retournement: quand dérivée1 ≈ 0 et que dérivée2 change de signe.
|
||||||
def apply_regression_derivatives(self,
|
def calculateRegression(self,
|
||||||
dataframe: DataFrame,
|
dataframe: DataFrame,
|
||||||
column: str = 'close',
|
column: str = 'close',
|
||||||
window: int = 50,
|
window: int = 50,
|
||||||
@@ -1136,22 +1172,11 @@ class Zeus_8_3_2_B_4_2(IStrategy):
|
|||||||
|
|
||||||
return df
|
return df
|
||||||
|
|
||||||
def get_mid_smooth_label(self, value):
|
def getValuesFromTable(self, values, value):
|
||||||
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]
|
for i in range(len(values) - 1):
|
||||||
labels = ['B5', 'B4', 'B3', 'B2', 'B1', 'N0', 'H1', 'H2', 'H3', 'H4', 'H5']
|
if values[i] <= value < values[i + 1]:
|
||||||
for i in range(len(bins) - 1):
|
return self.labels[i]
|
||||||
if bins[i] <= value < bins[i + 1]:
|
return self.labels[-1] # cas limite pour la borne max
|
||||||
return labels[i]
|
|
||||||
return labels[-1] # cas limite pour la borne max
|
|
||||||
|
|
||||||
def get_sma24_diff_label(self, value):
|
|
||||||
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]
|
|
||||||
labels = ['B5', 'B4', 'B3', 'B2', 'B1', 'N0', 'H1', 'H2', 'H3', 'H4', 'H5']
|
|
||||||
for i in range(len(bins) - 1):
|
|
||||||
if bins[i] <= value < bins[i + 1]:
|
|
||||||
return labels[i]
|
|
||||||
return labels[-1]
|
|
||||||
|
|
||||||
def interpolated_val_from_bins(self, row_pos, col_pos):
|
def interpolated_val_from_bins(self, row_pos, col_pos):
|
||||||
"""
|
"""
|
||||||
@@ -1168,15 +1193,14 @@ class Zeus_8_3_2_B_4_2(IStrategy):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# Labels ordonnés
|
# Labels ordonnés
|
||||||
labels = ['B5', 'B4', 'B3', 'B2', 'B1', 'N0', 'H1', 'H2', 'H3', 'H4', 'H5']
|
n = len(self.labels)
|
||||||
n = len(labels)
|
|
||||||
|
|
||||||
# Vérification des limites
|
# Vérification des limites
|
||||||
if not (0 <= row_pos <= n - 1) or not (0 <= col_pos <= n - 1):
|
if not (0 <= row_pos <= n - 1) or not (0 <= col_pos <= n - 1):
|
||||||
return np.nan
|
return np.nan
|
||||||
|
|
||||||
# Conversion des labels -> matrice
|
# Conversion des labels -> matrice
|
||||||
matrix = self.smooth_smadiff_matrice_df.reindex(index=labels, columns=labels).values
|
matrix = self.smooth_smadiff_matrice_df.reindex(index=self.labels, columns=self.labels).values
|
||||||
|
|
||||||
# Coordonnées entières (inférieures)
|
# Coordonnées entières (inférieures)
|
||||||
i = int(np.floor(row_pos))
|
i = int(np.floor(row_pos))
|
||||||
|
|||||||
Reference in New Issue
Block a user