talib.CORREL
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
| Type | Description |
numeric array | Indicator values, the same length as the input; the leading values without enough data are |
Arguments
| Name | Type | Required | Description |
inReal0 | numeric array | Yes | First series. |
inReal1 | numeric array | Yes | Second series; it must have the same length as |
optInTimePeriod | number | No | Calculation period. Default |
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.