Skip to content

Pearson's Correlation Coefficient (r)

CORREL calculates the correlation between two sets of data.

Method

tm.ta.correl(source_high, source_low, timeperiod)

Inputs

ParameterArgument typeDescriptionDefault Value
source_highpd.SeriesHigh prices series-
source_lowpd.SeriesLow prices series-
timeperiodintNumber of periods for the indicator30

Outputs

OutputType
correlnp.ndarray

Example usage

strategy.py
import tradomate as tm
@tm.strategy()
def my_strategy(config: tm.TradomateConfig, data: tm.TradomateData):
# Trying out Pearson's Correlation Coefficient (r)
correl = tm.ta.correl(data.high, data.low, timeperiod=30)
# Get the last value and print
last_value = correl.iloc[-1]
tm.log(f"Last value of Pearson's Correlation Coefficient (r) is {last_value}")
# Plot the values of correl
tm.plot(correl, title="Pearson's Correlation Coefficient (r)", overlay=False)