File size: 501 Bytes
97dcf92
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from scipy.optimize import linprog

# Coefficients for the objective function (negative because linprog does minimization)
c = [-0.88, -0.88, -0.85]

# Coefficients for the inequality constraint (sum of weights = 1)
A = [[1, 1, 1]]
b = [1]

# Bounds for each weight (between 0 and 1)
bounds = [(0, 1), (0, 1), (0, 1)]

# Solve the linear programming problem
result = linprog(c, A_eq=A, b_eq=b, bounds=bounds)

# The optimal weights
optimal_weights = result.x
print("Optimal weights:", optimal_weights)