## Making a Wildebeest Correlation plot

August 6, 2009 by wildebeests

What I’ve set out to do with the **Wildebeest Correlation Index** is to create a rolling correlation of prices and stockpiles. The correlation data then gets plotted with the line changing colour depending on the correlation: green for negatively correlated data and red for positively correlated data. The input is a list with the form {date, price, stockpile} …

From the initial data we create a temporary list of prices and stockpiles:

temp2 = data[[All,{2, 3}]]

This list is then partitioned into subsets of length chosen by the number, num, of points required for the correlation.The partitioned list is mapped on to the Correlation function:

temp = Correlation[#[ [All,1]], #[[All,2]] ]& /@ Partition[temp2, num, 1]

Next step is to add back the dates and make the plot. To make the line change colour we want to define a ColorFunction which sets the colour to be between green and red depending on the *y* value of the data:

ColorFunction→Function[{x,y}, Blend[{Green,Red},y]]

The Mathematica shortform notation for this function is written as

ColorFunction→(Blend[{Green,Red},#2]&)

An example of a WCI plot

### Like this:

Like Loading...

*Related*

## Leave a Reply