Log in to see Cloud of Tags

Wealth-Lab Wiki

Syntax

public static double Correlation(this double">"> x, double[ y, int n)

public double Correlation(double">"> x, double[ y, int n)


Parameter Description

xArray of double values (first data series)
yArray of double values (second data series)
nCorrelation lookback period

Description

Calculates Pearson Correlation. Uses code from ALGLIB project.

Example

The following example demonstrates how well correlated were CMO and RSI:

Example using C# extension methods:

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

namespace WealthLab.Strategies { public class CorrelationDemo : WealthScript { protected override void Execute() { // How well correlated were CMO and RSI?

int n = Bars.Count; double">n"> x = new double[n; double">n"> y = new double[n; RSI rsi = RSI.Series( Close, 20 ); CMO cmo = CMO.Series( Close, 20 ); for(int bar = 0; bar < Bars.Count; bar++) { xbar = rsibar; ybar = cmobar; } DrawLabel( PricePane, "Correlation: " + x.Correlation( y, n ) ); } } }


Legacy syntax example:

using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators; using Community.Components; // Correlation here

namespace WealthLab.Strategies { public class CorrelationDemo : WealthScript { protected override void Execute() { // How well correlated were CMO and RSI?

int n = Bars.Count; double">n"> x = new double[n; double">n"> y = new double[n; RSI rsi = RSI.Series( Close, 20 ); CMO cmo = CMO.Series( Close, 20 ); for(int bar = 0; bar < Bars.Count; bar++) { xbar = rsibar; ybar = cmobar; } Calculate calc = new Calculate(this); // pass WealthScript DrawLabel( PricePane, "Correlation: " + calc.Correlation( x, y, n ) ); } } }

Important Disclaimer: The information provided by Wealth-Lab is strictly for informational purposes and is not to be construed as advice or solicitation to buy or sell any security.  The owner of Wealth-Lab.com assumes no liability resulting from the use of the material contained herein for investment purposes. By using this web site, you agree to the terms of this disclaimer and our Terms of Use.


ScrewTurn Wiki. Some of the icons created by FamFamFam.