Spaces:
Sleeping
Sleeping
Update ml_model.py
#1
by Nexo-S - opened
- ml_model.py +26 -1
ml_model.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
import pandas as pd
|
| 2 |
-
import pandas_ta as ta
|
| 3 |
from sklearn.ensemble import RandomForestClassifier
|
| 4 |
import joblib
|
| 5 |
import os
|
|
@@ -7,6 +6,32 @@ import os
|
|
| 7 |
# Nouveau nom pour forcer la création d'un modèle neuf
|
| 8 |
ML_MODEL_FILE = "ml_model_v9.pkl"
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
def prepare_ml_features(df):
|
| 11 |
"""
|
| 12 |
Extrait la structure du marché (Market Structure).
|
|
|
|
| 1 |
import pandas as pd
|
|
|
|
| 2 |
from sklearn.ensemble import RandomForestClassifier
|
| 3 |
import joblib
|
| 4 |
import os
|
|
|
|
| 6 |
# Nouveau nom pour forcer la création d'un modèle neuf
|
| 7 |
ML_MODEL_FILE = "ml_model_v9.pkl"
|
| 8 |
|
| 9 |
+
import pandas as pd
|
| 10 |
+
import joblib
|
| 11 |
+
import os
|
| 12 |
+
from sklearn.ensemble import RandomForestClassifier
|
| 13 |
+
|
| 14 |
+
ML_MODEL_FILE = "ml_model_v9.pkl"
|
| 15 |
+
|
| 16 |
+
# --- Fonctions Quant Natives ---
|
| 17 |
+
def get_rsi(series, period=14):
|
| 18 |
+
delta = series.diff()
|
| 19 |
+
gain = (delta.where(delta > 0, 0)).rolling(window=period).mean()
|
| 20 |
+
loss = (-delta.where(delta < 0, 0)).rolling(window=period).mean()
|
| 21 |
+
rs = gain / loss
|
| 22 |
+
return 100 - (100 / (1 + rs))
|
| 23 |
+
|
| 24 |
+
def get_ema(series, span):
|
| 25 |
+
return series.ewm(span=span, adjust=False).mean()
|
| 26 |
+
|
| 27 |
+
def get_atr(df, period=14):
|
| 28 |
+
high_low = df['high'] - df['low']
|
| 29 |
+
high_close = (df['high'] - df['close'].shift()).abs()
|
| 30 |
+
low_close = (df['low'] - df['close'].shift()).abs()
|
| 31 |
+
ranges = pd.concat([high_low, high_close, low_close], axis=1)
|
| 32 |
+
return ranges.max(axis=1).rolling(period).mean()
|
| 33 |
+
# ... (Garde le reste de tes fonctions train_model, load_model, predict_prob sans changement)
|
| 34 |
+
|
| 35 |
def prepare_ml_features(df):
|
| 36 |
"""
|
| 37 |
Extrait la structure du marché (Market Structure).
|