Type/to search
Built-in Functions
Global
Log
Market
Trade
Account
Futures
Exchange
IO
Network
Storage
Threads
TA
Talib
Overlap Studies
Momentum Indicators
Volume Indicators
Volatility Indicators
Cycle Indicators
Price Transform
Statistic Functions
talib.BETA
talib.CORREL
talib.LINEARREG
talib.LINEARREG_ANGLE
talib.LINEARREG_INTERCEPT
talib.LINEARREG_SLOPE
talib.STDDEV
talib.TSF
talib.VAR
Math Transform
Math Operators
Pattern Recognition
OS
Structures
Built-in Variables and Constants
Conventions
Exchanges

Calculates the Pearson's Correlation Coefficient (r).

talib.CORREL(inReal0, inReal1)
talib.CORREL(inReal0, inReal1, optInTimePeriod)

Examples

Compute the correlation between close price and volume over 30 K-lines.

javascript
function main() { var records = exchange.GetRecords() if (!records) return var closes = records.map(function(r) { return r.Close }) var volumes = records.map(function(r) { return r.Volume }) var ret = talib.CORREL(closes, volumes, 30) Log(ret) }
python
import talib def main(): records = exchange.GetRecords() if not records: return ret = talib.CORREL(records.Close, records.Volume, 30) Log(ret)

Returns

TypeDescription

numeric array

Indicator values, the same length as the input; the leading values without enough data are NaN.

Arguments

NameTypeRequiredDescription

inReal0

numeric array

Yes

First series.

inReal1

numeric array

Yes

Second series; it must have the same length as inReal0.

optInTimePeriod

number

No

Calculation period. Default 30.

See Also

Remarks

TA-Lib equivalent: CORREL(Array(inReal0),Array(inReal1),Time Period = 30) = Array(outReal).

Returns Pearson's correlation coefficient of the two series over the latest optInTimePeriod bars, in the range [-1, 1].

In JavaScript, both inputs must be numeric arrays (extract a field from the K-line data with map first): if a K-line array is passed, both inputs take the close price of the same K-line data and the result is meaningless; arrays of different lengths raise an error.