Skip to content

Latest commit

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

📊 PrimeTrade Analytics

Trader Performance vs Market Sentiment

A comprehensive data science pipeline analyzing how Bitcoin Fear/Greed sentiment influences trader behavior and performance on Hyperliquid — uncovering actionable patterns for smarter trading strategies.

PythonPandasscikit-learnStreamlitDeployedLicense

Live Dashboard:primetradeds.streamlit.app


Daily PnL Timeline

211,224 trades · 32 unique accounts · 246 coins · 2 years of data · 13+ visualizations · Predictive ML Models



📑 Table of Contents



🎯 Objective

Analyze how Bitcoin market sentiment (Fear & Greed Index) relates to trader behavior and performance on Hyperliquid — a decentralized perpetual exchange — to uncover patterns that could inform smarter trading strategies.

This project delivers:

DeliverableDescription
Data PipelineAutomated cleaning, alignment, and metric engineering for 211K+ trades
Statistical AnalysisWelch's t-tests comparing Fear vs Greed day performance
Trader Segmentation3 segmentation schemes (frequency, consistency, leverage)
13+ VisualizationsDark-themed, publication-quality charts
Strategy Recommendations2 actionable, data-backed strategy rules
Predictive ModelRandom Forest achieving 60.7% accuracy on next-day PnL prediction
Behavioral ClusteringK-Means archetypes (Elite Performers, Selective Winners, etc.)
Interactive DashboardStreamlit app for real-time exploration


📂 Project Structure

PrimeTradeDS/
│
├── 📊 data/
│ ├── fear_greed_index.csv # Bitcoin Fear & Greed Index (2,644 days)
│ └── historical_data.csv # Hyperliquid trader data (211,224 trades)
│
├── 🔬 src/
│ ├── analysis.py # Core analysis pipeline (Parts A + B)
│ ├── visualizations.py # Chart generation engine (13+ charts)
│ └── bonus_models.py # Predictive model + clustering (Bonus)
│
├── 🖥️ dashboard/
│ └── app.py # Streamlit interactive dashboard
│
├── 📈 outputs/
│ ├── charts/ # All generated visualizations (PNG)
│ │ ├── 01_sentiment_distribution.png
│ │ ├── 02_pnl_by_sentiment.png
│ │ ├── 03_behavior_by_sentiment.png
│ │ ├── 04_daily_pnl_timeline.png
│ │ ├── 06_segment_performance.png
│ │ ├── 07_heatmap_*.png
│ │ ├── 08_top_bottom_traders.png
│ │ ├── 09_correlation_matrix.png
│ │ ├── 10_feature_importance.png
│ │ ├── 11_confusion_matrix.png
│ │ ├── 12_elbow_method.png
│ │ └── 13_trader_archetypes.png
│ │
│ └── tables/ # Analysis result tables (CSV + JSON)
│ ├── data_summary.json
│ ├── daily_metrics.csv
│ ├── sentiment_performance.json
│ ├── trader_segments.csv
│ ├── cluster_summary.csv
│ └── model_results.json
│
├── 📓 notebooks/
│ └── exploration.ipynb # Jupyter notebook (optional exploration)
│
├── requirements.txt # Python dependencies
├── .gitignore
└── README.md # You are here!


📊 Dataset Overview

Dataset 1: Bitcoin Fear & Greed Index

PropertyValue
Rows2,644
Columns5 (timestamp, value, classification, date, sentiment_binary)
Date Range2018-02-01 → 2025-05-02
Missing Values0
Duplicates0
CategoriesExtreme Fear, Fear, Greed, Extreme Greed

Dataset 2: Hyperliquid Historical Trader Data

PropertyValue
Rows211,224
Columns18
Date Range2023-05-01 → 2025-05-01
Unique Accounts32
Unique Coins246
Key FieldsAccount, Coin, Execution Price, Size USD, Side, Closed PnL, Fee, Timestamp

📌 Alignment: Both datasets were merged on date at daily granularity. The overlapping period covers ~730 trading days. Only 6 trades were dropped due to no sentiment match.



🔧 Setup & Installation

Prerequisites

  • Python 3.10+
  • pip

Quick Start

# 1. Clone the repository
git clone https://github.com/adarshcod30/PrimeTradeDS.git
cd PrimeTradeDS
# 2. Install dependencies
pip install -r requirements.txt
# 3. Run the full analysis pipelinecd src
python analysis.py # Part A + B: Data prep + Analysis
python visualizations.py # Generate all 13+ charts
python bonus_models.py # Bonus: Predictive model + clustering# 4. Launch the interactive dashboardcd ..
streamlit run dashboard/app.py


