-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdashboard.py
More file actions
142 lines (113 loc) · 4.95 KB
/
dashboard.py
File metadata and controls
142 lines (113 loc) · 4.95 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
134
135
136
137
138
139
140
141
142
import ast
import streamlit as st
from datetime import datetime, timedelta
from requests import post
URL = "https://backtestapi.onrender.com/backtesting/"
# Couleurs personnalisées
background_color = "#f0f0f0"
button_color = "#4CAF50"
button_hover_color = "#45a049"
text_color = "black"
border_color = "black"
# Configuration du style Streamlit
st.markdown(
f"""
<style>
body {{
color: {text_color};
background-color: {background_color};
}}
.stButton>button {{
background-color: {button_color};
color: white;
font-weight: bold;
border-color: {border_color};
border-width: 2px;
border-style: solid;
}}
.stButton>button:hover {{
background-color: {button_hover_color};
}}
</style>
""",
unsafe_allow_html=True,
)
def get_color(value):
if value >= 0:
return 'rgba(152, 251, 152, 0.7)' # Vert pastel
else:
return 'rgba(255, 182, 193, 0.7)'
def show_homepage():
st.title("Backtesting de stratégie de trading")
st.markdown("""
**Objectif :** Le but de ce projet est de développer une API permettant aux utilisateurs de soumettre leurs propres stratégies de trading algorithmique pour backtesting. Le système doit être capable d’exécuter ces stratégies sur des données de marché historiques et de fournir des analyses de performance sur la période spécifiée.
""")
def show_backtesting():
st.title('Backtesting de stratégie de trading')
col1, col2 = st.columns(2)
with col1:
start_date = st.date_input('Date de début', max_value=datetime.today() + timedelta(days=365 * 100), format="DD-MM-YYYY")
with col2:
end_date = st.date_input('Date de fin', value= datetime.today() + timedelta(days=7), max_value=datetime.today() + timedelta(days=365 * 100), format="DD-MM-YYYY")
if start_date < end_date:
st.success('Dates sélectionnées valides !')
else:
st.error('Erreur : La date de début doit être antérieure à la date de fin.')
func_strat = st.text_area("Fonction de trading avec les imports", value="import pandas as pd \n def fonction_trading(df: pd.DataFrame):\n ... \n df_positions = pd.DataFrame() \n return df_positions")
requirements = st.text_input("Imports nécessaires à la stratégie", value=["pandas", "numpy"])
tickers = st.text_input("Actifs utilisés dans la stratégie", value=["ETHBTC", "BNBETH"])
interval = st.text_input("Fréquence des données de marché", value="1d")
request_id = st.text_input("Id de la requête. Doit être unique !", value="12345")
is_recurring = st.selectbox("Répéter le backtest ?", [True, False])
start = start_date.strftime('%Y-%m-%d')
end = end_date.strftime('%Y-%m-%d')
if is_recurring:
repeat_frequency = st.number_input("fréquence de répétition", value=2)
else:
repeat_frequency = 0
if st.button("Backtest"):
with st.spinner("Calculating..."):
data = {
"func_strat": func_strat,
"requirements": ast.literal_eval(requirements),
"tickers": ast.literal_eval(tickers),
"dates": [start, end],
"interval": interval,
"request_id": request_id,
"is_recurring": is_recurring,
"repeat_frequency": repeat_frequency,
"nb_execution": 1
}
res = post(url=URL, json=data).json()
st.success("Backtest réussi !")
print("res :", res)
col1, col2 = st.columns(2)
# Afficher les informations dans la première colonne
with col1:
st.subheader('Performance')
for key, value in res.items():
if "Rendement" in key or "Ratio" in key:
color = get_color(value)
st.markdown(
f'<div style="background-color: {color}; padding: 10px; border-radius: 5px;"><strong>{key}</strong>: {value:.4f}</div>',
unsafe_allow_html=True)
# Afficher les informations dans la deuxième colonne
with col2:
st.subheader('Risque')
for key, value in res.items():
if "Volatilite" in key or "Deviation" in key or "VaR" in key or "Drawdown" in key or "Skewness" in key or "Kurtosis" in key:
color = get_color(value)
st.markdown(
f'<div style="background-color: {color}; padding: 10px; border-radius: 5px;"><strong>{key}</strong>: {value:.4f}</div>',
unsafe_allow_html=True)
def main():
pages = {
"Page d'accueil": show_homepage,
"Backtest de stratégies": show_backtesting,
}
st.sidebar.title("Navigation")
selection = st.sidebar.radio("Go to", list(pages.keys()))
page = pages[selection]
page()
if __name__ == "__main__":
main()