Objective:
maximize :((((alpha1*5000)+(alpha2*0.49431))-5000) + (((alpha1*5000)+(alpha2*0.49431))-0.49431))
constarints:
mod(alpha) <= 1
Code:
from scipy.optimize import minimize
alpha = [0,0];v1 = 5000
v2 = 0.49431537320810676
def objective(alpha,sign = -1.0):
alpha1 = alpha[0]
alpha2 = alpha[1]
return sign*((((alpha1*5000)+(alpha2*0.49431537320810676))-5000) + (((alpha1*5000)+(alpha2*0.49431537320810676))-0.49431537320810676))
def constraint1(alpha):
return (1- abs (alpha[0]))
def constraint2(alpha):
return (1- abs (alpha[1]))
con1 = {'type':'ineq','fun':constraint1}
con2 = {'type':'ineq','fun':constraint2}
cons = [con1,con2]
sol = minimize(objective,alpha,method='SLSQP',constraints = cons)
I have given the sign in the objective function to change the optimization to maximize.
Solution:
(sol.x)
>>>>[ 1.00104909 0.99560862]
I have given the constraints for the alpha for it to be less than 1 , but getting the solutions more than 1.