Correlation

Modified on 2017/05/26 10:19 by Eugene — Categorized as: Community Indicators

Correlation: Indicator Documentation

Syntax

DataSeries CorrelationXL( DataSeries x, DataSeries y, int period ) DataSeries Correlation( DataSeries x, DataSeries y, int period )

public static double Value( int bar, DataSeries x, DataSeries y, int period )


Parameter Description

xFirst DataSeries
ySecond DataSeries
periodLookback period used to calculate correlation between the series

Description

Returns Pearson's Correlation Coefficient between the two specified data series, x and y. Specify the quantity of data to analyze in the Lookback parameter (period).

The first series coded by Michael Bytnar and is used to match Excel's output, the other one coded by Steve Salemy returns Pearson Correlation function using a Community.Components function.

References:
Pearson Correlation - a Community.Components function

Example

This code plots both implementations of the Pearson Correlation formula taking correlation of RSI and CMO for example:

using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators; using Community.Indicators;

namespace WealthLab.Strategies { public class MyStrategy : WealthScript { protected override void Execute() { int Period = 99; CMO cmo = CMO.Series(Close,20); RSI rsi = RSI.Series(Close,20); DataSeries c1 = CorrelationXL.Series( cmo, rsi, Period ); DataSeries c2 = Correlation.Series( cmo, rsi, Period ); HideVolume(); ChartPane c = CreatePane( 50, false, true ); ChartPane c_ = CreatePane( 50, false, true ); PlotSeries (c, c1, Color.Black, WealthLab.LineStyle.Solid, 3); PlotSeries (c_, c2, Color.Blue, WealthLab.LineStyle.Solid, 3); } } }