Value Clamp
systemic:core-clampMathInputs
| Name | Type | Description |
|---|---|---|
| Min Value | Number | The lower limit (floor) for the data. |
| Max Value | Number | The upper limit (ceiling) for the data. |
| Data | Number series | The series of numbers to keep within the Min Value and Max Value limits. |
Outputs
| Name | Type | Description |
|---|---|---|
| Clamp | Number series | The input series with every value limited to the range from Min Value to Max Value. |
Cost
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
The same rule, case by case:
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 Value | Min = 10 | Max = 50 | Clamped Result | Action |
|---|---|---|---|---|
| 5 | 10 | 50 | 10 | Raised to floor |
| 20 | 10 | 50 | 20 | Unchanged |
| 35 | 10 | 50 | 35 | Unchanged |
| 55 | 10 | 50 | 50 | Lowered to ceiling |
| -100 | 10 | 50 | 10 | Raised 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 Range | Statistical Interpretation | Action |
|---|---|---|
| Beyond ±3σ | Occurs in ~0.3% of normal data | Clamp to ±3 |
| Between ±2σ and ±3σ | Occurs in ~4.3% of normal data | Keep or clamp to ±2.5 |
| Within ±2σ | 95% of normal data | Pass 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 Class | Typical Daily Return Range | Suggested 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
| Method | Formula | When to Use |
|---|---|---|
| Fixed percentile | Clamp at 1st and 99th percentile | Robust to distribution shape |
| Standard deviation | Mean ± k×σ (k=2 or 3) | Assumes near-normal distribution |
| Domain knowledge | Set by market expertise | When you know the realistic limits |
| Regulatory/risk limits | Externally mandated | Compliance requirements |
Dynamic vs Static Clamping
| Approach | Description | Trade-off |
|---|---|---|
| Static clamp | Fixed Min/Max values | Simple, predictable, may become outdated |
| Dynamic clamp | Bounds that follow the market | Adapts 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
| Method | How It Works | Best For |
|---|---|---|
| CLAMP | Hard cutoff at boundaries | Safety limits, preventing extremes |
| PERC (Percentile) | Rank-based position in history | Adaptive thresholds, distribution-free |
| ZSCR (Z-Score) | Distance from mean in std devs | Standardization, outlier detection |
| Min-Max Scaling | Rescale to [0,1] range | Full 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
| Situation | Behavior |
|---|---|
| Min > Max | Invalid configuration, rejected. Make sure Min ≤ Max |
| All values within range | All values pass through unchanged |
| All values outside range | All values clamped to nearest boundary |
| Empty values | Output is empty at the same position, never clamped to a boundary |
| Infinite values | Clamped to the nearest boundary like any other number |
| Min = Max | All 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:
- Calculates raw momentum
- Standardizes with Z-score (tells you how unusual the momentum is)
- Clamps to ±3 (prevents extreme Z-scores from dominating)
- Generates signals based on the bounded, standardized values
Advantages
| Advantage | Description |
|---|---|
| Predictability | Output range is guaranteed—no surprises |
| Speed | One simple check per value |
| Simplicity | Easy to understand and explain |
| Safety net | Stops extreme inputs from distorting later modules |
| Composable | Combines well with other modules |
Limitations
| Limitation | Mitigation |
|---|---|
| Information loss | Keep original series for reference if needed |
| Arbitrary boundaries | Use statistical methods to set bounds |
| Not adaptive | Normalize the series first (for example with a Z-score), then clamp |
| Boundary pileup | If too many values hit limits, reconsider your bounds |
Further Reading
- Winsorizing - Wikipedia — A related statistical technique for handling outliers
- Flash Crash of 2010 - Wikipedia — A case study in why algorithmic limits matter
- Outlier - Wikipedia — Understanding and handling extreme values in statistics
- Feature Scaling in Machine Learning — Broader context for data preprocessing