High-performance C++ equity risk analytics engine with real-time WebSocket streaming and live web dashboard. Compute 95% Value-at-Risk, Black-Scholes Greeks, and portfolio metrics with sub-millisecond latency.
riskcore-cpp delivers institutional-grade portfolio risk analytics:
- 95% Historical VaR (1-day, per position and portfolio)
- Black-Scholes Greeks (delta, gamma, vega, theta for ATM options)
- Sharpe Ratio (annualized with 4.5% risk-free rate)
- Variance-Covariance Portfolio VaR with Pearson correlation matrix
- Real-time Dashboard with 4 interactive chart panels and live metrics
graph LR
A["Market Data<br/>yfinance"] --> B["Data Loader<br/>CSV/JSON"]
B --> C["Risk Engine<br/>C++20"]
C --> D["WebSocket Server<br/>BSD Sockets"]
D --> E["Web Dashboard<br/>Chart.js"]
C --> F["JSON Output<br/>--run mode"]
style C fill:#0099cc
style D fill:#00cc88
style E fill:#ff5555
sequenceDiagram
participant Market as Market Data
participant Engine as Risk Engine
participant Calc as Calculations
participant WS as WebSocket
participant UI as Dashboard
Market->>Engine: Load positions + returns
Engine->>Calc: VaR, Greeks, Sharpe, Correlation
Calc->>Engine: Results (2ms typical)
Engine->>WS: Broadcast JSON
WS->>UI: WebSocket frame
UI->>UI: Update 4 charts + metrics
| Feature | Details |
|---|---|
| Risk Metrics | VaR 95%, Greeks, Sharpe, correlation, P&L tracking |
| Performance | Sub-millisecond computation, 60-tick rolling history |
| Real-time Updates | 2-second refresh cycle via WebSocket |
| Interactive UI | Dark theme, responsive layout, 4 live charts |
| Data Pipeline | yfinance → CSV/JSON → C++ engine |
| Portability | C++20, zero external math libraries, STL only |
brew install cmake libwebsockets pkg-config openssl
curl -LsSf https://astral.sh/uv/install.sh | shgit clone https://github.com/nim444/riskcore-cpp.git && cd riskcore-cpp
# Fetch market data
uv run scripts/fetch_data.py
# Build
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --parallel
# Single computation (JSON output)
./build/riskcore --run
# Live dashboard (2 terminals):
# Terminal 1:
./build/riskcore --serve
# Terminal 2:
python3 -m http.server 8000 --directory web
# Open http://localhost:8000- Portfolio VaR Trend — 60-point rolling window with dynamic Y-axis zoom
- Sharpe Rolling — Real-time ratio with 0.5 target reference line
- VaR Heatmap — Per-ticker risk sorted by impact (4-tier colour contrast)
- P&L Analysis — Dollar or percentage mode toggle (all 8 positions readable)
| Layer | Technology |
|---|---|
| Core | C++20, STL algorithms, BSD sockets |
| Build | CMake 3.20+, clang++ (Apple Silicon) |
| Backend | libwebsockets, OpenSSL, nlohmann/json |
| Frontend | Vanilla JS, Chart.js, CSS3 |
| Data | Python, yfinance, uv |
Edit scripts/fetch_data.py:
tickers = ["IBM", "GOOG", "NVDA", "MSFT", "AAPL", "TSLA", "AMZN", "META", "YOUR_TICKER"]
position_config = {"YOUR_TICKER": {"side": "LONG", "quantity": 1000}}Then: uv run scripts/fetch_data.py && cmake --build build --parallel && ./build/riskcore --serve
./build/riskcore --run # Compute once, output JSON
./build/riskcore --serve # Start WebSocket server (port 8080)
./build/riskcore --version # Show version- Distributed Architecture Extension — Design for multi-node risk computation and federated analytics
| Issue | Solution |
|---|---|
| WebSocket won't connect | Ensure ./build/riskcore --serve is running on port 8080 |
| Dashboard shows "undefined" | Verify web server runs on port 8000 |
| Port conflict | lsof -i :8080 to find process |
| $0 prices | Run uv run scripts/fetch_data.py to fetch data |
MIT License – See LICENSE file