📋 Part A — Data Preparation

Data Loading & Cleaning

Both datasets were loaded, inspected, and cleaned:

  • Timestamps converted to proper datetime objects
  • Numeric columns coerced (handling mixed types in Size, PnL, Fee)
  • Date alignment performed via inner join on date column
  • Duplicates checked and removed
  • Missing values handled (0 missing in both datasets after cleaning)

Engineered Metrics

The following daily per-account metrics were computed:

MetricFormulaPurpose
total_pnlSum of Closed PnL per day per accountDaily profit/loss
trade_countCount of trades per dayActivity level
win_rateProfitable trades / Total tradesSuccess ratio
avg_size_usdMean position size in USDRisk appetite
long_ratioBUY trades / Total tradesDirectional bias
avg_pnl_per_tradeTotal PnL / Trade countEfficiency
total_volumeSum of Size USDCapital deployed

Result: 2,340 account-day observation rows generated from 211,218 merged trades.



📈 Part B — Analysis & Insights

1. Does Performance Differ Between Fear vs Greed Days?

PnL by Sentiment

MetricFear (Mean)Greed (Mean)T-StatP-ValueSignificant?
Total PnL$5,185.15$3,973.050.930.353
Win Rate35.71%36.10%-0.260.796
Avg PnL/Trade$71.96$115.18-1.030.303
Trade Count105.3682.572.260.024
Avg Size USD$8,529.86$6,199.411.910.056⚠️
Long Ratio52.15%47.23%3.060.002

Key Findings:

🔍 Insight 1: Traders are significantly more active on Fear days (105 vs 83 trades/day, p=0.024). Fear-driven volatility creates more trading opportunities.

🔍 Insight 2: Traders show a strong long bias on Fear days (52.1% vs 47.2%, p=0.002). Counter-intuitively, traders buy the dip during fear — a contrarian signal.

🔍 Insight 3: While average PnL per trade is higher on Greed days ($115 vs $72), the total PnL is actually higher on Fear days due to increased volume — suggesting that volume, not accuracy, drives Fear-day profits.


2. Behavioral Changes by Sentiment

Behavior by Sentiment

3. Trader Segmentation

Three segmentation schemes were applied:

SegmentCriteriaGroups
FrequencyMedian split on trading daysFrequent / Infrequent
ConsistencySharpe ratio (mean PnL / std PnL)Consistent Winner / Inconsistent
LeverageMedian split on avg leverageHigh / Low (when data available)
Segment Performance

Segment × Sentiment Cross-Analysis

Frequency HeatmapConsistency Heatmap

4. Top & Bottom Performers

Top Bottom Traders

5. Metric Correlations

Correlation Matrix


💡 Part C — Actionable Strategy Recommendations

Based on the statistical analysis and segmentation, here are 2 data-backed strategy ideas:

Strategy 1: "Fear-Day Volume Harvester"

Rule: During Fear days, increase trade frequency for Frequent Traders (those with high activity), but with smaller position sizes.

Rationale:

  • Fear days generate 27.6% more trades on average (statistically significant, p=0.024)
  • Total PnL is 30.5% higher on Fear days ($5,185 vs $3,973) due to volume
  • However, per-trade efficiency is lower ($72 vs $115), so many small trades capture the volatility premium better than large bets
  • Frequent traders already have the skill to execute high-volume strategies

Implementation:

IF sentiment == "Fear":
target_trade_count = baseline_count * 1.3 # Increase activity 30%
position_size = baseline_size * 0.75 # Reduce size 25%
bias = "long" # Exploit buy-the-dip tendency

Strategy 2: "Greed-Day Precision Play"

Rule: During Greed days, reduce trade frequency for Inconsistent Traders and focus on higher-conviction, larger trades with a balanced long/short ratio.

Rationale:

  • Greed-day per-trade PnL is 60% higher ($115 vs $72) — quality > quantity
  • Long ratio drops to 47.2% (near balanced) — suggesting the market rewards two-sided trading on Greed days
  • Inconsistent traders benefit from waiting for clearer setups rather than overtrading
  • Position sizes can be slightly larger given higher per-trade expected value

Implementation:

IF sentiment == "Greed":
target_trade_count = baseline_count * 0.8 # Reduce activity 20%
position_size = baseline_size * 1.15 # Increase size 15%
bias = "balanced" # Long/short balanced
min_conviction_threshold = 0.7 # Only take high-confidence trades


🧠 Bonus — Predictive Model & Clustering

Predictive Model: Next-Day Profitability

