Scanner Module - Multi-Symbol Analysis
This module provides utilities for scanning multiple symbols with strategies and ranking results based on performance metrics.
Types
RankBy = enum TotalReturn, AnnualizedReturn, SharpeRatio, WinRate, ProfitFactor, MaxDrawdown, TotalTrades
- Metrics to rank scan results by
Scanner = object strategy*: Strategy symbols*: seq[string] initialCash*: float64 commission*: float64 verbose*: bool
- Multi-symbol scanner for strategy analysis
ScanResult = object symbol*: string report*: BacktestReport signals*: seq[Signal]
- Result from scanning a single symbol
Procs
proc `$`(scanResult: ScanResult): string {....raises: [], tags: [], forbids: [].}
- String representation of a scan result
proc filter(results: seq[ScanResult]; minReturn: float64 = NegInf; minSharpe: float64 = NegInf; minWinRate: float64 = 0.0; minTrades: int = 0; maxDrawdown: float64 = Inf): seq[ScanResult] {. ...raises: [], tags: [], forbids: [].}
-
Filter scan results by criteria
Args: minReturn: Minimum total return percentage minSharpe: Minimum Sharpe ratio minWinRate: Minimum win rate percentage minTrades: Minimum number of trades maxDrawdown: Maximum drawdown percentage
Returns: Filtered results
proc newScanner(strategy: Strategy; symbols: seq[string]; initialCash: float64 = 100000.0; commission: float64 = 0.0; verbose: bool = false): Scanner {....raises: [], tags: [], forbids: [].}
-
Create a new multi-symbol scanner
Args: strategy: Trading strategy to apply to all symbols symbols: List of symbols to scan initialCash: Initial capital for each backtest commission: Commission rate (e.g., 0.001 for 0.1%) verbose: Print progress messages
Returns: Scanner instance ready to run
proc rankBy(results: var seq[ScanResult]; metric: RankBy; ascending: bool = false) {....raises: [], tags: [], forbids: [].}
-
Rank scan results by a performance metric
Args: results: Scan results to rank (modified in place) metric: Metric to rank by ascending: If true, rank ascending (low to high), else descending
proc scan(scanner: Scanner; dataMap: Table[string, seq[OHLCV]]): seq[ScanResult] {. ...raises: [KeyError, ValueError, Exception], tags: [RootEffect, TimeEffect], forbids: [].}
-
Scan multiple symbols with the strategy
Args: dataMap: Table mapping symbols to their OHLCV data
Returns: Sequence of ScanResult for each symbol
proc scanFromCSV(scanner: Scanner; csvDir: string): seq[ScanResult] {. ...raises: [KeyError, ValueError, Exception], tags: [ReadDirEffect, ReadIOEffect, RootEffect, TimeEffect], forbids: [].}
-
Scan symbols by loading CSV files from a directory
Expected file naming: {symbol}.csv
Args: csvDir: Directory containing CSV files
Returns: Sequence of ScanResult for each symbol
proc summary(results: seq[ScanResult]): string {....raises: [], tags: [], forbids: [].}
-
Generate a summary table of scan results
Returns: Formatted string with results table
proc topN(results: seq[ScanResult]; n: int): seq[ScanResult] {....raises: [], tags: [], forbids: [].}
-
Get top N results (assumes already ranked)
Args: results: Ranked scan results n: Number of top results to return
Returns: Top N results