I would like to calculate the correlation matrix using linq, with a single phrase. How can I do that (if it is possible)?
Assume I have already an array of size N called volatilites and Returns is a jagged array, with N arrays all of the same size.
I am also using:
using stats = MathNet.Numerics.Statistics.ArrayStatistics
and this is the code that I want to make in LINQ:
double[,] correlation_matrix = new double[N,N];
for (int i=0; i<N;i++){
for (int j = i + 1; j < N; j++){
correlation_matrix [i,j]= stats.Covariance(Returns[i], Returns[j]) / (volatilities[i] * volatilities[j]); // stores it to check values
}
}
thanks!
Aggregateto fill out 2d array to LINQ-fy that code into single statement, but I doubt anyone would see it as improvement.