I have a weighted sum:

weighted sum = w1*mu1 + (1-w1)*mu2

with

variance weighted sum = (w1^2)*var1 + ((1-w1)^2)*var2 + 2*w1*(1-w1)*cov

where

mu1 = mean 1; mu2 = mean 2; var1 = variance for mean 1; var2 = variance for mean 2; cov = covariance; w1 = weight.

My objective is to compute the value of w1 that provides the highest absolute abratio

(w1*mu1 + (1-w1)*mu2)/ sqrt((w1^2)*var1 + ((1-w1)^2)*var2 + 2*w1*(1-w1)*cov)

which is actually a Z statistic.

It is possible to take the derivative and to obtain an equation that finds the critical point assuming that w1 may assume any value. However, Is it possible to obtain an equation that maximizes the absolute ratio (weighted sum)/sqrt(variance_weighted_sum) limiting the possible values of w1 between 0 and 1 or between 0 and 2?

Actually, I would like an advice to know if this is feasible using derivatives, or if it is only possible via non-linear programming.

I will be very grateful for any help.