-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimulateur_multi.py
More file actions
79 lines (62 loc) · 2.6 KB
/
simulateur_multi.py
File metadata and controls
79 lines (62 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# simulateur_multi.py
from core.engine import profil, scoring, config_loader
import core.historique_rendements as historique_rendements
from defi_sources import defillama
from graphiques import gains_profils
SOLDE_INITIAL = 1000.0
DUREE_SIMULATION_JOURS = 7 # ← simulation sur 7 jours
def simuler_investissement(pools, solde, jours=7, pond_apr=1.0):
montant_par_pool = solde / len(pools)
gains = []
for pool in pools:
apr = pool.get("apr", 0)
gain = montant_par_pool * (apr / 100) * (jours / 365) * pond_apr
gains.append(gain)
return round(sum(gains), 2)
def formater_resultats(profil_nom, top3, gain):
texte = f"🧪 Profil : {profil_nom}\n"
for i, pool in enumerate(top3, 1):
texte += (f"TOP {i} : {pool['plateforme']} | {pool['nom']} | "
f"TVL ${pool['tvl_usd']:.2f} | APR {pool['apr']:.2f}% | "
f"Score {pool['score']:.2f}\n")
texte += f"📅 Durée : {DUREE_SIMULATION_JOURS} jours\n"
texte += f"💰 Gain estimé : {gain:.2f}$\n\n"
return texte
def analyser_par_profil(pools, profils, callback_affichage=None):
resultats_gains = {}
texte_final = ""
for nom_profil in profils:
ponderations = profil.charger_ponderations(nom_profil)
pools_avec_scores = scoring.calculer_scores(pools.copy(), ponderations)
pools_triees = sorted(pools_avec_scores, key=lambda p: p["score"], reverse=True)
top3 = pools_triees[:3]
gain_total = simuler_investissement(
top3,
SOLDE_INITIAL,
jours=DUREE_SIMULATION_JOURS,
pond_apr=ponderations["apr"]
)
historique_rendements.enregistrer_resultats(nom_profil, top3, gain_total)
resultats_gains[nom_profil] = gain_total
texte_final += formater_resultats(nom_profil, top3, gain_total)
# Graphe
gains_profils.afficher_et_sauvegarder_gains(resultats_gains, duree_jours=DUREE_SIMULATION_JOURS)
# Affichage des résultats dans l’interface si callback fourni
if callback_affichage:
callback_affichage(texte_final)
else:
print(texte_final)
def main(callback_affichage=None):
config_loader.charger_config()
pools = defillama.recuperer_pools()
if not pools:
texte = "❌ Aucune pool récupérée."
if callback_affichage:
callback_affichage(texte)
else:
print(texte)
return
profils_a_tester = ["prudent", "modere", "equilibre", "dynamique", "agressif"]
analyser_par_profil(pools, profils_a_tester, callback_affichage=callback_affichage)
if __name__ == "__main__":
main()