-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
67 lines (52 loc) · 2.63 KB
/
Copy pathapp.py
File metadata and controls
67 lines (52 loc) · 2.63 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
import streamlit as st
import pandas as pd
import plotly.express as px
st.set_page_config(page_title="Trader Behavior vs Sentiment", layout="wide")
st.title("Primetrade.ai Data Science Intern Assignment")
st.markdown("### Analyzing Trader Performance vs Market Sentiment on Hyperliquid")
@st.cache_data
def load_data():
try:
df = pd.read_csv('aggregated_trader_metrics.csv')
df['date'] = pd.to_datetime(df['date'])
return df
except FileNotFoundError:
return pd.DataFrame()
df = load_data()
if df.empty:
st.warning("Data not found. Please run analysis.py first to generate the aggregated metrics.")
else:
st.sidebar.header("Filters")
sentiment_filter = st.sidebar.multiselect("Sentiment", options=df['Sentiment_Broad'].unique(), default=df['Sentiment_Broad'].unique())
filtered_df = df[df['Sentiment_Broad'].isin(sentiment_filter)]
col1, col2 = st.columns(2)
with col1:
st.subheader("Average PnL by Sentiment")
fig1 = px.box(filtered_df, x="Sentiment_Broad", y="Closed PnL", color="Sentiment_Broad", title="PnL Distribution")
st.plotly_chart(fig1, use_container_width=True)
with col2:
st.subheader("Win Rate Distribution")
fig2 = px.box(filtered_df, x="Sentiment_Broad", y="Win Rate", color="Sentiment_Broad", title="Win Rate")
st.plotly_chart(fig2, use_container_width=True)
st.subheader("Behavioral Changes")
col3, col4, col5 = st.columns(3)
with col3:
fig3 = px.histogram(filtered_df, x="Trade Count", color="Sentiment_Broad", barmode="overlay", title="Trade Frequency")
st.plotly_chart(fig3, use_container_width=True)
with col4:
fig4 = px.box(filtered_df, x="Sentiment_Broad", y="Avg Trade Size USD", color="Sentiment_Broad", title="Trade Size (USD)")
# filter out extreme outliers for better visualization
fig4.update_yaxes(range=[0, filtered_df['Avg Trade Size USD'].quantile(0.95)])
st.plotly_chart(fig4, use_container_width=True)
with col5:
fig5 = px.box(filtered_df, x="Sentiment_Broad", y="Long/Short Ratio", color="Sentiment_Broad", title="Long/Short Bias")
fig5.update_yaxes(range=[0, 5])
st.plotly_chart(fig5, use_container_width=True)
st.markdown("### Actionable Output Segments")
st.markdown("""
- **High Leverage vs Low Leverage**: Use Total Volume USD as a proxy.
- **Frequent vs Infrequent**: Based on median daily Trade Count.
- **Consistent Winners vs Inconsistent**: Based on Win Rate.
""")
if st.checkbox("Show Raw Data"):
st.write(filtered_df.head(100))