DocsMathStatisticsSharpe Ratio

Sharpe Ratio

Windowed · default period 20Statistics

The Sharpe node computes a rolling Sharpe-like ratio assuming zero risk-free rate: mean(window) / population_std(window). When the input is a series of returns, this is the classical per-period Sharpe ratio. Higher values indicate better risk-adjusted return; negative values mean the average return is negative relative to its volatility. Requires at least 2 non-null values.

Algorithm

  • vals = non-null values in window
  • μ = mean(vals), σ = population_std(vals)
  • output = μ / σ
  • Returns null when σ = 0 (zero-variance window)
  • Note: uses population std, not sample std — differs from annualized broker Sharpe metrics

Parameters

NameTypeDefaultDescription
periodnumber20Rolling window size.

Inputs & Outputs

PortTypeDescription
Inputs
inputnumber[]Source numeric array
Outputs
valuesnumber | nullComputed value at each bar; null before the warmup period completes
timestampsnumber[]Bar timestamps (UNIX ms), aligned 1-to-1 with values
Live mode: In live streaming mode the node updates only the last bar in-place rather than recalculating the full array, keeping CPU usage minimal during real-time data feeds.

Use Cases

Rolling Risk Quality

Monitor rolling Sharpe on a strategy's bar-by-bar P&L series to detect when risk-adjusted performance degrades — a Sharpe drop below 0.5 may trigger a strategy pause.

Asset Ranking

Rank tradable instruments by their rolling Sharpe on returns to select the current best risk-adjusted performers for a rotating long-only portfolio.

Regime Quality Gate

Enter new positions only when rolling Sharpe on recent returns is positive — ensuring you are entering during periods of historically positive risk-adjusted momentum.