Speed improvement possible?

It would help with an example to actually run the code.
That said, making the i loop the inner loop will help:

function AddMatrixToInput!(row,day,instrument,Imatrix,pcMatrix,rankedcorrelationlist,lookback,relatedInstruments)
    for j=1:relatedInstruments, i in 1:lookback
        Imatrix[i,j,row]=min(max(pcMatrix[day-i,rankedcorrelationlist[instrument,j]],-0.2),0.25)
    end
end

You could also use annotations like @inbounds. I’d recommend reading the performance tips.

3 Likes