CUSUM
Page contents
CUSUM Indicator in StrategyQuant
In today’s post, we’ll take a closer look at a custom implementation of the CUSUM (Cumulative Sum) indicator. Often used in statistical process control, the CUSUM technique helps detect small shifts in the mean level of a series. This particular implementation is designed for integration into StrategyQuant, offering traders a dynamic way to monitor and react to market changes.
What Is CUSUM?
CUSUM is a sequential analysis technique that accumulates deviations from a target value over time. By comparing the cumulative sum against defined thresholds, it becomes easier to spot even subtle shifts in price behavior. In our implementation, two separate accumulators—one for upward movements (CUSUM Positive) and one for downward movements (CUSUM Negative)—signal when the change in the underlying price series becomes significant.
Code Walkthrough
The indicator is defined as a Java class that extends
IndicatorBlock
, ensuring seamless integration with StrategyQuant’s ecosystem. Let’s break down the key components:
Parameters and Inputs
- Chart Data: The indicator uses a chart (typically the close price) as the data source.
- Period: Determines the window size over which the rolling mean and standard deviation are calculated. This is crucial as it defines the sensitivity of the indicator.
- Threshold (k): Sets the detection threshold. A higher threshold means the indicator becomes less sensitive, reducing false signals.
- Drift (μ): Accounts for the expected drift in the process, enabling the detection of smaller but persistent changes.
Rolling Statistics Calculation
For each new bar (or time point), the code computes the rolling mean and standard deviation over the defined period. These statistics serve as the baseline to standardize the current price data.
Standardization and CUSUM Calculation
The current price is standardized by subtracting the mean and dividing by the standard deviation. The standardized value is then used to update the CUSUM accumulators:
- CUSUM Positive: Accumulates positive deviations.
- CUSUM Negative: Accumulates negative deviations.
Each update subtracts both the drift and the threshold, ensuring that only significant deviations contribute to the cumulative sum.
Handling Edge Cases
An important detail is the check for the standard deviation. When price data are too consistent (resulting in a standard deviation of zero), the code resets it to 1. This safeguard prevents division errors and keeps the indicator robust under low-volatility conditions.
Bringing It All Together
This CUSUM indicator is a powerful tool for traders looking to catch subtle but sustained changes in price action. By dynamically adjusting to recent market data (through rolling statistics) and accounting for noise via the threshold and drift parameters, the indicator offers a balanced approach to signal generation.
If you’re interested in incorporating this indicator into your trading strategies, the code is structured to be both adaptable and easy to integrate within the StrategyQuant environment.