• C++ Programming for Financial Engineering
    Highly recommended by thousands of MFE students. Covers essential C++ topics with applications to financial engineering.
    Python for Finance with Intro to Data Science
    Gain practical understanding of Python to read, understand, and write professional Python code for your first day on the job.
    An Intuition-Based Options Primer for FE
    Ideal for entry level positions interviews and graduate studies, specializing in options trading arbitrage and options valuation models.

Constrained Opt. with Non-linear Obj and Constraints

Wallstyouth

Vice President
I have a collection of m items T = [t1, t2, …tm] each of quantity Q = [q1, q2, …qm]. I need to distribute these m items to n people P = [p1, p2, …pn]. Ideally, the items would be distributed according to a fixed schedule, an m x n F = [fij], where fij = fkj for all j and any i,k in [1,m] and sum(F) = 1. Unfortunately there are restrictions on how each item may be partitioned that prevent this ideal distribution. So I must settle for some best distribution X = {xij}. My goal is to find X such that I minimize the error from the ideal distribution given the constraints on each items partitioning.

Here’s how I set it up for MATLAB’s fmincon:

Objective: min f(x) = sum(sqrt(( X / F – 1)^2)

Such that,

Constraint 1 (c(x) <= 0):
c(x) = - X*Q + A, where A = [a1, a2, …,am] and ai < qi for all I (in my problem A is each securities’ minimum tradable lot)

Constraint 2 (ceq(x) = 0):
ceq(x) = mod(X*Q, L), where L = [l1, l2, …lm] and li | ai for all I (in my problem L is each securities’ minimum tradable increment)

Constraint 3 (Aeq*X = beq): to ensure column sum of xij = 1 for all j.
Aeq(x) = ones(m, m*n) (m*n columns since MATLAB treats guess R x C matrix x0 as (R*C x 1) vector.
beq(x) = ones(1, m)

Boundaries:
lb = zeros (no short allocations)
ub = ones (max allocation is 100%)

I keep getting the MaxFunEvals error. I’ve tried kicking up the count but it doesn’t help. I think the problem is: set up wrong, poorly conditioned, getting bogged down on “flat spot” of f(x), I’m sure others… Can anyone suggest how to make this better or a better way of doing this? Thanks in advance.
 

Tsotne

Well-Known Member
could we put this into a code editor? We might get a solution.
 

Tsotne

Well-Known Member
I evaluated it and I think first of all you have a logic error.

Aeq(x) = ones(m, m*n)

Why don't split the matrix into n row vectors, (or m column vectors but its harder) and it'll make your vector easier to manipulate.

I keep getting the MaxFunEvals error.

I think you have defined the matrix boundaries incorrectly (not sure though) . You can divide the matrix into n rows and remove irrelevant rows if they all contain elements all equal to 0. BTW, is this the only method you want to evaluate the problem with? There are many optimization algorithms I am aware. Not this one. Take simplex, dual-simplex, modified simplexes(can also be converted for nonlinear optimizations), Newton - Raphson, Karmarkar... depending on whether the problem is linear or nonlinear.
 
Top