market-data-source 0.3.0

High-performance synthetic market data generator with financial precision. Generate unlimited OHLC candles, tick data, and realistic trading scenarios for backtesting and research.
Documentation
# PRP-43: Tick Aggregation Engine

## Context & Motivation

**Integration Goal**: Convert high-frequency tick data into various aggregated formats (time bars, volume bars, dollar bars).

**User Requirement**: Flexible aggregation of tick data for different analysis timeframes and methods.

**Technical Challenge**: Efficiently aggregate millions of ticks while supporting multiple aggregation types.

## Requirements

### Aggregation Types
1. **Time Bars**: Fixed time intervals (1min, 5min, etc.)
2. **Volume Bars**: Fixed volume thresholds
3. **Dollar Bars**: Fixed value traded
4. **Tick Bars**: Fixed number of ticks

### Aggregation Features
1. **Streaming Aggregation**: Real-time bar formation
2. **OHLCV Calculation**: Accurate OHLC from ticks
3. **VWAP Tracking**: Volume-weighted average price
4. **Statistics**: Additional metrics per bar

## Implementation Blueprint

### Phase 1: Aggregation Framework
1. Create `src/aggregation/mod.rs`
2. Define `Aggregator` trait
3. Implement time-based aggregation
4. Add OHLC calculation logic

### Phase 2: Alternative Bars
1. Implement volume bars
2. Add dollar/value bars
3. Create tick count bars
4. Add information-driven bars

### Phase 3: Streaming Support
1. Add streaming aggregation
2. Implement partial bar updates
3. Create bar completion callbacks
4. Add backfill support

## Success Criteria

### Validation Gates
```bash
# Test aggregation
cargo test tick_aggregation
cargo test bar_formation

# Validate accuracy
cargo test aggregation_accuracy
```

### Implementation Metrics
- [ ] Process 1M ticks in < 500ms
- [ ] Support 10+ aggregation types
- [ ] Streaming latency < 1ms
- [ ] Accurate VWAP calculation

## Dependencies & References

**Prerequisites**:
- Complete PRP-41 (Tick Generator)
- Tick data structures in place

**Research Sources**:
- Advances in Financial Machine Learning (Lopez de Prado)
- Alternative bar construction methods
- Market microstructure aggregation

**Implementation Patterns**:
- Use iterator pattern for streaming
- Implement as composable transforms
- Support parallel aggregation

## Implementation Tasks

### Phase 1: Core Engine (2-3 hours)
1. Design aggregator trait
2. Implement time bars
3. Add OHLC logic
4. Test accuracy

### Phase 2: Alternative Bars (2-3 hours)
1. Add volume bars
2. Implement dollar bars
3. Create tick bars
4. Validate formations

### Phase 3: Streaming (2-3 hours)
1. Add streaming mode
2. Implement callbacks
3. Optimize performance
4. Document usage

## Risk Mitigation
- Validate against known aggregations
- Handle edge cases (gaps, halts)
- Ensure numerical precision
- Provide aggregation diagnostics

## Success Score
**8/10** - Well-defined requirements with clear implementation patterns from research.