Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ repos:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
args: ['--allow-multiple-documents']
- id: check-added-large-files
- id: check-merge-conflict
- id: mixed-line-ending
Expand Down
64 changes: 63 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,12 @@ set(EXCHANGE_SOURCES
# exchange/fix/InteractiveBrokersFixConnector.cpp
)

# Risk management library files
set(RISK_SOURCES
core/risk/RiskManager.cpp core/risk/CircuitBreaker.cpp
core/risk/VaREngine.cpp core/risk/AlertManager.cpp
core/risk/DisasterRecovery.cpp)

# Create core library
add_library(core STATIC ${CORE_SOURCES})
target_link_libraries(
Expand All @@ -233,9 +239,21 @@ target_link_libraries(
spdlog::spdlog
fmt::fmt)

# Create risk library
add_library(risk STATIC ${RISK_SOURCES})
target_link_libraries(
risk
PUBLIC core
Threads::Threads
Boost::system
Boost::filesystem
nlohmann_json::nlohmann_json
spdlog::spdlog
fmt::fmt)

# Create strategy library
add_library(strategy STATIC ${STRATEGY_SOURCES})
target_link_libraries(strategy PUBLIC core Threads::Threads Boost::system
target_link_libraries(strategy PUBLIC core risk Threads::Threads Boost::system
Boost::filesystem)

# Create exchange library
Expand Down Expand Up @@ -271,6 +289,7 @@ if(BUILD_VISUALIZATION)
target_link_libraries(
visualization
PUBLIC core
risk
strategy
Threads::Threads
Boost::system
Expand All @@ -294,12 +313,14 @@ if(BUILD_VISUALIZATION)
endif()
set(PINNACLEMM_LIBS
core
risk
strategy
exchange
Threads::Threads
Boost::system
Boost::filesystem
Boost::program_options
nlohmann_json::nlohmann_json
spdlog::spdlog
fmt::fmt)

Expand Down Expand Up @@ -431,6 +452,42 @@ if(BUILD_TESTS)
add_executable(routing_test tests/routing_test.cpp)
target_link_libraries(routing_test core exchange Threads::Threads fmt::fmt)
add_test(NAME RoutingTests COMMAND routing_test)

# Risk Manager tests
add_executable(risk_manager_tests tests/unit/RiskManagerTests.cpp)
target_link_libraries(risk_manager_tests core risk GTest::gtest_main
GTest::gtest Threads::Threads)
add_test(NAME RiskManagerTests COMMAND risk_manager_tests)

# Circuit Breaker tests
add_executable(circuit_breaker_tests tests/unit/CircuitBreakerTests.cpp)
target_link_libraries(circuit_breaker_tests core risk GTest::gtest_main
GTest::gtest Threads::Threads)
add_test(NAME CircuitBreakerTests COMMAND circuit_breaker_tests)

# VaR Engine tests
add_executable(var_engine_tests tests/unit/VaREngineTests.cpp)
target_link_libraries(var_engine_tests core risk GTest::gtest_main
GTest::gtest Threads::Threads)
add_test(NAME VaREngineTests COMMAND var_engine_tests)

# Alert Manager tests
add_executable(alert_manager_tests tests/unit/AlertManagerTests.cpp)
target_link_libraries(alert_manager_tests core risk GTest::gtest_main
GTest::gtest Threads::Threads)
add_test(NAME AlertManagerTests COMMAND alert_manager_tests)

# Disaster Recovery tests
add_executable(disaster_recovery_tests tests/unit/DisasterRecoveryTests.cpp)
target_link_libraries(
disaster_recovery_tests
core
risk
GTest::gtest_main
GTest::gtest
Threads::Threads
Boost::filesystem)
add_test(NAME DisasterRecoveryTests COMMAND disaster_recovery_tests)
endif()

# Benchmarks
Expand Down Expand Up @@ -496,6 +553,11 @@ if(BUILD_BENCHMARKS)
tests/performance/BacktestingBenchmark.cpp)
target_link_libraries(backtesting_benchmark core strategy
benchmark::benchmark Threads::Threads)

# Risk check benchmarks
add_executable(risk_check_benchmark tests/performance/RiskCheckBenchmark.cpp)
target_link_libraries(risk_check_benchmark core risk benchmark::benchmark
Threads::Threads)
endif()

# Install targets
Expand Down
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,16 @@ WORKDIR /app
COPY --from=builder /app/build/pinnaclemm /app/
COPY --from=builder /app/config/ /app/config/

# Create logs and data directories
RUN mkdir -p /app/logs /app/data /app/data/backups

# Set environment variables
ENV LD_LIBRARY_PATH=/usr/local/lib

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
CMD curl -f http://localhost:8081/api/health || exit 1
Comment thread
coderabbitai[bot] marked this conversation as resolved.

# Default command
ENTRYPOINT ["/app/pinnaclemm"]
CMD ["--mode", "simulation", "--symbol", "BTC-USD", "--verbose"]
34 changes: 31 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ PinnacleMM is a high-performance, production-grade market making system designed
- **Advanced Backtesting**: Historical data replay with Monte Carlo analysis and A/B testing
- **Real-Time Visualization**: Professional web dashboard with live performance monitoring (access at `visualization/static/index.html` when running with `--enable-visualization`)
- **Structured Data Export**: JSON Lines (JSONL) logging for market data, strategy metrics, and trading events with `--json-log` flag
- **Risk Management**: Pre-trade risk checks (~750ns), position/exposure limits, drawdown tracking, daily loss limits, and auto-hedging
- **Circuit Breaker**: Automatic market halt on rapid price moves, spread widening, volume spikes, latency degradation, or crisis regime detection
- **Real-Time VaR**: Value at Risk using historical, parametric, and Monte Carlo (10K simulations) methods with lock-free double-buffered reads
- **Alerting System**: 16 alert types with throttling, severity levels, and WebSocket delivery to the dashboard
- **Disaster Recovery**: Atomic risk state persistence, position reconciliation, and labeled backup management
- **Kubernetes Deployment**: Production-ready StatefulSet with health probes, PVC, network policies, and pod disruption budget
- **Enterprise Security**: AES-256-CBC encryption with unique salts, 100,000 PBKDF2 iterations, secure password input, comprehensive input validation, audit logging, rate limiting, and certificate pinning
- **Comprehensive Testing**: Extensive test suite ensuring reliability and performance

Expand All @@ -53,6 +59,7 @@ PinnacleMM is a high-performance, production-grade market making system designed
PinnacleMM follows a modular, layered architecture:

- **Core Engine Layer**: Ultra-low latency components handling order book and execution
- **Risk Layer**: Pre-trade checks, circuit breaker, VaR engine, alerting, and disaster recovery
- **Strategy Layer**: Pluggable strategies for different market making approaches
- **Exchange Layer**: Multi-protocol connectivity (WebSocket, FIX) with simulation capabilities
- **Persistence Layer**: Memory-mapped file system for crash recovery
Expand Down Expand Up @@ -116,7 +123,6 @@ make -j$(sysctl -n hw.ncpu) # macOS
```

### Script Features Comparison
> **Note**: I will update later on after completing phase 4 and 5, cleaning up the code and getting PinnacleMM ready for optimization and production deployment.

| Feature | Native Script (`scripts/run-native.sh`) | Docker Script (`scripts/run-docker.sh`) |
|---------|-----------------------------------|-----------------------------------|
Expand Down Expand Up @@ -413,6 +419,11 @@ docker run -it --name pinnaclemm-live \

- **Order Book Engine**: Ultra-fast matching engine with lock-free operations
- **Market Making Strategy**: Adaptive pricing based on market conditions
- **Risk Manager**: Lock-free pre-trade risk checks with position, exposure, and loss limits
- **Circuit Breaker**: Market circuit breaker with 8 triggers and automatic recovery
- **VaR Engine**: Real-time Value at Risk with Monte Carlo simulations on a background thread
- **Alert Manager**: Alerting system with throttling and real-time WebSocket delivery
- **Disaster Recovery**: Atomic state persistence, position reconciliation, and backup management
- **ML Spread Optimization**: Neural network-based spread prediction with ~1-2μs latency
- **Order Book Flow Analyzer**: Real-time analysis of order flow patterns and market microstructure
- **Market Impact Predictor**: Advanced models for predicting price impact of trades
Expand All @@ -432,7 +443,12 @@ docker run -it --name pinnaclemm-live \
- [API Reference](docs/api/reference.md)
- [Project Roadmap](docs/ROADMAP.md)

### Advanced Features (Phase 3 - All Complete)
### Risk Management & Production
- [Risk Management](docs/RISK_MANAGEMENT.md) - **Pre-trade checks, VaR, circuit breaker, alerting**
- [Disaster Recovery](docs/DISASTER_RECOVERY.md) - **Operational runbook for crash recovery and backups**
- [Kubernetes Deployment](docs/KUBERNETES_DEPLOYMENT.md) - **Production K8s deployment guide**

### Advanced Features (ML)
- [ML Spread Optimization](docs/ML_SPREAD_OPTIMIZATION.md) - **Neural network-based spread prediction**
- [Order Book Flow Analysis](docs/ORDER_BOOK_FLOW_ANALYSIS.md) - **Real-time market microstructure analysis**
- [Market Impact Prediction](docs/MARKET_IMPACT_PREDICTION.md) - **Advanced trade impact modeling**
Expand Down Expand Up @@ -488,7 +504,7 @@ The PinnacleMM system includes a professional web-based dashboard for real-time
- **Strategy Controls**: Multiple strategy monitoring and comparison
- **Market Regime Visualization**: Real-time regime detection with confidence indicators
- **ML Metrics Panel**: Model accuracy, prediction latency, and retrain statistics
- **Risk Analysis**: VaR calculations, drawdown analysis, and risk metrics
- **Risk Analysis**: Real-time VaR (historical, parametric, Monte Carlo), circuit breaker status, position/exposure limits, drawdown tracking, and alerting

### Technical Details
- **Frontend**: HTML5/CSS3/JavaScript with Chart.js and D3.js
Expand All @@ -515,6 +531,8 @@ open build/test_dashboard.html
- [Interactive Brokers Setup](docs/IB_TESTING_GUIDE.md)

### System Administration
- [Kubernetes Deployment](docs/KUBERNETES_DEPLOYMENT.md)
- [Disaster Recovery Runbook](docs/DISASTER_RECOVERY.md)
- [Persistence System](docs/architecture/persistence.md)
- [Recovery Guide](docs/user_guide/recovery.md)
- [Security & API Key Management](docs/security/credentials.md)
Expand All @@ -541,6 +559,8 @@ PinnacleMM achieves exceptional performance metrics:

- **Order Book Update Latency**: <1 μs (microsecond)
- **Order Execution Latency**: <50 μs (end-to-end)
- **Pre-Trade Risk Check**: ~750ns (lock-free, 8 sequential checks)
- **Circuit Breaker Check**: ~5ns (single atomic load)
- **ML Prediction Latency**: 1-3 μs (neural network inference)
- **Throughput**: 100,000+ messages per second
- **Recovery Time**: <5 seconds for full system recovery
Expand Down Expand Up @@ -570,6 +590,14 @@ cd build
# ✓ Multi-venue execution with 1ms latency
# ✓ 8 completed fills across multiple strategies

# Test risk management components (Phase 4)
./risk_manager_tests # 11 tests - pre-trade checks, position limits
./circuit_breaker_tests # 10 tests - state machine, triggers
./var_engine_tests # 8 tests - VaR calculations
./alert_manager_tests # 8 tests - alerting, throttling
./disaster_recovery_tests # 8 tests - state persistence, backups
./risk_check_benchmark # Risk check latency benchmarks

# Memory safety validation with Address Sanitizer (development builds)
cmake -DCMAKE_BUILD_TYPE=Debug -DENABLE_SANITIZERS=ON .. && make -j8
./pinnaclemm --mode simulation --symbol BTC-USD --verbose
Expand Down
42 changes: 42 additions & 0 deletions config/default_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,47 @@
"snapshotIntervalMin": 15,
"keepSnapshots": 5,
"compactionThreshold": 1000000
},
"risk_management": {
"limits": {
"max_position_size": 10.0,
"max_notional_exposure": 1000000.0,
"max_net_exposure": 500000.0,
"max_gross_exposure": 2000000.0,
"max_drawdown_pct": 5.0,
"daily_loss_limit": 10000.0,
"max_order_size": 1.0,
"max_order_value": 50000.0,
"max_daily_volume": 100.0,
"max_orders_per_second": 100
},
"circuit_breaker": {
"price_move_1min_pct": 2.0,
"price_move_5min_pct": 5.0,
"spread_widen_multiplier": 3.0,
"volume_spike_multiplier": 5.0,
"cooldown_period_ms": 30000,
"half_open_test_duration_ms": 10000,
"max_latency_us": 10000,
"price_history_size": 300
},
"var": {
"window_size": 252,
"simulation_count": 10000,
"horizon": 1.0,
"update_interval_ms": 60000,
"var_limit_pct": 2.0
},
"auto_hedge": {
"enabled": false,
"threshold_pct": 50.0,
"interval_ms": 5000
},
"alerts": {
"min_interval_ms": 5000,
"max_history": 1000,
"warning_threshold_pct": 80.0,
"critical_threshold_pct": 100.0
}
}
}
Loading
Loading