1.3. Consider The Bond-Portfolio Problem Formulated in Section 1.3. Reformulate The Problem

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

1.3. Consider the bond-portfolio problem formulated in section 1.3.

Reformulate the problem


restricting the bonds available only to bonds A and D. Further add a constraint that the holding of
the municipal bonds must be less than or equal to $3 million.
a). What the optimal solution?
c). How much can the municipal limit be relaxed before it becomes a nonbinding constraint?

from gurobipy import *

try:
# Create a new model
m = Model('Portfolio Selection')

# Create variables (lowerbound at 0 by default)


x = m.addVar(vtype = GRB.CONTINUOUS, name = 'x', lb = 0, ub = 3)
y = m.addVar(vtype = GRB.CONTINUOUS, name = 'y', lb = 4, ub = GRB.INFINITY)

# Integrate new variable


m.update()

# Set object
m.setObjective(0.043*x + 0.0022*y, GRB.MAXIMIZE)

m.addConstr(x+y <= 10, 'c0')

m.addConstr(3*x - 2*y <= 0, 'c1')

m.addConstr(2*x - y <= 0, 'c2')

m.optimize()

print 'Model Status: ', m.status

for v in m.getVars():
print v.varName, v.x

except GurobiError:
print 'Error Report'
OUTPUT:

Optimize a model with 3 rows, 2 columns and 6 nonzeros


Coefficient statistics:
Matrix range [1e+00, 3e+00]
Objective range [2e-03, 4e-02]
Bounds range [3e+00, 4e+00]
RHS range [1e+01, 1e+01]
Presolve removed 3 rows and 2 columns
Presolve time: 0.01s
Presolve: All rows and columns removed
Iteration Objective Primal Inf. Dual Inf. Time
0 1.4440000e-01 0.000000e+00 0.000000e+00 0s

Solved in 0 iterations and 0.01 seconds


Optimal objective 1.444000000e-01
Model Status: 2
x 3.0
y 7.0

1.9

python code:

from gurobipy import *

try:
# Create a new model
m = Model('Portfolio Selection')

# Create variables (lowerbound at 0 by default)


x1 = m.addVar(vtype = GRB.CONTINUOUS, name = 'x1', lb = 250, ub =
GRB.INFINITY)
x2 = m.addVar(vtype = GRB.CONTINUOUS, name = 'x2', lb = 375, ub =
GRB.INFINITY)
x3 = m.addVar(vtype = GRB.CONTINUOUS, name = 'x3', lb = 150, ub =
GRB.INFINITY)

# Integrate new variable


m.update()

# Set object
m.setObjective(3*x1 + 9*x2 + 25*x3, GRB.MAXIMIZE)

m.addConstr(0.1*x1 + 0.2*x2 + 0.7*x3 <= 250, 'c0')


m.addConstr(0.2*x1 + 0.35*x2+ 0.1*x3 <= 350, 'c1')

m.addConstr(0.1*x1 + 0.2*x2 + 0.3*x3 <= 150, 'c2')

m.optimize()

print 'Model Status: ', m.status

for v in m.getVars():
print v.varName, v.x

except GurobiError:
print 'Error Report'

OUTPUT:
Optimize a model with 3 rows, 3 columns and 9 nonzeros
Coefficient statistics:
Matrix range [1e-01, 7e-01]
Objective range [3e+00, 2e+01]
Bounds range [2e+02, 4e+02]
RHS range [2e+02, 4e+02]
Presolve removed 3 rows and 3 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Iteration Objective Primal Inf. Dual Inf. Time
0 8.2916667e+03 0.000000e+00 0.000000e+00 0s

Solved in 0 iterations and 0.00 seconds


Optimal objective 8.291666667e+03
Model Status: 2
x1 250.0
x2 375.0
x3 166.666666667

You might also like