Benchmark Relative Metrics
"Beat the market" only means something once "the market" is defined as a concrete return series and the comparison is done with the standard formulas, applied consistently. This library computes the four standard benchmark-relative statistics - beta (covariance over benchmark variance), Jensen's alpha (mean strategy return minus beta times mean benchmark return), information ratio (mean active return over active-return standard deviation) and up/down capture ratios (compounded strategy growth over compounded benchmark growth, restricted to periods where the benchmark itself was up or down) - from two aligned arrays of period returns. The benchmark is not fixed to any particular symbol or buy-and-hold assumption - pass in whatever return series is the right comparison: an index proxy built from another instrument's closes, a fixed savings rate, another strategy's own return stream, or the same symbol's raw buy-and-hold return. The library only needs the two arrays aligned to the same period boundaries. The one detail most hand-rolled versions get wrong is capture ratio: it is a ratio of COMPOUNDED growth factors over the qualifying periods, not a plain average of per-period ratios. Averaging per-period ratios lets a single benchmark period near zero blow up the average with an extreme outlier ratio; compounding the numerator and denominator separately before dividing does not have that failure mode. The demo constructs a synthetic strategy series with a KNOWN target beta and alpha baked in, then verifies the library recovers values close to those targets - proof the regression is correct, not just plausible-looking. Notes and limitations - Alpha() is the risk-free-rate-OMITTED form (mean strategy return minus beta times mean benchmark return). Callers wanting the textbook risk- free-adjusted alpha should subtract the per-period risk-free return from BOTH input arrays before calling - this library does not assume or fetch a risk-free rate on the caller's behalf. - Beta()/Alpha() return 0.0 when the benchmark series has effectively zero variance in the sample - there is nothing to regress against, so a real beta cannot be computed, and 0.0 is returned rather than a divide-by-near-zero artefact. - Up/down capture ratios return 0.0 when the benchmark never qualifies (e.g. DownCaptureRatio() on a sample where the benchmark was never negative), rather than dividing by zero. - All five statistics are full-sample batch calculations over the two arrays passed in - there is no incremental/streaming variant. Re-run over a growing array as new periods complete if a live-updating figure is needed. - Returns must be genuine period-over-period fractional returns (e.g. 0.01 for +1%), aligned index-for-index between the two arrays. Misaligned periods, or mixing price levels with returns, will silently produce meaningless output - there is no way for the library to detect that from the arrays alone.
Script · MT4 · v1.0 · Free
About Benchmark Relative Metrics
Benchmark Relative Metrics is a script for MetaTrader 4. It has 3 settings, such as Period count, Target beta and Target alpha. MQL source code included.
Files in the download: BenchmarkRelativeMetrics.mqh, BenchmarkRelativeMetrics.txt, BenchmarkRelativeMetricsDemo.mq4.
Settings
| Setting | Default | What it does |
|---|---|---|
| Period count | 400 | Number of synthetic return periods |
| Target beta | 0.60 | Beta used to construct the synthetic strategy series |
| Target alpha | 0.0004 | Per-period alpha added on top (fraction, e.g. 0.0004 = 0.04%) |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: MT4 Script · MQL4 Source Code