Using Optimization toolbox in nonlinear with matrix manipulation

I'm looking for optimization problem as follows that I don't know how to optimize it through Matlab Code or toolbox.
I have a minimum costs problem
The Parameters are follows:
BidPrices=[4735,4730,4727;410,409.7,409;59,58.8,58.5]; % Parameters which include 3 bid prices columns for 3 securities.
BidQuantity=[7000,2500,1081;320,1500,25000;754000,20000,101026]; % Bid Quantity for each bid
OpenPrice=[4735 ;410 ;59.1] % The open Price
Weights=[0.5;0.25;0.25]
Quantity=zeros(3:3) % variable to minimize
f=Qunatity*BidPrices % The function to minimize
The constraints are:
% Positive nonzero interger quantity
Quantity>=0
Quantity=Integer
% Quantity cannot exceed its bid quantity
Quantity(:,1)<=BidQuantity(:,1);
Quantity(:,2)<=BidQuantity(:,2);
Quantity(:,3)<=BidQuantity(:,3);
% The total change in the index from OpenPrice is higher than 1%
% First Step: Define active price matrix because when the quantity from bid1 to bid2 also change the price of the index
for I=1:length(OpenPrice)
if Quantity(I,1)>0 && Quantity(I,2)>0
EffectivePrice(I,1)=0
else
EffectivePrice(I,1)=0
end
if EffectivePrice(I,1)==0 && Quantity(I,2)==0 && Quantity(I,3)==0
EffectivePrice(I,2)=0
else
EffectivePrice(I,2)=0
end
if EffectivePrice(I,1)==0 && Quantity(I,3)>0
EffectivePrice(I,3)=1
else
EffectivePrice(I,3)=0
end
end
% Step 2: Defining the Constraint
Constraint=((EffectivePrice*BidPrices*Weights)/(OpenPrice*Weights))-1<=0.01
% How to write it correctly in Matlab code so that matlab can solve it? I didn't succeed with the toolbox.

1 Comment

f=Qunatity*BidPrices % The function to minimize
This is a 3x3 matrix-valued quantity, so it is not clear what it means to "minimize" it

Sign in to comment.

Answers (2)

You would use INTLINPROG in the Optimziation Toolbox

9 Comments

But how do I set this problem in intlinprog? How I need to define the constraints in a function?
Well, that is your homework assignment so we can't do it for you here, however, it appears that you only have upper and lower bound constraints. Note that intlinprog lets you specify these directly with arguments, lb,ub. From the documentation,
x = intlinprog(f,intcon,A,b,Aeq,beq,lb,ub)
This is not a homework assignment, it is a optimization for index changes I need to calculate. In addition, how do I use the constraint of the effective price? How do I define 3*3 matrix of quantities?
Use linear indexing and a vector of length 9
But than I will lose the constrain on the bid column. I need it like a matrix
It is not possible to specify a matrix constraint. The values being processed are converted to vector form.
But it does not matter, because you can rewrite your constraint in terms of linear indexing for any constraint supported short of nonlinear constraints. Nonlinear constraints are expressed by a function handle and inside the function you can reshape if you really need to.
Does the optimization toolbox can use a matrix of variables, like in excel?
Any matrix of variables will be either rejected by the algorithm or reshaped into a vector, depending on which routine you are using.
Can you please help me to demonstrate how to rephrase the last constraint (of the limitation of 1%)

Sign in to comment.

You have
Constraint=((EffectivePrice*BidPrices*Weights)/(OpenPrice*Weights))-1<=0.01
and at any one point, EffectivePrice is the vector of trial values and BidPrices and Weights and OpenPrice are inputs.
So start doing some algebra:
((EffectivePrice*BidPrices*Weights)/(OpenPrice*Weights))-1<=0.01
impies
((EffectivePrice*BidPrices*Weights)/(OpenPrice*Weights)) <= 1.01
implies
((EffectivePrice*BidPrices*Weights) <= 1.01 * (OpenPrice*Weights)
implies
EffectivePrice <= 1.01 * (OpenPrice*Weights) / (BidPrices*Weights)
Everything on the right hand side is known in advance, so it can be computed as an upperbound.
Now at this point we run into the problem that OpenPrice and Weights are both 3 x 1 so you cannot "*" them together. If we guess that the formula should be
1.01 * (OpenPrice.*Weights) / (BidPrices*Weights)
then we get
ans =
0.505346858984519 0 0
0.0218787974850742 0 0
0.00315374861309241 0 0
Now as we go back through the code we can see that EffectivePrice is a binary variable, value 0 except in the case EffectivePrice(I,1)==0 && Quantity(I,3)>0 . And we can see that all of the constraint values are either 0 or a value less than 1. With the value required to be binary, this tells us that EffectivePrice must be identically 0.
This analysis assumes that when you write
Constraint=((EffectivePrice*BidPrices*Weights)/(OpenPrice*Weights))-1<=0.01
that even though ((EffectivePrice*BidPrices*Weights)/(OpenPrice*Weights)) is a 3 x 3 matrix, that you want the "-1" to be applied to all 9 entries. The calculations become different if the "-1" should instead be eye(3)
... You still have not explained how you can "minimize" f=Qunatity*BidPrices which is 3 x 3

1 Comment

In the "EffectivePrice", the condition is that the second bid should be effective only after the quantity of the first bid is filled. Hence, I'm not sure if the condition in RHS is a true constraint. Regarding the minimization of the function, I want that the cost of changing the price by 1% (which costs money when buying the first, second, third bid), would be minimized. Did I write this wrong?

Sign in to comment.

Asked:

on 4 Jan 2017

Commented:

on 7 Jan 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!