Geometry Analysis
Section A: Scatter data preparation, marginal distributions, and summary metrics.
geometry
Geometry analysis: scatter data preparation and marginal distributions.
scatter_data(trades, trim_method='iqr', trim_k=1.5, trim_percentile_range=(1.0, 99.0))
Prepare raw and trimmed scatter data for plotting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trades
|
TradeSet
|
Trade geometry data |
required |
trim_method
|
(iqr, percentile, None)
|
Outlier removal method |
'iqr'
|
trim_k
|
float
|
IQR multiplier (used if trim_method='iqr') |
1.5
|
trim_percentile_range
|
tuple
|
Percentile bounds (used if trim_method='percentile') |
(1.0, 99.0)
|
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary containing: - 'raw': {'mfe': array, 'mae': array} - 'trimmed': {'mfe': array, 'mae': array, 'keep_mask': array} - 'n_raw': int - 'n_trimmed': int |
Source code in signal_analyzer/analysis/geometry.py
marginals(trades, bins=50, use_kde=True)
Calculate marginal distributions for MFE and MAE separately.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trades
|
TradeSet
|
Trade geometry data |
required |
bins
|
int
|
Number of bins for histogram |
50
|
use_kde
|
bool
|
If True, also compute Kernel Density Estimate |
True
|
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary containing: - 'mfe_hist': {'bins': array, 'counts': array, 'density': array} - 'mae_hist': {'bins': array, 'counts': array, 'density': array} - 'mfe_kde': {'x': array, 'density': array} (if use_kde=True) - 'mae_kde': {'x': array, 'density': array} (if use_kde=True) |
Source code in signal_analyzer/analysis/geometry.py
geometry_metrics(trades)
Compute summary statistics for trade geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trades
|
TradeSet
|
Trade geometry data |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary of metrics: - n_trades: Number of trades - median_mfe: Median MFE (%) - median_mae: Median MAE (%) - mean_mfe: Mean MFE (%) - mean_mae: Mean MAE (%) - win_rate: Fraction of trades with MFE > 0 - mfe_p95: 95th percentile MFE - mfe_p99: 99th percentile MFE - mae_p5: 5th percentile MAE (tail risk) - mae_p1: 1st percentile MAE (extreme tail risk) - mfe_mae_corr: Correlation between MFE and MAE |