Skip to content

API Overview

The Trade Geometry Analyzer API is organized into four main modules:

Core Module (signal_analyzer.core)

Foundation components for signal processing and trade path extraction:

  • events - Convert continuous signals to discrete entry/exit events
  • trades - TradeSet dataclass and path computation
  • utils - Statistical helpers (outlier removal, knee point detection)

Analysis Module (signal_analyzer.analysis)

Six analysis sections, each with dedicated functions:

  • geometry - Section A: Scatter data, marginals, metrics
  • frontiers - Section B: Risk/reward boundaries
  • ordering - Section C: Time sequencing analysis
  • feasibility - Section D: TP/SL probability heatmaps
  • volnorm - Section E: Volatility normalization
  • clusters - Section F: Trade archetype clustering

Plotting Module (signal_analyzer.plotting)

Visualization functions mirroring the analysis modules:

  • scatter - MFE vs MAE scatter plots
  • frontiers - Frontier curves
  • heatmaps - TP/SL probability/EV heatmaps
  • volnorm - Vol-normalization visualizations
  • clusters - Cluster scatter plots and statistics

Main Analyzer (signal_analyzer.analyzer)

The high-level orchestrator:

  • analyzer - analyze() function, AnalysisConfig, AnalysisResult

Quick Reference

Main Entry Point

from signal_analyzer import analyze, AnalysisConfig

result = analyze(df, sig_col='sig', config=AnalysisConfig(H=20))

Core Data Structures

from signal_analyzer import TradeSet

# TradeSet: Container for trade geometry
trades = TradeSet(
    side='long',
    mfe=np.array([...]),
    mae=np.array([...]),
    # ... more fields
)

Configuration

from signal_analyzer import AnalysisConfig

config = AnalysisConfig(
    H=20,                              # Forward horizon
    sections=['A', 'B', 'C', 'D'],    # Sections to run
    store_paths=True,                  # Required for Section D
    vol_col='atr',                     # Enable vol normalization
)

Results

# Analysis result structure
result.long_trades            # TradeSet
result.short_trades           # TradeSet
result.section_a              # Dict with 'long'/'short' keys
result.section_b              # Dict with 'long'/'short' keys
# ... sections c-f
result.plots                  # Dict of matplotlib figures

Design Philosophy

The library follows these principles:

  1. Modular: Each section is independent, import only what you need
  2. Vectorized: NumPy-based for performance (10K+ trades easily)
  3. Stateless: Pure functions, no hidden state
  4. Flexible: Configure everything, sane defaults
  5. Transparent: Full access to intermediate results

Common Patterns

Running Specific Sections

# Only geometry and frontiers (fast)
config = AnalysisConfig(H=10, sections=['A', 'B'], store_paths=False)
result = analyze(df, sig_col='sig', config=config)

Custom Analysis

from signal_analyzer.core import signal_to_events, compute_trade_paths
from signal_analyzer.analysis.geometry import geometry_metrics

# Step-by-step manual analysis
events = signal_to_events(df.sig)
trades = compute_trade_paths(df, events['enter_long'], side='long', H=20)
metrics = geometry_metrics(trades)

Accessing Raw Data

# Get TradeSet with full paths
config = AnalysisConfig(H=20, store_paths=True)
result = analyze(df, sig_col='sig', config=config)

# Access MFE paths (shape: n_trades × H)
mfe_paths = result.long_trades.mfe_path
mae_paths = result.long_trades.mae_path

# Custom analysis on paths
quick_winners = np.any(mfe_paths[:, :5] >= 1.0, axis=1)

Next Steps

  • Explore individual modules in the sidebar
  • See Examples for real usage patterns
  • Check User Guide for section details