Intégration fonctions polynomiales

This commit is contained in:
Jérôme Delacotte
2025-05-04 17:19:44 +02:00
parent d2378b0b63
commit d9f6d160f6
3 changed files with 191 additions and 0 deletions

View File

@@ -506,6 +506,7 @@ class Zeus_8_3_2_B_4_2(IStrategy):
################### INFORMATIVE 1h
informative = self.dp.get_pair_dataframe(pair=metadata['pair'], timeframe="1h")
informative = self.calculateTendency(informative, 3)
informative = self.apply_regression_derivatives(informative, column='mid', window=50, degree=3)
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['rsi'] = talib.RSI(informative['close'], length=7)
@@ -514,12 +515,14 @@ class Zeus_8_3_2_B_4_2(IStrategy):
informative['sma5'] = talib.SMA(informative, timeperiod=5)
informative['sma5_pct'] = 100 * (informative['sma5'] - informative['sma5'].shift(1)) / informative['sma5']
dataframe = merge_informative_pair(dataframe, informative, self.timeframe, "1h", ffill=True)
################### INFORMATIVE 1d
informative = self.dp.get_pair_dataframe(pair=metadata['pair'], timeframe="1d")
informative = self.calculateTendency(informative, 3)
informative = self.apply_regression_derivatives(informative, column='mid', window=50, degree=3)
informative['rsi'] = talib.RSI(informative['close'], length=7)
informative['rsi_diff'] = informative['rsi'].diff()
informative['rsi_diff_2'] = informative['rsi_diff'].diff()
@@ -546,6 +549,8 @@ class Zeus_8_3_2_B_4_2(IStrategy):
informative['mid_min_max'] = min_14_days + (max_14_days - min_14_days) / 2
informative['middle'] = informative['lowest_4'] + (informative['highest_4'] - informative['lowest_4']) / 2
informative['mid_min_max_0.98'] = informative['mid_min_max'] * 0.98
dataframe = merge_informative_pair(dataframe, informative, self.timeframe, "1d", ffill=True)
dataframe['count_buys'] = 0
@@ -1391,3 +1396,38 @@ class Zeus_8_3_2_B_4_2(IStrategy):
down_pct_values[i] = 100 * (dataframe['close'].iloc[i] - dataframe['close'].iloc[i - shift_value]) / \
dataframe['close'].iloc[i - shift_value]
return down_pct_values
def apply_regression_derivatives(self, dataframe: DataFrame, column: str = 'close', window: int = 50, degree: int = 3):
df = dataframe.copy()
deriv1 = []
deriv2 = []
for i in range(len(df)):
if i < window:
deriv1.append(np.nan)
deriv2.append(np.nan)
continue
y = df[column].iloc[i - window:i].values
x = np.arange(window)
# Régression polynomiale
coeffs = np.polyfit(x, y, degree)
poly = np.poly1d(coeffs)
# Dérivées
d1 = np.polyder(poly, 1) # première dérivée
d2 = np.polyder(poly, 2) # seconde dérivée
# On calcule les valeurs de la dérivée à la dernière bougie
val_d1 = d1(window - 1)
val_d2 = d2(window - 1)
deriv1.append(val_d1)
deriv2.append(val_d2)
df['regression_deriv1'] = deriv1
df['regression_deriv2'] = deriv2
return df