I often find it useful to calculate the correlation of two time-based variables directly inside MySQL. For example:-
SELECT calcCorrelation('BHP','RIO','3600');
Where the first two inputs are the variable selections and the third is the time based quantization to use. Since MySQL does not have any built-in corr() function you need to do the heavy lifting yourself with a stored function.

