Effacer les filtres
Effacer les filtres

Using Optimization toolbox in nonlinear with matrix manipulation

2 vues (au cours des 30 derniers jours)
Yossi
Yossi le 4 Jan 2017
Commenté : Yossi le 7 Jan 2017
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 commentaire
Matt J
Matt J le 5 Jan 2017
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

Connectez-vous pour commenter.

Réponses (2)

Matt J
Matt J le 4 Jan 2017
You would use INTLINPROG in the Optimziation Toolbox
  9 commentaires
Walter Roberson
Walter Roberson le 5 Jan 2017
Any matrix of variables will be either rejected by the algorithm or reshaped into a vector, depending on which routine you are using.
Yossi
Yossi le 5 Jan 2017
Can you please help me to demonstrate how to rephrase the last constraint (of the limitation of 1%)

Connectez-vous pour commenter.


Walter Roberson
Walter Roberson le 5 Jan 2017
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 commentaire
Yossi
Yossi le 7 Jan 2017
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?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Get Started with Optimization Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by