This gets the inner loops vectorized (gets about a 100x speed improvement on my machine):
rho1 = 1 - rho;
for t=1:size(datesdaily1,1)
w = weig1(t,:) .* sqrt(Rates(t,:));
x = w.' * w;
y = x .* rho;
z = x .* rho1;
numerator = numerator + sum(y(~isnan(y)));
denominator = denominator + sum(z(~isnan(z)));
end
Could potentially vectorize the outer loop as well, but may run into memory issues if the variable sizes are large. What are your variable sizes?