| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- from Model.Donnee import *
- from Model.profil import profile
- from Config.paths import SysExploite
- import datetime as dt
- import json
- import hashlib
- import os
- import uuid
- import random
- ProbabiliteMutationNombre = 0.5
- ProbabiliteMutationReste = 0.5
- class CL_Param:
- def __init__(self):
-
- self.PortefeuilleDemarage = 50000.0
- self.NBAction = NombreActionFichier()
-
- """
- L'horizon depent directement du nombre de jour de recul la regle epirique est : lookback ≈ 3× à 10× horizon
-
- | Fast | a testé | Optimal | Robuste |
- NBjourRecul | 5 | 32 jours | 64 | 100 |
- horizon | 1 | 5 jours | 10 | 15 |
-
- """
- self.NbJourRecul = 32
- self.Horizon = 5
-
- self.Analysis = ["Close","others_dr","trend_sma_fast","trend_sma_slow","momentum_rsi","volatility_atr","volatility_bbw","volume_obv"]
- self.NbAnalysis = len(self.Analysis)
- self.poidsAchat = [0.25, 0.20, 0.15, 0.10, 0.05]
- self.NBachat = len(self.poidsAchat)
- self.ValVente = 0
- if SysExploite == "windows":
- self.epochs = 2
- else :
- self.epochs = 20000
- self.batch_size = 128
-
- self.LearningRate = 1e-3
-
- # Groupes pour éviter les features corrélés
- self.groups = {
- # ---- MACD ----
- "macd": {
- "trend_macd": 5,
- "trend_macd_signal": 5,
- "trend_macd_diff": 5
- },
-
- # ---- PPO ----
- "ppo": {
- "momentum_ppo": 5,
- "momentum_ppo_signal": 5,
- "momentum_ppo_hist": 5
- },
-
- # ---- Stoch RSI ----
- "stoch_rsi": {
- "momentum_stoch_rsi": 5,
- "momentum_stoch_rsi_k": 5,
- "momentum_stoch_rsi_d": 5
- },
-
- # ---- Stochastic ----
- "stoch": {
- "momentum_stoch": 3,
- "momentum_stoch_signal": 3
- },
-
- # ---- ATR / Volatility ----
- "atr": {
- "volatility_atr": 5,
- "volatility_ui": 1
- },
-
- # ---- Bollinger ----
- "bollinger": {
- "volatility_bbm": 5,
- "volatility_bbh": 5,
- "volatility_bbl": 5,
- "volatility_bbw": 5,
- "volatility_bbp": 3,
- "volatility_bbhi": 3,
- "volatility_bbli": 3
- },
-
- # ---- Keltner ----
- "keltner": {
- "volatility_kcc": 5,
- "volatility_kch": 5,
- "volatility_kcl": 5,
- "volatility_kcw": 3,
- "volatility_kcp": 3,
- "volatility_kchi": 3,
- "volatility_kcli": 3
- },
-
- # ---- Donchian ----
- "donchian": {
- "volatility_dcl": 3,
- "volatility_dch": 5,
- "volatility_dcm": 3,
- "volatility_dcw": 3,
- "volatility_dcp": 3
- },
-
- # ---- SMA / EMA ----
- "moving_avg": {
- "trend_sma_fast": 3,
- "trend_sma_slow": 3,
- "trend_ema_fast": 3,
- "trend_ema_slow": 3
- },
-
- # ---- ADX ----
- "adx": {
- "trend_adx": 5,
- "trend_adx_pos": 3,
- "trend_adx_neg": 3
- },
-
- # ---- Vortex ----
- "vortex": {
- "trend_vortex_ind_pos": 3,
- "trend_vortex_ind_neg": 3,
- "trend_vortex_ind_diff": 5
- },
-
- # ---- Aroon ----
- "aroon": {
- "trend_aroon_up": 3,
- "trend_aroon_down": 3,
- "trend_aroon_ind": 5
- },
-
- # ---- Ichimoku ----
- "ichimoku": {
- "trend_ichimoku_conv": 3,
- "trend_ichimoku_base": 3,
- "trend_ichimoku_a": 3,
- "trend_ichimoku_b": 3,
- "trend_stc": 3
- },
-
- # ---- Volume indicators ----
- "volume": {
- "volume_obv": 5,
- "volume_mfi": 5,
- "volume_cmf": 5,
- "volume_vpt": 3,
- "volume_vwap": 3,
- "volume_adi": 3,
- "volume_fi": 1,
- "volume_em": 1,
- "volume_nvi": 1
- },
-
- # ---- Momentum divers ----
- "momentum_other": {
- "momentum_rsi": 5,
- "momentum_wr": 3,
- "momentum_uo": 3,
- "momentum_ao": 3,
- "momentum_kama": 3,
- "momentum_tsi": 3
- },
-
- # ---- Trend divers ----
- "trend_other": {
- "trend_trix": 3,
- "trend_mass_index": 3,
- "trend_kst": 3,
- "trend_kst_sig": 3,
- "trend_kst_diff": 3,
- "trend_dpo": 3,
- "trend_psar_up_indicator": 5,
- "trend_psar_down_indicator": 5
- },
-
- # ---- Faible pertinence ----
- "low_value": {
- "others_dr": 1,
- "others_dlr": 1
- }
- }
-
- @profile
- def StockParam(self, NomDuModel):
- #Sauvegarde les paramètres dans un fichier .param
- data = {
- "NbJourRecul": self.NbJourRecul,
- "Horizon":self.Horizon,
- "NBAction": self.NBAction,
- "Analysis": self.Analysis,
- "NbParam": self.NbAnalysis,
- "PortefeuilleDemarage": self.PortefeuilleDemarage,
- "poidsAchat":self.poidsAchat,
- "ValVente": self.ValVente,
- "epochs":self.epochs,
- "batch_size":self.batch_size,
- "LearningRate":self.LearningRate,
- }
- with open(f"{NomDuModel}.param", "w") as f:
- json.dump(data, f, indent=4)
-
- @profile
- def RestaureParam(self, NomDuModel):
- #Restaure les paramètres depuis un fichier .param
- NomDuModel = NomDuModel + ".param"
- if not os.path.exists(NomDuModel):
- raise FileNotFoundError(f"Le fichier {NomDuModel}.param est introuvable.")
-
- with open(NomDuModel, "r") as f:
- data = json.load(f)
-
- self.NbJourRecul = data.get("NbJourRecul", self.NbJourRecul)
- self.Horizon = data.get("Horizon", self.Horizon)
- self.NBAction = data.get("NBAction", self.NBAction)
- self.Analysis = data.get("Analysis", self.Analysis)
- self.NbAnalysis = data.get("NbParam", len(self.Analysis))
- self.PortefeuilleDemarage = data.get("PortefeuilleDemarage", self.PortefeuilleDemarage)
- self.poidsAchat = data.get("poidsAchat", self.poidsAchat)
- self.ValVente = data.get("ValVente", self.ValVente)
- self.epochs = data.get("",self.epochs)
- self.batch_size =data.get("",self.batch_size)
- self.LearningRate =data.get("",self.LearningRate)
-
- def UUIDData(self, Demmarage, NBNJour):
- data = {
- "Demmarage": Demmarage,
- "NBJour": NBNJour,
- "NbJourRecul": self.NbJourRecul,
- "Horizon": self.Horizon,
- "NBAction": self.NBAction,
- "Analysis": self.Analysis
- }
-
- # sérialisation stable (ordre garanti)
- payload = json.dumps(data, sort_keys=True).encode("utf-8")
-
- # hash
- h = hashlib.blake2s(payload, digest_size=8).hexdigest() # 16 chars
-
- return h
-
- def UUIDRAM(self, date_debut, nb_jours):
- data = {
- "Demmarage": date_debut,
- "NBJour": nb_jours,
- "NbJourRecul": self.NbJourRecul
- }
-
- # sérialisation stable (ordre garanti)
- payload = json.dumps(data, sort_keys=True).encode("utf-8")
-
- # hash
- h = hashlib.blake2s(payload, digest_size=8).hexdigest() # 16 chars
-
- return h
|