[FEATURE] Complete BacktestEngine strategy integration stubs
- Dominant language
- C++
- Stars
- 14
- Forks
- 12
- Avg merge
- 1h 27m
- Merged PRs (30d)
- 3
Description
## Description
The `BacktestEngine` has three incomplete stub implementations that prevent full strategy integration during backtesting.
## Current Stubs
### 1. `processMarketData()` - Line 592-601
```cpp
void BacktestEngine::processMarketData(const MarketDataPoint& data) {
m_analyzer->recordMarketData(data);
// Update strategy with new market data (if strategy supports it)
if (m_strategy) {
// Note: I would need to add a method to update market data in the strategy
// m_strategy->updateMarketData(data);
}
}
```
Issue: Strategy doesn't receive market data updates during backtest
### 2. `processStrategyOrders()` - Line 603-616
```cpp
void BacktestEngine::processStrategyOrders() {
// This is a simplified implementation
// In a real implementation, we would:
// 1. Get orders from the strategy
// 2. Validate orders against risk limits
// 3. Execute orders with simulated market impact
// 4. Update strategy with fill information
if (m_strategy && m_currentTime % 5000000000ULL == 0) { // Every 5 seconds
// Simulate strategy generating orders
// This would be replaced with actual strategy integration
}
}
```
Issue: No actual order processing from strategy
### 3. `updatePortfolio()` - Line 618-626
```cpp
void BacktestEngine::updatePortfolio(const MarketDataPoint& data) {
if (m_position != 0.0) {
// Simplified P&L calculation
// In practice, this would be more sophisticated
double markToMarket = m_position * data.price;
m_unrealizedPnL = markToMarket; // Simplified - would need cost basis
}
}
```
Issue: Simplified P&L calculation without cost basis tracking
### 4. `calculatePerformance()` - Line 628-635
```cpp
void BacktestEngine::calculatePerformance() {
createSnapshot();
// Add to analyzer
// Note: PerformanceAnalyzer would need a method to add snapshots
// m_analyzer->addSnapshot(snapshot);
}
```
Issue: Snapshots created but not stored in analyzer
## Expected Behavior
`processMarketData()`
- Add updateMarketData() method to MLEnhancedMarketMaker
- Feed market data to strategy for decision making
- Update strategy's internal state
`processStrategyOrders()`
- Get pending orders from strategy
- Validate against risk limits (max position, drawdown)
- Simulate execution with slippage and market impact
- Update fills and notify strategy
`updatePortfolio()`
- Track cost basis for positions
- Calculate realized P&L on trades
- Calculate unrealized P&L from mark-to-market
- Update balance accurately
`calculatePerformance()`
- Add addSnapshot() method to PerformanceAnalyzer
- Store performance snapshots for historical analysis
- Enable performance charting
## Implementation Tasks
I have to:
1. Add strategy interface methods for backtest integration
2. Implement order validation and execution simulation
3. Add cost basis tracking for accurate P&L
4. Implement snapshot storage in PerformanceAnalyzer
#### Affected Files
- strategies/backtesting/BacktestEngine.cpp
- strategies/backtesting/BacktestEngine.h
- strategies/basic/MLEnhancedMarketMaker.h (add interface methods)
- strategies/backtesting/PerformanceAnalyzer.h (add snapshot storage)
Contributor guide
Assessment
This issue has not been assessed yet.