| # Architecture |
|
|
| This document describes the system architecture of the Quantum Hybrid Portfolio optimization platform. |
|
|
| ## Overview |
|
|
| The system consists of: |
|
|
| 1. **Backend API** (`api.py`) β Flask REST API, optimization, backtest, market data |
| 2. **Frontend** (`frontend/`) β React dashboard (EnhancedQuantumDashboard.js) |
| 3. **Core** (`core/quantum_inspired/`) β QSW optimizer, graph builder, evolution dynamics |
| 4. **Services** (`services/`) β Market data, backtest, portfolio optimizer |
|
|
| ## Data Flow |
|
|
| ``` |
| βββββββββββββββββββ HTTP βββββββββββββββββββ Python ββββββββββββββββββββ |
| β React Dashboard β ββββββββββββΊ β Flask API β ββββββββββββββΊ β QSW Optimizer β |
| β (port 3000) β proxy β (port 5000) β services β (core/) β |
| βββββββββββββββββββ ββββββββββ¬βββββββββ ββββββββββββββββββββ |
| β |
| β yfinance / cache |
| βΌ |
| βββββββββββββββββββ |
| β Market Data β |
| β (services/) β |
| βββββββββββββββββββ |
| ``` |
|
|
| ## Backend |
|
|
| ### API Layer (`api.py`) |
|
|
| - CORS enabled for frontend |
| - Optional `X-API-Key` authentication |
| - Structured JSON logging |
| - Prometheus metrics (`/metrics`) |
| - In-memory market data cache (TTL configurable) |
|
|
| ### Services |
|
|
| - **market_data** β Fetches prices via yfinance, returns covariance and returns |
| - **backtest** β Runs backtest with rebalancing, computes metrics |
| - **portfolio_optimizer** β Wraps QSW optimizer, applies constraints and presets |
|
|
| ### Core |
|
|
| - **quantum_walk.py** β QuantumStochasticWalkOptimizer (main QSW algorithm) |
| - **graph_builder.py** β Financial graph from returns/covariance |
| - **evolution_dynamics.py** β Quantum evolution (continuous, discrete, etc.) |
| - **stability_enhancer.py** β Turnover reduction |
|
|
| ## Frontend |
|
|
| ### Structure |
|
|
| - **App.js** β Entry, ErrorBoundary, ToastContainer |
| - **EnhancedQuantumDashboard.js** β Main dashboard (state, tabs, layout) |
| - **components/dashboard/** β Slider, MetricCard, TabButton, SectionTitle, RegimeSelector, etc. |
| - **lib/simulationEngine.js** β Synthetic market data, simulation optimization |
| - **services/api.js** β Axios client for backend API |
|
|
| ### State |
|
|
| - Data source (api vs sim) |
| - Omega, evolution time, regime, evolution method, objective |
| - Constraints, tickers, dates |
| - Optimization result, backtest result, sensitivity data |
| - Active tab, metrics view (optimization vs backtest) |
|
|
| ### API vs Simulation |
|
|
| - **API:** Calls `/api/portfolio/optimize`, `/api/market-data`, `/api/portfolio/backtest` |
| - **Simulation:** Uses `lib/simulationEngine.js` to generate data and run QSW locally |
|
|
| ## Configuration |
|
|
| - **config/qsw_config.py** β Omega, evolution time, turnover, weights |
| - **config/production_config.py** β Production settings (if used) |
| - **Environment** β FLASK_ENV, LOG_LEVEL, CACHE_TTL, API_KEY, etc. |
|
|
| ## Deployment |
|
|
| - **Docker** β Dockerfile and docker-compose for containerized run |
| - **Production** β JWT auth, rate limiting, Redis, PostgreSQL (see PRODUCTION_READINESS_PLAN.md) |
|
|
| --- |
|
|
| *Last updated: 2026-02* |
|
|