Skip to content

Outlier Detection and Filtering Serviceo #18

@Villarley

Description

@Villarley

Outlier Detection and Filtering Service

📝 Description

Implement an outlier detection service that identifies and filters anomalous or suspicious data before aggregation. This service should use multiple statistical techniques to detect prices that deviate significantly from consensus or are technically impossible (negative prices, >50% changes in seconds, etc.).

Context: Data from external APIs can have errors, glitches, or be manipulated. It's critical to filter this data before aggregating to avoid contaminating the consensus price that will be published on-chain.

Tech Stack:

  • NestJS Service
  • Statistical algorithms (IQR, Z-score, MAD)
  • RxJS for stream processing
  • TypeScript with strict types

✅ Requirements

  • Implement an OutlierDetectionService with multiple detection strategies
  • Detect prices outside reasonable ranges (e.g., negative price, >50% change)
  • Implement IQR-based detection (Interquartile Range)
  • Implement Z-score-based detection (standard deviation)
  • Implement MAD-based detection (Median Absolute Deviation)
  • Configure adjustable thresholds via environment variables
  • Mark outliers instead of discarding them (for later analysis)
  • Calculate data quality metrics per source
  • Implement logging of detected outliers for debugging

🎯 Acceptance Criteria

  • The service correctly detects negative or zero prices
  • At least 3 outlier detection methods are implemented
  • Thresholds are configurable via environment variables
  • Outliers are marked with metadata explaining why they were detected
  • Data quality metrics are generated per source (% of outliers)
  • Unit tests exist with edge cases (>85% coverage)
  • Each detection strategy and its parameters are documented
  • The service doesn't crash with empty or insufficient data

📁 Expected files to change/structure

  • apps/aggregator/src/services/outlier-detection.service.ts - Main service
  • apps/aggregator/src/services/outlier-detection.service.spec.ts - Tests
  • apps/aggregator/src/strategies/outlier-detectors/ - Strategies
    • iqr-detector.ts
    • zscore-detector.ts
    • mad-detector.ts
    • range-detector.ts
  • apps/aggregator/src/interfaces/outlier-result.interface.ts - Detection result
  • apps/aggregator/src/app.module.ts - Register service
  • apps/aggregator/.env.example - Configuration variables
  • apps/aggregator/README.md - Document strategies

Metadata

Metadata

Assignees

No one assigned

    Labels

    Stellar WaveIssues in the Stellar wave program

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions