Systemicbeta

Value Clamp

systemic:core-clampMath

Inputs

NameTypeDescription
Min ValueNumberThe lower limit (floor) for the data.
Max ValueNumberThe upper limit (ceiling) for the data.
DataNumber seriesThe series of numbers to keep within the Min Value and Max Value limits.

Outputs

NameTypeDescription
ClampNumber seriesThe input series with every value limited to the range from Min Value to Max Value.

Cost

6
credits per run
1,000
bars

0.199 + 0.00573·n credits for n bars, rounded up. The marks are each plan's limit of bars.

The Clamp module keeps every value of a series between a minimum and a maximum. Limits matter: in the May 6, 2010 Flash Crash, the Dow Jones fell nearly 1,000 points in minutes, partly because algorithms reacted to extreme signals without limits. CLAMP stops extreme values from spreading through your strategy.

Use it for position sizing, for preparing data for machine learning, or for any signal that must stay within safe limits. However extreme the input, the output stays within the range you set.


The Core Formula

Clamp(x)=max⁡(Min,  min⁡(x,  Max))\text{Clamp}(x) = \max\bigl(\text{Min},\; \min(x,\; \text{Max})\bigr)

The same rule, case by case:

Clamp(x)={Minif x<Minxif Min≤x≤MaxMaxif x>Max\text{Clamp}(x) = \begin{cases} \text{Min} & \text{if } x < \text{Min} \\[4pt] x & \text{if } \text{Min} \leq x \leq \text{Max} \\[4pt] \text{Max} & \text{if } x > \text{Max} \end{cases}

In plain English: Values below the minimum get raised to the minimum. Values above the maximum get lowered to the maximum. Everything in between passes through unchanged.


How Clamping Works

flowchart TD
    INPUT["Input Value: x"] --> CHECK{"Where is x?"}
    
    CHECK -->|"x < Min"| FLOOR["Output = Min<br/>🔺 Raised to floor"]
    CHECK -->|"Min ≤ x ≤ Max"| PASS["Output = x<br/>✓ Unchanged"]
    CHECK -->|"x > Max"| CEIL["Output = Max<br/>🔻 Lowered to ceiling"]
    
    FLOOR --> OUT["Bounded Output"]
    PASS --> OUT
    CEIL --> OUT
    
    style FLOOR fill:#dc2626,color:#fff
    style PASS fill:#059669,color:#fff
    style CEIL fill:#2563eb,color:#fff
    style OUT fill:#6b7280,color:#fff

Worked Example

Original ValueMin = 10Max = 50Clamped ResultAction
5105010Raised to floor
20105020Unchanged
35105035Unchanged
55105050Lowered to ceiling
-100105010Raised to floor

The Distribution Effect

Clamping changes the tails of a distribution by moving extreme values onto the boundaries:

flowchart LR
    subgraph Before["Raw Distribution"]
        B1["Fat tails extend<br/>to extreme values"]
        B2["Outliers present"]
    end
    
    subgraph Transform["CLAMP Applied"]
        T["Values outside [Min, Max]<br/>compressed to boundaries"]
    end
    
    subgraph After["Clamped Distribution"]
        A1["Bounded range"]
        A2["Spikes at boundaries<br/>(if many outliers)"]
    end
    
    Before --> Transform --> After

Important: Clamping is not normalization. It does not rescale values. It is a hard cutoff that can create "pileups" at the boundaries if many values exceed the limits.


Real-World Applications

1. The Circuit Breaker: Limiting Extreme Signals

A key use of clamping is to stop a signal from implying an extreme position during market stress:

flowchart TD
    subgraph Signal["Raw Signal Generation"]
        SIG["Momentum Signal<br/>Range: -∞ to +∞"]
    end
    
    subgraph Safety["Safety Layer"]
        CLAMP["CLAMP<br/>Min: -100%, Max: +100%"]
    end
    
    subgraph Position["Position Sizing"]
        POS["Position = Signal × Capital"]
    end
    
    subgraph Risk["Risk Outcome"]
        SAFE["Maximum exposure<br/>= 100% of capital"]
    end
    
    SIG --> CLAMP --> POS --> SAFE

Scenario: Your momentum signal usually ranges from -50 to +50. During a flash crash, it suddenly spikes to +500. Without clamping, a position size calculated from it would be 500% of your capital, far too much leverage.

With CLAMP: The signal is capped at +100, so the position size it implies stays manageable however extreme the signal becomes.

2. Z-Score Winsorization for Machine Learning

When you feed financial data into machine learning models, outliers can dominate model training and make the model worse on new data. Clamping Z-scores is a common way to prepare the data:

Z-Score RangeStatistical InterpretationAction
Beyond ±3σOccurs in ~0.3% of normal dataClamp to ±3
Between ±2σ and ±3σOccurs in ~4.3% of normal dataKeep or clamp to ±2.5
Within ±2σ95% of normal dataPass through

Why ±3? In a normal distribution, 99.7% of values fall within 3 standard deviations. Values beyond this threshold are often considered outliers that may distort analysis.

3. Return Capping for Risk Models

Extreme daily returns can blow up Value-at-Risk (VaR) calculations. Many institutional risk models clamp returns before computing risk metrics:

Asset ClassTypical Daily Return RangeSuggested Clamp
Large-cap equities-5% to +5%±10%
Cryptocurrencies-20% to +20%±30%
Forex majors-2% to +2%±5%
Commodities-5% to +5%±15%

Clamping returns at these levels keeps almost all real price moves while stopping very rare events from dominating your risk calculations.

4. Indicator Rescaling

Some indicators (like RSI) are already bounded 0-100, but others have no natural limits. Clamping creates consistent ranges for multi-indicator systems:

flowchart LR
    subgraph Unbounded["Unbounded Indicators"]
        ZS["Z-Score: -∞ to +∞"]
        ROC["Rate of Change: -∞ to +∞"]
        MOM["Momentum: -∞ to +∞"]
    end
    
    subgraph Clamp["CLAMP Layer"]
        C1["CLAMP(-3, +3)"]
        C2["CLAMP(-50, +50)"]
        C3["CLAMP(-100, +100)"]
    end
    
    subgraph Uniform["Bounded Range"]
        B1["Comparable scales"]
        B2["Safe for combination"]
    end
    
    ZS --> C1 --> B1
    ROC --> C2 --> B1
    MOM --> C3 --> B1

Choosing Your Boundaries

The key to clamping is choosing good boundaries. Too tight, and you lose useful signal information. Too loose, and the clamp gives no protection.

Statistical Approaches

MethodFormulaWhen to Use
Fixed percentileClamp at 1st and 99th percentileRobust to distribution shape
Standard deviationMean ± k×σ (k=2 or 3)Assumes near-normal distribution
Domain knowledgeSet by market expertiseWhen you know the realistic limits
Regulatory/risk limitsExternally mandatedCompliance requirements

Dynamic vs Static Clamping

ApproachDescriptionTrade-off
Static clampFixed Min/Max valuesSimple, predictable, may become outdated
Dynamic clampBounds that follow the marketAdapts to market conditions, more complex

CLAMP is static: Min Value and Max Value are fixed numbers and cannot be wired to a series. For bounds that adapt, normalize the series first (for example with a Z-score), then clamp the result.


CLAMP vs Alternative Normalization Methods

MethodHow It WorksBest For
CLAMPHard cutoff at boundariesSafety limits, preventing extremes
PERC (Percentile)Rank-based position in historyAdaptive thresholds, distribution-free
ZSCR (Z-Score)Distance from mean in std devsStandardization, outlier detection
Min-Max ScalingRescale to [0,1] rangeFull range transformation
flowchart TD
    Q["What do you need?"] --> SAFE{"Prevent extreme values<br/>from exceeding limits?"}
    SAFE -->|Yes| CLAMP["Use CLAMP"]
    SAFE -->|No| COMPARE{"Compare current value<br/>to recent history?"}
    COMPARE -->|Yes| PERC["Use PERC"]
    COMPARE -->|No| STANDARD{"Need standardized<br/>units (std devs)?"}
    STANDARD -->|Yes| ZSCR["Use ZSCR"]
    STANDARD -->|No| BOTH["Consider combining<br/>ZSCR + CLAMP"]

Edge Cases and Considerations

SituationBehavior
Min > MaxInvalid configuration, rejected. Make sure Min ≤ Max
All values within rangeAll values pass through unchanged
All values outside rangeAll values clamped to nearest boundary
Empty valuesOutput is empty at the same position, never clamped to a boundary
Infinite valuesClamped to the nearest boundary like any other number
Min = MaxAll values become that single value

Missing Data

When an input value is empty (null), such as a data gap or a bar when the market is closed, the output is empty at the same position. An empty value is not treated as 0 and is never moved to the Min or Max boundary. Every number, however extreme (including infinity), has a valid clamped result. Only empty inputs give empty outputs.

Information Loss Warning

Clamping discards information about how extreme outliers were. If the difference between "moderately extreme" and "catastrophically extreme" matters to your analysis, use CLAMP alongside the original series, not instead of it.


The "Guardrails" Pattern: A Complete Example

Combine clamping with other modules to build a signal that stays within safe limits:

flowchart TD
    subgraph Data["Raw Data"]
        PRICE["Price Series"]
    end
    
    subgraph Signal["Signal Generation"]
        MOM["Momentum(20)"]
    end
    
    subgraph Normalize["Normalization"]
        ZSCR["Z-Score(50)"]
    end
    
    subgraph Guardrails["Safety Guardrails"]
        CLAMP["CLAMP(-3, +3)"]
    end
    
    subgraph Action["Trade Logic"]
        GTR["If > +2"]
        LST["If < -2"]
    end
    
    subgraph Trades["Actions"]
        BUY["Consider Long"]
        SELL["Consider Short"]
    end
    
    PRICE --> MOM --> ZSCR --> CLAMP
    CLAMP --> GTR --> BUY
    CLAMP --> LST --> SELL

This pattern:

  1. Calculates raw momentum
  2. Standardizes with Z-score (tells you how unusual the momentum is)
  3. Clamps to ±3 (prevents extreme Z-scores from dominating)
  4. Generates signals based on the bounded, standardized values

Advantages

AdvantageDescription
PredictabilityOutput range is guaranteed—no surprises
SpeedOne simple check per value
SimplicityEasy to understand and explain
Safety netStops extreme inputs from distorting later modules
ComposableCombines well with other modules

Limitations

LimitationMitigation
Information lossKeep original series for reference if needed
Arbitrary boundariesUse statistical methods to set bounds
Not adaptiveNormalize the series first (for example with a Z-score), then clamp
Boundary pileupIf too many values hit limits, reconsider your bounds

Further Reading

Rendering diagrams...
© 2026 WanoLabs. All rights reservedBeta v0.1.5