Initial commit: UI/UX dashboard skeleton

- Basic Flask backend with mock metrics API
- Bootstrap/Chart.js frontend dashboard
- Displays key metrics: PnL, drawdown, win rate
- Interactive charts and auto-refresh
- Ready for integration with real data sources
This commit is contained in:
2026-02-04 10:41:02 +08:00
commit 0121cb6097
5 changed files with 511 additions and 0 deletions

70
app.py Normal file
View File

@@ -0,0 +1,70 @@
#!/usr/bin/env python3
"""
Simple dashboard server for Quantitative Trading Platform.
Provides mock metrics for PnL, drawdown, and win rate.
"""
from flask import Flask, render_template, jsonify
import random
from datetime import datetime, timedelta
app = Flask(__name__)
def generate_mock_metrics():
"""Generate realistic mock trading metrics."""
# Simulate daily PnL over last 30 days
end_date = datetime.now()
start_date = end_date - timedelta(days=30)
daily_pnl = []
current_pnl = 0
for i in range(30):
day_pnl = random.uniform(-500, 1500)
current_pnl += day_pnl
daily_pnl.append({
'date': (start_date + timedelta(days=i)).strftime('%Y-%m-%d'),
'pnl': round(day_pnl, 2),
'cumulative': round(current_pnl, 2)
})
# Calculate derived metrics
total_pnl = current_pnl
peak = max([d['cumulative'] for d in daily_pnl])
trough = min([d['cumulative'] for d in daily_pnl])
max_drawdown = round(abs(trough - peak), 2) if peak > 0 else 0
# Win rate (percentage of profitable days)
profitable_days = sum(1 for d in daily_pnl if d['pnl'] > 0)
win_rate = round(profitable_days / len(daily_pnl) * 100, 1)
# Current portfolio value (simulated)
portfolio_value = 100000 + total_pnl
return {
'total_pnl': round(total_pnl, 2),
'daily_pnl': daily_pnl,
'max_drawdown': max_drawdown,
'win_rate': win_rate,
'portfolio_value': round(portfolio_value, 2),
'peak': round(peak, 2),
'trough': round(trough, 2),
'last_updated': end_date.isoformat()
}
@app.route('/')
def dashboard():
"""Serve the dashboard HTML page."""
return render_template('dashboard.html')
@app.route('/api/metrics')
def metrics():
"""API endpoint returning current metrics."""
return jsonify(generate_mock_metrics())
@app.route('/health')
def health():
"""Health check endpoint."""
return jsonify({'status': 'healthy', 'timestamp': datetime.now().isoformat()})
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=True)