A Random Forest and Gradient Boosting classifier were trained to predict next-day profitability bucket (Loss / Neutral / Profit) using:

Features: Sentiment, current-day PnL, win rate, trade count, position size, volume, lag features (1-day, 2-day), rolling 3-day PnL mean/std

ModelCV AccuracyStd
Random Forest60.7%±4.3%
Gradient Boosting57.1%±4.4%

Baseline (random): 33.3% — our model achieves 1.82× baseline accuracy.

Feature Importance

Top predictive features: trader_count, pnl_rolling3, total_volume, vol_rolling3 — indicating that market-wide activity and momentum are stronger predictors than sentiment alone.

Confusion Matrix

Trader Clustering: Behavioral Archetypes

K-Means clustering (k=4) identified distinct trader archetypes:

Trader Archetypes

ArchetypeCountAvg PnLWin RateAvg TradesAvg Size (USD)
🎯 Selective Winners19$7,32132.1%2,908$7,000
🏆 Elite Performers5$7,05637.3%5,111$23,397
📉 Struggling Traders8$6,71041.1%16,302$4,002

🔑 Key Insight: Elite Performers trade large positions ($23K avg) but are selective. Struggling Traders have the highest win rate (41%) but overtrade (16K trades), eroding gains through fees.

Elbow Method


📊 Dashboard

An interactive Streamlit dashboard is deployed and available for real-time exploration:

Live:primetradeds.streamlit.app

Or run locally:

streamlit run dashboard/app.py

Dashboard features:

  • Guided sidebar with contextual descriptions — anyone can understand the controls without prior context
  • Human-readable trader labels (Trader-01, Trader-02...) instead of raw hex addresses
  • Sentiment vs Performance — violin plots, PnL timelines, and statistical significance tests
  • Behavioral Patterns — trade frequency, position sizing, and long/short bias comparisons
  • Trader Segments — segmentation explorer with leaderboard and cross-analysis
  • Predictive Model — feature importance, confusion matrix, and cluster archetypes
  • Key Takeaways — summary of all insights + two strategy recommendation cards


🌐 Deployment

The dashboard is deployed on Streamlit Community Cloud:

PropertyValue
URLprimetradeds.streamlit.app
PlatformStreamlit Community Cloud
Branchmain
Main filedashboard/app.py

To deploy your own instance:

  1. Fork this repository
  2. Go to share.streamlit.io
  3. Connect your GitHub account and select the repo
  4. Set Main file path to dashboard/app.py
  5. Click Deploy


🛠️ Tech Stack

CategoryTechnology
LanguagePython 3.10+
Data ProcessingPandas, NumPy
VisualizationMatplotlib, Seaborn, Plotly
Machine Learningscikit-learn (Random Forest, Gradient Boosting, K-Means)
Statistical TestingSciPy (Welch's t-test)
DashboardStreamlit
ExportKaleido (chart export)
DeploymentStreamlit Community Cloud


📝 Summary Write-Up

Methodology

  1. Data Preparation: Loaded 211K+ trades and 2,644 days of sentiment data. Cleaned, parsed timestamps, engineered 7 daily metrics per account, and merged on date via inner join.
  2. Statistical Analysis: Applied Welch's two-sample t-tests to compare Fear vs Greed day metrics. Used α=0.05 significance threshold.
  3. Segmentation: Created 3 trader segmentation schemes (frequency, consistency, leverage) using median splits and Sharpe ratio.
  4. Predictive Modeling: Built Random Forest + Gradient Boosting classifiers with lag features and rolling statistics to predict next-day profitability.
  5. Clustering: Applied K-Means (k=4) with PCA visualization to identify behavioral archetypes.

Key Insights

  1. Fear days drive volume, not accuracy — 27.6% more trades, but per-trade PnL is 37.5% lower
  2. Traders buy the dip — statistically significant long bias on Fear days (52.1% vs 47.2%, p=0.002)
  3. Overtrading kills returns — Struggling Traders have the highest win rate (41%) but the most trades, eroding profits through fees
  4. Momentum > Sentiment — Rolling PnL and volume are stronger predictors than raw sentiment

Strategy Recommendations

  1. Fear Days: Increase frequency, decrease size — harvest volatility with controlled risk
  2. Greed Days: Decrease frequency, increase conviction — precision over volume


👤 Author

Adarsh Dwivedi

GitHub


About

Analyzing how Bitcoin Fear/Greed sentiment influences trader behavior and performance on Hyperliquid — 211K trades, statistical analysis, ML models, and an interactive Streamlit dashboard.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages