CORREL
CORREL
Summary
Pearson's correlation coefficient (r) between two input series over a rolling window of optInTimePeriod bars. Measures how linearly the two series move together. r near +1: strong positive co-movement; near -1: strong inverse; near 0: no linear relationship.
Formula
r = (sumXY - sumX*sumY/n) / sqrt((sumX2 - sumX^2/n) * (sumY2 - sumY^2/n)), n = optInTimePeriod, sums over the window
Notes
- When the correlation is undefined for a window (for example a constant series), the output is 0 rather than an error or NaN.
Inputs
inReal0— First data series (X)inReal1— Second data series (Y)
Outputs
outReal— Correlation coefficient r in [-1, 1]
Parameters
| Parameter | Type | Default | Accepted values | Description |
|---|---|---|---|---|
optInTimePeriod | integer | 30 | 1–100000 | Rolling window length |
Properties
Numerical Stability: Start-Independent
| Display Flags |
|---|
| ☐ Overlap Input |
| ✅ Independent Y-Axis i |
| ☐ Candlestick |
Implementation
TA-Lib Definition: correl.c · correl.yaml
| Native | File |
|---|---|
| C | ta_CORREL.c |
| Rust | correl.rs |
| Java | Core_CORREL.java |
TA-Lib is also available for Python, R and more using a wrapper.
Aliases
Pearson Correlation, Correlation Coefficient, r
See Also
References
- Karl Pearson