-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathutils.py
More file actions
133 lines (113 loc) · 3.87 KB
/
utils.py
File metadata and controls
133 lines (113 loc) · 3.87 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import pandas as pd
import plotly.graph_objects as go
def create_gauge_chart(probability):
"""
Crée un graphique de type gauge pour afficher la probabilité de hausse du marché
"""
fig = go.Figure(
go.Indicator(
mode="gauge+number",
value=probability * 100,
domain={"x": [0, 1], "y": [0, 1]},
gauge={
"axis": {"range": [0, 100], "tickwidth": 1},
"bar": {"color": "rgba(50,150,255,0.8)"},
"bgcolor": "white",
"borderwidth": 2,
"bordercolor": "gray",
"steps": [
{"range": [0, 30], "color": "rgba(255,0,0,0.1)"},
{"range": [30, 70], "color": "rgba(255,255,0,0.1)"},
{"range": [70, 100], "color": "rgba(0,255,0,0.1)"},
],
"threshold": {
"line": {"color": "red", "width": 4},
"thickness": 0.75,
"value": 50,
},
},
title={"text": "Market Trend Probability", "font": {"size": 24}},
number={"suffix": "%", "font": {"size": 20}},
)
)
fig.update_layout(
paper_bgcolor="rgba(0,0,0,0)", plot_bgcolor="rgba(0,0,0,0)", height=400
)
return fig
def create_model_probability_chart(probabilities):
"""
Crée un graphique en barres pour comparer les probabilités des différents modèles
"""
models = list(probabilities.keys())
probs = [probabilities[model] * 100 for model in models]
colors = [
"rgba(50,150,255,0.8)" if p > 50 else "rgba(255,50,50,0.8)" for p in probs
]
fig = go.Figure(
data=[
go.Bar(
x=models,
y=probs,
marker_color=colors,
text=[f"{p:.1f}%" for p in probs],
textposition="auto",
)
]
)
fig.update_layout(
title={
"text": "Model Confidence Levels",
"y": 0.9,
"x": 0.5,
"xanchor": "center",
"yanchor": "top",
"font": {"size": 24},
},
yaxis_title="Probability (%)",
paper_bgcolor="rgba(0,0,0,0)",
plot_bgcolor="rgba(0,0,0,0)",
height=400,
yaxis=dict(gridcolor="rgba(0,0,0,0.1)", range=[0, 100]),
xaxis=dict(gridcolor="rgba(0,0,0,0.1)"),
)
return fig
def create_historical_chart(df, date, window=30):
"""
Crée un graphique historique des indicateurs clés
"""
# Convertir la colonne date en datetime si ce n'est pas déjà fait
df["Data"] = pd.to_datetime(df["Data"])
# Sélectionner une fenêtre de données autour de la date
date = pd.to_datetime(date)
mask = (df["Data"] >= date - pd.Timedelta(days=window)) & (
df["Data"] <= date + pd.Timedelta(days=window)
)
df_window = df[mask]
fig = go.Figure()
# Ajouter les indicateurs clés
key_indicators = {
"XAU BGNL": "Gold Price",
"VIX": "Volatility Index",
"LUMSTRUU": "Global Bond Index",
"LMBITR": "Market Index",
"LUACTRUU": "Aggregate Bond Index",
}
for col, name in key_indicators.items():
if col in df_window.columns:
# Normaliser les valeurs pour une meilleure visualisation
values = df_window[col]
normalized = (values - values.min()) / (values.max() - values.min())
fig.add_trace(
go.Scatter(x=df_window["Data"], y=normalized, name=name, mode="lines")
)
fig.update_layout(
title="Historical Market Indicators",
xaxis_title="Date",
yaxis_title="Normalized Value",
height=400,
margin=dict(l=10, r=10, t=40, b=10),
paper_bgcolor="white",
plot_bgcolor="white",
hovermode="x unified",
)
return fig