feat: Integrated Dashboard v2.0 with LLM-driven Mock Backend
- Promoted prototype dashboard to main app - Added /api/market-data endpoint - Implemented market_simulator.py for realistic OHLCV generation - Updated MoomooClient to serve simulated scenarios - Wired frontend to backend API
This commit is contained in:
485
static/css/style.css
Normal file
485
static/css/style.css
Normal file
@@ -0,0 +1,485 @@
|
||||
/*
|
||||
* Quantitative Trading Platform - Interactive Mockup
|
||||
* CSS Styles for the complete platform mockup
|
||||
*/
|
||||
|
||||
:root {
|
||||
/* Color Palette */
|
||||
--primary-dark: #0a1929;
|
||||
--secondary-dark: #1e2a38;
|
||||
--tertiary-dark: #2a3a4d;
|
||||
|
||||
/* Accent Colors */
|
||||
--accent-blue: #1976d2;
|
||||
--accent-green: #4caf50;
|
||||
--accent-red: #f44336;
|
||||
--accent-purple: #9c27b0;
|
||||
--accent-orange: #ff9800;
|
||||
--accent-cyan: #00bcd4;
|
||||
--accent-yellow: #ffc107;
|
||||
|
||||
/* Text Colors */
|
||||
--text-primary: #ffffff;
|
||||
--text-secondary: #b0bec5;
|
||||
--text-muted: #78909c;
|
||||
|
||||
/* Border Colors */
|
||||
--border-dark: #37474f;
|
||||
--border-light: #546e7a;
|
||||
|
||||
/* Status Colors */
|
||||
--status-success: #4caf50;
|
||||
--status-warning: #ff9800;
|
||||
--status-danger: #f44336;
|
||||
--status-info: #2196f3;
|
||||
|
||||
/* Chart Colors */
|
||||
--chart-line: #4caf50;
|
||||
--chart-area: rgba(76, 175, 80, 0.1);
|
||||
--chart-grid: #37474f;
|
||||
}
|
||||
|
||||
/* Base Styles */
|
||||
body {
|
||||
font-family: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, 'Roboto', sans-serif;
|
||||
background-color: var(--primary-dark);
|
||||
color: var(--text-primary);
|
||||
overflow-x: hidden;
|
||||
font-size: 0.9rem;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
/* Typography */
|
||||
h1, h2, h3, h4, h5, h6 {
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.text-muted {
|
||||
color: var(--text-muted) !important;
|
||||
}
|
||||
|
||||
/* Cards */
|
||||
.card {
|
||||
background-color: var(--primary-dark);
|
||||
border: 1px solid var(--border-dark);
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.card:hover {
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.card-header {
|
||||
background-color: rgba(255, 255, 255, 0.03);
|
||||
border-bottom: 1px solid var(--border-dark);
|
||||
padding: 0.75rem 1rem;
|
||||
}
|
||||
|
||||
.card-body {
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
/* Border accent colors */
|
||||
.border-accent-blue {
|
||||
border-color: var(--accent-blue) !important;
|
||||
}
|
||||
|
||||
.border-accent-green {
|
||||
border-color: var(--accent-green) !important;
|
||||
}
|
||||
|
||||
.border-accent-red {
|
||||
border-color: var(--accent-red) !important;
|
||||
}
|
||||
|
||||
.border-accent-purple {
|
||||
border-color: var(--accent-purple) !important;
|
||||
}
|
||||
|
||||
.border-accent-orange {
|
||||
border-color: var(--accent-orange) !important;
|
||||
}
|
||||
|
||||
.border-secondary-dark {
|
||||
border-color: var(--secondary-dark) !important;
|
||||
}
|
||||
|
||||
/* Sidebar Navigation */
|
||||
.sidebar {
|
||||
min-height: calc(100vh - 56px);
|
||||
padding-top: 1rem;
|
||||
}
|
||||
|
||||
.nav-link {
|
||||
color: var(--text-secondary);
|
||||
padding: 0.75rem 1rem;
|
||||
margin: 0.125rem 0.5rem;
|
||||
border-radius: 6px;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.nav-link:hover {
|
||||
color: var(--text-primary);
|
||||
background-color: rgba(255, 255, 255, 0.05);
|
||||
}
|
||||
|
||||
.nav-link.active {
|
||||
color: var(--text-primary);
|
||||
background-color: rgba(25, 118, 210, 0.15);
|
||||
border-left: 3px solid var(--accent-blue);
|
||||
}
|
||||
|
||||
.nav-link i {
|
||||
width: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* Progress Bars */
|
||||
.progress {
|
||||
background-color: var(--tertiary-dark);
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.progress-bar {
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
/* Tables */
|
||||
.table-dark {
|
||||
--bs-table-bg: transparent;
|
||||
--bs-table-striped-bg: rgba(255, 255, 255, 0.03);
|
||||
--bs-table-hover-bg: rgba(255, 255, 255, 0.05);
|
||||
color: var(--text-primary);
|
||||
border-color: var(--border-dark);
|
||||
}
|
||||
|
||||
.table-dark th {
|
||||
font-weight: 600;
|
||||
color: var(--text-secondary);
|
||||
border-color: var(--border-dark);
|
||||
}
|
||||
|
||||
.table-dark td {
|
||||
border-color: var(--border-dark);
|
||||
}
|
||||
|
||||
/* Forms */
|
||||
.form-control, .form-select {
|
||||
background-color: var(--secondary-dark);
|
||||
border: 1px solid var(--border-dark);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.form-control:focus, .form-select:focus {
|
||||
background-color: var(--secondary-dark);
|
||||
border-color: var(--accent-blue);
|
||||
color: var(--text-primary);
|
||||
box-shadow: 0 0 0 0.25rem rgba(25, 118, 210, 0.25);
|
||||
}
|
||||
|
||||
.form-control::placeholder {
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.input-group-text {
|
||||
background-color: var(--tertiary-dark);
|
||||
border: 1px solid var(--border-dark);
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
/* Buttons */
|
||||
.btn {
|
||||
border-radius: 6px;
|
||||
font-weight: 500;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.btn-outline-light {
|
||||
color: var(--text-secondary);
|
||||
border-color: var(--border-dark);
|
||||
}
|
||||
|
||||
.btn-outline-light:hover {
|
||||
background-color: rgba(255, 255, 255, 0.1);
|
||||
border-color: var(--border-light);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background-color: var(--accent-blue);
|
||||
border-color: var(--accent-blue);
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
background-color: #1565c0;
|
||||
border-color: #1565c0;
|
||||
}
|
||||
|
||||
.btn-success {
|
||||
background-color: var(--accent-green);
|
||||
border-color: var(--accent-green);
|
||||
}
|
||||
|
||||
.btn-danger {
|
||||
background-color: var(--accent-red);
|
||||
border-color: var(--accent-red);
|
||||
}
|
||||
|
||||
.btn-warning {
|
||||
background-color: var(--accent-orange);
|
||||
border-color: var(--accent-orange);
|
||||
color: #000;
|
||||
}
|
||||
|
||||
.btn-info {
|
||||
background-color: var(--accent-cyan);
|
||||
border-color: var(--accent-cyan);
|
||||
}
|
||||
|
||||
/* Badges */
|
||||
.badge {
|
||||
font-weight: 500;
|
||||
padding: 0.35em 0.65em;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.bg-purple {
|
||||
background-color: var(--accent-purple) !important;
|
||||
}
|
||||
|
||||
/* Alerts */
|
||||
.alert {
|
||||
border-radius: 6px;
|
||||
border: 1px solid transparent;
|
||||
}
|
||||
|
||||
.alert-warning {
|
||||
background-color: rgba(255, 152, 0, 0.1);
|
||||
border-color: rgba(255, 152, 0, 0.3);
|
||||
color: var(--accent-orange);
|
||||
}
|
||||
|
||||
.alert-success {
|
||||
background-color: rgba(76, 175, 80, 0.1);
|
||||
border-color: rgba(76, 175, 80, 0.3);
|
||||
color: var(--accent-green);
|
||||
}
|
||||
|
||||
.alert-info {
|
||||
background-color: rgba(33, 150, 243, 0.1);
|
||||
border-color: rgba(33, 150, 243, 0.3);
|
||||
color: var(--accent-blue);
|
||||
}
|
||||
|
||||
/* Charts Container */
|
||||
canvas {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
/* Section Transitions */
|
||||
.section-content {
|
||||
animation: fadeIn 0.3s ease;
|
||||
}
|
||||
|
||||
@keyframes fadeIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(10px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
/* Responsive Adjustments */
|
||||
@media (max-width: 768px) {
|
||||
.sidebar {
|
||||
min-height: auto;
|
||||
border-right: none;
|
||||
border-bottom: 1px solid var(--border-dark);
|
||||
}
|
||||
|
||||
.nav-link {
|
||||
margin: 0.125rem 0;
|
||||
}
|
||||
|
||||
.display-4 {
|
||||
font-size: 2.5rem;
|
||||
}
|
||||
}
|
||||
|
||||
/* Utility Classes */
|
||||
.text-success {
|
||||
color: var(--accent-green) !important;
|
||||
}
|
||||
|
||||
.text-danger {
|
||||
color: var(--accent-red) !important;
|
||||
}
|
||||
|
||||
.text-warning {
|
||||
color: var(--accent-orange) !important;
|
||||
}
|
||||
|
||||
.text-info {
|
||||
color: var(--accent-cyan) !important;
|
||||
}
|
||||
|
||||
.bg-primary-dark {
|
||||
background-color: var(--primary-dark) !important;
|
||||
}
|
||||
|
||||
.bg-secondary-dark {
|
||||
background-color: var(--secondary-dark) !important;
|
||||
}
|
||||
|
||||
.border-secondary-dark {
|
||||
border-color: var(--secondary-dark) !important;
|
||||
}
|
||||
|
||||
/* Scrollbar Styling */
|
||||
::-webkit-scrollbar {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-track {
|
||||
background: var(--secondary-dark);
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-thumb {
|
||||
background: var(--tertiary-dark);
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-thumb:hover {
|
||||
background: var(--border-light);
|
||||
}
|
||||
|
||||
/* List Groups */
|
||||
.list-group-item {
|
||||
background-color: transparent;
|
||||
color: var(--text-primary);
|
||||
border-color: var(--border-dark);
|
||||
}
|
||||
|
||||
.list-group-item:hover {
|
||||
background-color: rgba(255, 255, 255, 0.03);
|
||||
}
|
||||
|
||||
/* Hover Effects */
|
||||
.hover-lift {
|
||||
transition: transform 0.2s ease;
|
||||
}
|
||||
|
||||
.hover-lift:hover {
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
/* Highlight animation for updated values */
|
||||
@keyframes highlight {
|
||||
0% { color: var(--text-primary); }
|
||||
50% { color: var(--accent-yellow); }
|
||||
100% { color: var(--text-primary); }
|
||||
}
|
||||
|
||||
.text-highlight {
|
||||
animation: highlight 1s ease;
|
||||
}
|
||||
|
||||
/* Status Indicators */
|
||||
.status-indicator {
|
||||
display: inline-block;
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
margin-right: 6px;
|
||||
}
|
||||
|
||||
.status-indicator.online {
|
||||
background-color: var(--accent-green);
|
||||
box-shadow: 0 0 8px var(--accent-green);
|
||||
}
|
||||
|
||||
.status-indicator.warning {
|
||||
background-color: var(--accent-orange);
|
||||
box-shadow: 0 0 8px var(--accent-orange);
|
||||
}
|
||||
|
||||
.status-indicator.offline {
|
||||
background-color: var(--accent-red);
|
||||
box-shadow: 0 0 8px var(--accent-red);
|
||||
}
|
||||
|
||||
/* Metric Cards */
|
||||
.metric-card {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.metric-card::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 3px;
|
||||
background: linear-gradient(90deg, var(--accent-blue), var(--accent-cyan));
|
||||
}
|
||||
|
||||
.metric-card.green::before {
|
||||
background: linear-gradient(90deg, var(--accent-green), #81c784);
|
||||
}
|
||||
|
||||
.metric-card.red::before {
|
||||
background: linear-gradient(90deg, var(--accent-red), #e57373);
|
||||
}
|
||||
|
||||
.metric-card.orange::before {
|
||||
background: linear-gradient(90deg, var(--accent-orange), #ffb74d);
|
||||
}
|
||||
|
||||
/* Loading States */
|
||||
.loading-skeleton {
|
||||
background: linear-gradient(90deg, var(--secondary-dark) 25%, var(--tertiary-dark) 50%, var(--secondary-dark) 75%);
|
||||
background-size: 200% 100%;
|
||||
animation: loading 1.5s infinite;
|
||||
}
|
||||
|
||||
@keyframes loading {
|
||||
0% {
|
||||
background-position: 200% 0;
|
||||
}
|
||||
100% {
|
||||
background-position: -200% 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Tooltips */
|
||||
.tooltip-inner {
|
||||
background-color: var(--tertiary-dark);
|
||||
color: var(--text-primary);
|
||||
border-radius: 4px;
|
||||
padding: 0.5rem 0.75rem;
|
||||
}
|
||||
|
||||
.tooltip.bs-tooltip-top .tooltip-arrow::before {
|
||||
border-top-color: var(--tertiary-dark);
|
||||
}
|
||||
|
||||
.tooltip.bs-tooltip-bottom .tooltip-arrow::before {
|
||||
border-bottom-color: var(--tertiary-dark);
|
||||
}
|
||||
|
||||
.tooltip.bs-tooltip-start .tooltip-arrow::before {
|
||||
border-left-color: var(--tertiary-dark);
|
||||
}
|
||||
|
||||
.tooltip.bs-tooltip-end .tooltip-arrow::before {
|
||||
border-right-color: var(--tertiary-dark);
|
||||
}
|
||||
381
static/js/app.js
Normal file
381
static/js/app.js
Normal file
@@ -0,0 +1,381 @@
|
||||
/*
|
||||
* Quantitative Trading Platform - Interactive Mockup
|
||||
* Main JavaScript for navigation and interactivity
|
||||
*/
|
||||
|
||||
// Global state
|
||||
const AppState = {
|
||||
currentSection: 'dashboard',
|
||||
charts: {},
|
||||
mockData: {}
|
||||
};
|
||||
|
||||
// Initialize the application
|
||||
function initApp() {
|
||||
console.log('Quantitative Trading Platform Mockup Initialized');
|
||||
|
||||
// Set up navigation
|
||||
setupNavigation();
|
||||
|
||||
// Load mock data
|
||||
loadMockData();
|
||||
|
||||
// Initialize charts
|
||||
initCharts();
|
||||
|
||||
// Show default section
|
||||
showSection('dashboard');
|
||||
|
||||
// Set up event listeners for interactive elements
|
||||
setupEventListeners();
|
||||
}
|
||||
|
||||
// Set up sidebar navigation
|
||||
function setupNavigation() {
|
||||
const navLinks = document.querySelectorAll('.nav-link[data-section]');
|
||||
|
||||
navLinks.forEach(link => {
|
||||
link.addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
const section = this.getAttribute('data-section');
|
||||
showSection(section);
|
||||
|
||||
// Update active state
|
||||
navLinks.forEach(l => l.classList.remove('active'));
|
||||
this.classList.add('active');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Show a specific section
|
||||
function showSection(sectionId) {
|
||||
// Hide all sections
|
||||
const sections = document.querySelectorAll('.section-content');
|
||||
sections.forEach(section => {
|
||||
section.classList.add('d-none');
|
||||
});
|
||||
|
||||
// Show the selected section
|
||||
const targetSection = document.getElementById(`${sectionId}-section`);
|
||||
if (targetSection) {
|
||||
targetSection.classList.remove('d-none');
|
||||
AppState.currentSection = sectionId;
|
||||
|
||||
// Update page title
|
||||
const sectionTitle = targetSection.querySelector('h1, h2')?.textContent || 'Quantitative Trading Platform';
|
||||
document.title = `${sectionTitle} - Mockup`;
|
||||
|
||||
// Refresh charts for the section if needed
|
||||
refreshSectionCharts(sectionId);
|
||||
}
|
||||
}
|
||||
|
||||
// Refresh charts for a specific section
|
||||
function refreshSectionCharts(sectionId) {
|
||||
switch(sectionId) {
|
||||
case 'dashboard':
|
||||
if (AppState.charts.portfolioChart) {
|
||||
updatePortfolioChart();
|
||||
}
|
||||
break;
|
||||
case 'data-management':
|
||||
if (AppState.charts.dataQualityChart) {
|
||||
updateDataQualityChart();
|
||||
}
|
||||
break;
|
||||
case 'strategy-engine':
|
||||
if (AppState.charts.backtestChart) {
|
||||
updateBacktestChart();
|
||||
}
|
||||
break;
|
||||
case 'risk-management':
|
||||
if (AppState.charts.riskChart) {
|
||||
updateRiskChart();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Set up event listeners for buttons and interactive elements
|
||||
function setupEventListeners() {
|
||||
// Refresh buttons
|
||||
const refreshButtons = document.querySelectorAll('button:contains("Refresh"), .btn-refresh, .btn-outline-light');
|
||||
refreshButtons.forEach(btn => {
|
||||
// Look for the refresh button specifically
|
||||
if (btn.querySelector('.bi-arrow-clockwise') || btn.textContent.includes('Refresh')) {
|
||||
btn.addEventListener('click', function() {
|
||||
// Fetch real market data from backend
|
||||
const symbol = 'AAPL'; // Default for now
|
||||
fetch(`/api/market-data/${symbol}`)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
// Update UI with real data
|
||||
updateDashboardWithRealData(data);
|
||||
showToast(`Data refreshed for ${symbol}`, 'success');
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error fetching data:', error);
|
||||
showToast('Failed to refresh data', 'danger');
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Form submissions
|
||||
const forms = document.querySelectorAll('form');
|
||||
forms.forEach(form => {
|
||||
form.addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
showToast('Settings saved successfully', 'success');
|
||||
});
|
||||
});
|
||||
|
||||
// Toggle buttons
|
||||
const toggleButtons = document.querySelectorAll('.btn[data-toggle]');
|
||||
toggleButtons.forEach(btn => {
|
||||
btn.addEventListener('click', function() {
|
||||
const target = this.getAttribute('data-toggle');
|
||||
const state = this.getAttribute('data-state');
|
||||
|
||||
if (target && state) {
|
||||
// Toggle state
|
||||
const newState = state === 'on' ? 'off' : 'on';
|
||||
this.setAttribute('data-state', newState);
|
||||
|
||||
// Update button appearance
|
||||
if (newState === 'on') {
|
||||
this.classList.remove('btn-outline-secondary');
|
||||
this.classList.add('btn-success');
|
||||
this.innerHTML = '<i class="bi bi-toggle-on me-1"></i> ON';
|
||||
} else {
|
||||
this.classList.remove('btn-success');
|
||||
this.classList.add('btn-outline-secondary');
|
||||
this.innerHTML = '<i class="bi bi-toggle-off me-1"></i> OFF';
|
||||
}
|
||||
|
||||
showToast(`Feature ${newState === 'on' ? 'enabled' : 'disabled'}`, 'info');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Tab clicks
|
||||
const tabs = document.querySelectorAll('[data-bs-toggle="tab"]');
|
||||
tabs.forEach(tab => {
|
||||
tab.addEventListener('shown.bs.tab', function() {
|
||||
const tabId = this.getAttribute('data-bs-target');
|
||||
console.log(`Tab activated: ${tabId}`);
|
||||
});
|
||||
});
|
||||
|
||||
// Simulate live data updates
|
||||
setInterval(updateLiveData, 5000);
|
||||
}
|
||||
|
||||
// Update live data (simulated)
|
||||
function updateLiveData() {
|
||||
if (AppState.currentSection === 'dashboard') {
|
||||
// Update metrics with small random changes
|
||||
updateDashboardMetrics();
|
||||
}
|
||||
}
|
||||
|
||||
// Update dashboard metrics with random changes
|
||||
function updateDashboardMetrics() {
|
||||
const metrics = {
|
||||
'total-pnl': { base: 42580, range: 500 },
|
||||
'max-drawdown': { base: 8420, range: 200 },
|
||||
'win-rate': { base: 64.8, range: 1.5 }
|
||||
};
|
||||
|
||||
for (const [id, config] of Object.entries(metrics)) {
|
||||
const element = document.getElementById(id);
|
||||
if (element) {
|
||||
const current = parseFloat(element.textContent.replace(/[^\d.-]/g, ''));
|
||||
const change = (Math.random() - 0.5) * 2 * config.range;
|
||||
const newValue = config.base + change;
|
||||
|
||||
// Format based on metric type
|
||||
if (id === 'total-pnl' || id === 'max-drawdown') {
|
||||
element.textContent = `$${Math.round(newValue).toLocaleString()}`;
|
||||
} else if (id === 'win-rate') {
|
||||
element.textContent = `${newValue.toFixed(1)}%`;
|
||||
}
|
||||
|
||||
// Add subtle animation
|
||||
element.classList.add('text-highlight');
|
||||
setTimeout(() => {
|
||||
element.classList.remove('text-highlight');
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function updateDashboardWithRealData(data) {
|
||||
// Update key metrics cards
|
||||
const metrics = data.metrics;
|
||||
|
||||
// Total P&L
|
||||
const pnlEl = document.querySelector('.card-title.text-success');
|
||||
if (pnlEl) pnlEl.textContent = `$${metrics.total_pnl.toLocaleString()}`;
|
||||
|
||||
// Max Drawdown
|
||||
const ddEl = document.querySelector('.card-title.text-danger');
|
||||
if (ddEl) ddEl.textContent = `$${metrics.max_drawdown.toLocaleString()}`;
|
||||
|
||||
// Win Rate
|
||||
const winEl = document.querySelector('.card-title.text-info');
|
||||
if (winEl) winEl.textContent = `${metrics.win_rate}%`;
|
||||
|
||||
// Update chart
|
||||
if (AppState.charts.portfolioChart) {
|
||||
AppState.charts.portfolioChart.data.labels = data.daily_pnl.map(d => d.date);
|
||||
AppState.charts.portfolioChart.data.datasets[0].data = data.daily_pnl.map(d => d.cumulative);
|
||||
AppState.charts.portfolioChart.update();
|
||||
}
|
||||
}
|
||||
|
||||
// Show toast notification
|
||||
function showToast(message, type = 'info') {
|
||||
// Create toast container if it doesn't exist
|
||||
let toastContainer = document.getElementById('toast-container');
|
||||
if (!toastContainer) {
|
||||
toastContainer = document.createElement('div');
|
||||
toastContainer.id = 'toast-container';
|
||||
toastContainer.className = 'toast-container position-fixed bottom-0 end-0 p-3';
|
||||
document.body.appendChild(toastContainer);
|
||||
}
|
||||
|
||||
// Create toast
|
||||
const toastId = 'toast-' + Date.now();
|
||||
const toast = document.createElement('div');
|
||||
toast.id = toastId;
|
||||
toast.className = `toast align-items-center text-bg-${type} border-0`;
|
||||
toast.setAttribute('role', 'alert');
|
||||
toast.setAttribute('aria-live', 'assertive');
|
||||
toast.setAttribute('aria-atomic', 'true');
|
||||
|
||||
toast.innerHTML = `
|
||||
<div class="d-flex">
|
||||
<div class="toast-body">
|
||||
${message}
|
||||
</div>
|
||||
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
|
||||
</div>
|
||||
`;
|
||||
|
||||
toastContainer.appendChild(toast);
|
||||
|
||||
// Initialize and show toast
|
||||
const bsToast = new bootstrap.Toast(toast, { delay: 3000 });
|
||||
bsToast.show();
|
||||
|
||||
// Remove toast after it's hidden
|
||||
toast.addEventListener('hidden.bs.toast', function() {
|
||||
toast.remove();
|
||||
});
|
||||
}
|
||||
|
||||
// Load mock data
|
||||
function loadMockData() {
|
||||
// Generate mock data for charts
|
||||
AppState.mockData = {
|
||||
portfolioData: generatePortfolioData(),
|
||||
dataQualityData: generateDataQualityData(),
|
||||
backtestData: generateBacktestData(),
|
||||
riskData: generateRiskData()
|
||||
};
|
||||
}
|
||||
|
||||
// Generate mock portfolio data
|
||||
function generatePortfolioData() {
|
||||
const data = [];
|
||||
let value = 100000;
|
||||
|
||||
for (let i = 0; i < 30; i++) {
|
||||
const date = new Date();
|
||||
date.setDate(date.getDate() - (30 - i));
|
||||
|
||||
// Random walk with drift
|
||||
const change = (Math.random() - 0.4) * 0.02 * value;
|
||||
value += change;
|
||||
|
||||
data.push({
|
||||
date: date.toLocaleDateString('en-US', { month: 'short', day: 'numeric' }),
|
||||
value: Math.max(90000, value)
|
||||
});
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
// Generate mock data quality data
|
||||
function generateDataQualityData() {
|
||||
const data = [];
|
||||
|
||||
for (let i = 0; i < 7; i++) {
|
||||
const date = new Date();
|
||||
date.setDate(date.getDate() - (7 - i));
|
||||
|
||||
data.push({
|
||||
date: date.toLocaleDateString('en-US', { weekday: 'short' }),
|
||||
completeness: 90 + Math.random() * 8,
|
||||
latency: 5 + Math.random() * 15,
|
||||
errors: Math.floor(Math.random() * 5)
|
||||
});
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
// Generate mock backtest data
|
||||
function generateBacktestData() {
|
||||
const strategies = ['Dual Momentum', 'Mean Reversion', 'Pairs Trading'];
|
||||
const data = [];
|
||||
|
||||
strategies.forEach(strategy => {
|
||||
let returns = 100;
|
||||
const returnsData = [];
|
||||
|
||||
for (let i = 0; i < 12; i++) {
|
||||
const monthlyReturn = (Math.random() - 0.2) * 0.1;
|
||||
returns *= (1 + monthlyReturn);
|
||||
returnsData.push(returns);
|
||||
}
|
||||
|
||||
data.push({
|
||||
strategy,
|
||||
returns: returnsData,
|
||||
sharpe: 0.8 + Math.random() * 1.5,
|
||||
winRate: 50 + Math.random() * 30
|
||||
});
|
||||
});
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
// Generate mock risk data
|
||||
function generateRiskData() {
|
||||
const metrics = ['VaR', 'CVaR', 'Max Drawdown', 'Volatility'];
|
||||
const data = [];
|
||||
|
||||
metrics.forEach(metric => {
|
||||
const values = [];
|
||||
for (let i = 0; i < 10; i++) {
|
||||
values.push(Math.random() * 10);
|
||||
}
|
||||
data.push({ metric, values });
|
||||
});
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
// Initialize when DOM is loaded
|
||||
document.addEventListener('DOMContentLoaded', initApp);
|
||||
|
||||
// Export for use in other scripts
|
||||
window.App = {
|
||||
showSection,
|
||||
showToast,
|
||||
refreshSectionCharts,
|
||||
state: AppState
|
||||
};
|
||||
414
static/js/mock-data.js
Normal file
414
static/js/mock-data.js
Normal file
@@ -0,0 +1,414 @@
|
||||
/*
|
||||
* Quantitative Trading Platform - Interactive Mockup
|
||||
* Mock data generation for charts and displays
|
||||
*/
|
||||
|
||||
// Chart initialization
|
||||
function initCharts() {
|
||||
// Initialize Portfolio Chart
|
||||
initPortfolioChart();
|
||||
|
||||
// Initialize Data Quality Chart
|
||||
initDataQualityChart();
|
||||
|
||||
// Initialize Backtest Chart
|
||||
initBacktestChart();
|
||||
|
||||
// Initialize Risk Chart
|
||||
initRiskChart();
|
||||
}
|
||||
|
||||
// Portfolio Performance Chart
|
||||
function initPortfolioChart() {
|
||||
const ctx = document.getElementById('portfolioChart');
|
||||
if (!ctx) return;
|
||||
|
||||
const data = generatePortfolioData();
|
||||
|
||||
AppState.charts.portfolioChart = new Chart(ctx, {
|
||||
type: 'line',
|
||||
data: {
|
||||
labels: data.map(d => d.date),
|
||||
datasets: [{
|
||||
label: 'Portfolio Value',
|
||||
data: data.map(d => d.value),
|
||||
borderColor: '#4caf50',
|
||||
backgroundColor: 'rgba(76, 175, 80, 0.1)',
|
||||
fill: true,
|
||||
tension: 0.4,
|
||||
pointRadius: 2,
|
||||
pointHoverRadius: 5
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false,
|
||||
plugins: {
|
||||
legend: {
|
||||
display: false
|
||||
},
|
||||
tooltip: {
|
||||
mode: 'index',
|
||||
intersect: false,
|
||||
callbacks: {
|
||||
label: function(context) {
|
||||
return `$${context.parsed.y.toLocaleString()}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
scales: {
|
||||
x: {
|
||||
grid: {
|
||||
color: 'rgba(255, 255, 255, 0.05)'
|
||||
},
|
||||
ticks: {
|
||||
color: '#b0bec5'
|
||||
}
|
||||
},
|
||||
y: {
|
||||
grid: {
|
||||
color: 'rgba(255, 255, 255, 0.05)'
|
||||
},
|
||||
ticks: {
|
||||
color: '#b0bec5',
|
||||
callback: function(value) {
|
||||
return '$' + (value / 1000).toFixed(0) + 'k';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Data Quality Chart
|
||||
function initDataQualityChart() {
|
||||
const ctx = document.getElementById('dataQualityChart');
|
||||
if (!ctx) return;
|
||||
|
||||
const data = generateDataQualityData();
|
||||
|
||||
AppState.charts.dataQualityChart = new Chart(ctx, {
|
||||
type: 'line',
|
||||
data: {
|
||||
labels: data.map(d => d.date),
|
||||
datasets: [
|
||||
{
|
||||
label: 'Completeness (%)',
|
||||
data: data.map(d => d.completeness),
|
||||
borderColor: '#4caf50',
|
||||
backgroundColor: 'rgba(76, 175, 80, 0.1)',
|
||||
fill: true,
|
||||
tension: 0.4,
|
||||
yAxisID: 'y'
|
||||
},
|
||||
{
|
||||
label: 'Latency (ms)',
|
||||
data: data.map(d => d.latency),
|
||||
borderColor: '#2196f3',
|
||||
backgroundColor: 'rgba(33, 150, 243, 0.1)',
|
||||
fill: true,
|
||||
tension: 0.4,
|
||||
yAxisID: 'y1'
|
||||
}
|
||||
]
|
||||
},
|
||||
options: {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false,
|
||||
plugins: {
|
||||
legend: {
|
||||
position: 'top',
|
||||
labels: {
|
||||
color: '#b0bec5'
|
||||
}
|
||||
}
|
||||
},
|
||||
scales: {
|
||||
x: {
|
||||
grid: {
|
||||
color: 'rgba(255, 255, 255, 0.05)'
|
||||
},
|
||||
ticks: {
|
||||
color: '#b0bec5'
|
||||
}
|
||||
},
|
||||
y: {
|
||||
type: 'linear',
|
||||
display: true,
|
||||
position: 'left',
|
||||
min: 80,
|
||||
max: 100,
|
||||
grid: {
|
||||
color: 'rgba(255, 255, 255, 0.05)'
|
||||
},
|
||||
ticks: {
|
||||
color: '#b0bec5',
|
||||
callback: function(value) {
|
||||
return value + '%';
|
||||
}
|
||||
}
|
||||
},
|
||||
y1: {
|
||||
type: 'linear',
|
||||
display: true,
|
||||
position: 'right',
|
||||
min: 0,
|
||||
max: 30,
|
||||
grid: {
|
||||
drawOnChartArea: false
|
||||
},
|
||||
ticks: {
|
||||
color: '#b0bec5',
|
||||
callback: function(value) {
|
||||
return value + 'ms';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Backtest Results Chart
|
||||
function initBacktestChart() {
|
||||
const ctx = document.getElementById('backtestChart');
|
||||
if (!ctx) return;
|
||||
|
||||
const data = generateBacktestData();
|
||||
|
||||
AppState.charts.backtestChart = new Chart(ctx, {
|
||||
type: 'line',
|
||||
data: {
|
||||
labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
|
||||
datasets: data.map((strategy, index) => {
|
||||
const colors = ['#4caf50', '#2196f3', '#9c27b0'];
|
||||
return {
|
||||
label: strategy.strategy,
|
||||
data: strategy.returns,
|
||||
borderColor: colors[index],
|
||||
backgroundColor: colors[index] + '20',
|
||||
fill: false,
|
||||
tension: 0.4
|
||||
};
|
||||
})
|
||||
},
|
||||
options: {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false,
|
||||
plugins: {
|
||||
legend: {
|
||||
position: 'top',
|
||||
labels: {
|
||||
color: '#b0bec5'
|
||||
}
|
||||
}
|
||||
},
|
||||
scales: {
|
||||
x: {
|
||||
grid: {
|
||||
color: 'rgba(255, 255, 255, 0.05)'
|
||||
},
|
||||
ticks: {
|
||||
color: '#b0bec5'
|
||||
}
|
||||
},
|
||||
y: {
|
||||
grid: {
|
||||
color: 'rgba(255, 255, 255, 0.05)'
|
||||
},
|
||||
ticks: {
|
||||
color: '#b0bec5',
|
||||
callback: function(value) {
|
||||
return '$' + value.toLocaleString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Risk Management Chart
|
||||
function initRiskChart() {
|
||||
const ctx = document.getElementById('riskChart');
|
||||
if (!ctx) return;
|
||||
|
||||
const data = generateRiskData();
|
||||
|
||||
AppState.charts.riskChart = new Chart(ctx, {
|
||||
type: 'radar',
|
||||
data: {
|
||||
labels: data.map(d => d.metric),
|
||||
datasets: [{
|
||||
label: 'Risk Metrics',
|
||||
data: data.map(d => d.values[0]),
|
||||
backgroundColor: 'rgba(255, 152, 0, 0.2)',
|
||||
borderColor: 'rgba(255, 152, 0, 1)',
|
||||
pointBackgroundColor: 'rgba(255, 152, 0, 1)',
|
||||
pointBorderColor: '#fff',
|
||||
pointHoverBackgroundColor: '#fff',
|
||||
pointHoverBorderColor: 'rgba(255, 152, 0, 1)'
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false,
|
||||
plugins: {
|
||||
legend: {
|
||||
display: false
|
||||
}
|
||||
},
|
||||
scales: {
|
||||
r: {
|
||||
angleLines: {
|
||||
color: 'rgba(255, 255, 255, 0.1)'
|
||||
},
|
||||
grid: {
|
||||
color: 'rgba(255, 255, 255, 0.1)'
|
||||
},
|
||||
pointLabels: {
|
||||
color: '#b0bec5'
|
||||
},
|
||||
ticks: {
|
||||
color: '#b0bec5',
|
||||
backdropColor: 'transparent'
|
||||
},
|
||||
min: 0,
|
||||
max: 10
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Update functions for live data
|
||||
function updatePortfolioChart() {
|
||||
if (!AppState.charts.portfolioChart) return;
|
||||
|
||||
const newData = generatePortfolioData();
|
||||
AppState.charts.portfolioChart.data.labels = newData.map(d => d.date);
|
||||
AppState.charts.portfolioChart.data.datasets[0].data = newData.map(d => d.value);
|
||||
AppState.charts.portfolioChart.update('none');
|
||||
}
|
||||
|
||||
function updateDataQualityChart() {
|
||||
if (!AppState.charts.dataQualityChart) return;
|
||||
|
||||
const newData = generateDataQualityData();
|
||||
AppState.charts.dataQualityChart.data.labels = newData.map(d => d.date);
|
||||
AppState.charts.dataQualityChart.data.datasets[0].data = newData.map(d => d.completeness);
|
||||
AppState.charts.dataQualityChart.data.datasets[1].data = newData.map(d => d.latency);
|
||||
AppState.charts.dataQualityChart.update('none');
|
||||
}
|
||||
|
||||
function updateBacktestChart() {
|
||||
if (!AppState.charts.backtestChart) return;
|
||||
|
||||
const newData = generateBacktestData();
|
||||
newData.forEach((strategy, index) => {
|
||||
AppState.charts.backtestChart.data.datasets[index].data = strategy.returns;
|
||||
});
|
||||
AppState.charts.backtestChart.update('none');
|
||||
}
|
||||
|
||||
function updateRiskChart() {
|
||||
if (!AppState.charts.riskChart) return;
|
||||
|
||||
const newData = generateRiskData();
|
||||
AppState.charts.riskChart.data.datasets[0].data = newData.map(d => d.values[0]);
|
||||
AppState.charts.riskChart.update('none');
|
||||
}
|
||||
|
||||
// Data generation functions (same as in app.js but exported for use)
|
||||
function generatePortfolioData() {
|
||||
const data = [];
|
||||
let value = 100000;
|
||||
|
||||
for (let i = 0; i < 30; i++) {
|
||||
const date = new Date();
|
||||
date.setDate(date.getDate() - (30 - i));
|
||||
|
||||
const change = (Math.random() - 0.4) * 0.02 * value;
|
||||
value += change;
|
||||
|
||||
data.push({
|
||||
date: date.toLocaleDateString('en-US', { month: 'short', day: 'numeric' }),
|
||||
value: Math.max(90000, value)
|
||||
});
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function generateDataQualityData() {
|
||||
const data = [];
|
||||
|
||||
for (let i = 0; i < 7; i++) {
|
||||
const date = new Date();
|
||||
date.setDate(date.getDate() - (7 - i));
|
||||
|
||||
data.push({
|
||||
date: date.toLocaleDateString('en-US', { weekday: 'short' }),
|
||||
completeness: 90 + Math.random() * 8,
|
||||
latency: 5 + Math.random() * 15,
|
||||
errors: Math.floor(Math.random() * 5)
|
||||
});
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function generateBacktestData() {
|
||||
const strategies = ['Dual Momentum', 'Mean Reversion', 'Pairs Trading'];
|
||||
const data = [];
|
||||
|
||||
strategies.forEach(strategy => {
|
||||
let returns = 100;
|
||||
const returnsData = [];
|
||||
|
||||
for (let i = 0; i < 12; i++) {
|
||||
const monthlyReturn = (Math.random() - 0.2) * 0.1;
|
||||
returns *= (1 + monthlyReturn);
|
||||
returnsData.push(returns);
|
||||
}
|
||||
|
||||
data.push({
|
||||
strategy,
|
||||
returns: returnsData,
|
||||
sharpe: 0.8 + Math.random() * 1.5,
|
||||
winRate: 50 + Math.random() * 30
|
||||
});
|
||||
});
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function generateRiskData() {
|
||||
const metrics = ['VaR', 'CVaR', 'Max Drawdown', 'Volatility'];
|
||||
const data = [];
|
||||
|
||||
metrics.forEach(metric => {
|
||||
const values = [];
|
||||
for (let i = 0; i < 10; i++) {
|
||||
values.push(Math.random() * 10);
|
||||
}
|
||||
data.push({ metric, values });
|
||||
});
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
// Export for use in other scripts
|
||||
window.MockData = {
|
||||
initCharts,
|
||||
updatePortfolioChart,
|
||||
updateDataQualityChart,
|
||||
updateBacktestChart,
|
||||
updateRiskChart,
|
||||
generatePortfolioData,
|
||||
generateDataQualityData,
|
||||
generateBacktestData,
|
||||
generateRiskData
|
||||
};
|
||||
Reference in New Issue
Block a user