0

I'm new to the community and finally, here I am for my first question!

I'm stuck on a Maximization problem (you can see it below):

Problem Set enter image description here

My variables are set in this way:

pass;               import numpy    as np
from scipy.optimize import minimize

n_bond = 4

# Vector of Present Value for each Bond
pv_vec = [ 115.34755980259271, 100.95922248766202,
            93.87539028309668, 93.63295880149812
            ]

# Vector of Duration for each Bond
dur_vec = [4.880937192589091, 5.1050167320620625, 3.713273768775609, 1.0]

# Vector of Convexity for each Bond
conv_vec = [31.66708597860361, 33.73613393551434, 18.098806559076504, 2.0]

# Initial guess
alpha = np.random.random(n_bond)
alpha = alpha / np.sum(alpha)

W0 = 1000   # Initial wealth
K  =    3.5 # Target Duration

def obj(self):
    return sum(conv_vec[i]*(pv_vec[i]*alpha[i])/W0 for i in range(n_bond))*(-1)

def cons1(self):
    return sum(pv_vec[i]*alpha[i] for i in range(n_bond)) - W0

def cons2(self):
    return sum(dur_vec[i]*(pv_vec[i]*alpha[i])/W0 for i in range(n_bond)) - K

const = ({'type': 'eq', 'fun': cons1},
         {'type': 'eq', 'fun': cons2})

non_neg = []
for i in range(n_bond):
    non_neg.append((0, None))

non_neg = tuple(non_neg)

solution = minimize(fun=obj,
                    x0=alpha,
                    method='SLSQP',
                    bounds = non_neg,
                    constraints=cons,
                    options = {'disp':True, 'ftol': 1e-20, 'maxiter': 1000})

And now the error message of minimization:

Singular matrix C in LSQ subproblem    (Exit mode 6)
            Current function value: -2.5052545159234914
            Iterations: 1
            Function evaluations: 6
            Gradient evaluations: 1
     fun: -2.5052545159234914
     jac: array([0.00000, 0.00000, 0.00000, 0.00000])
 message: 'Singular matrix C in LSQ subproblem'
    nfev: 6
     nit: 1
    njev: 1
  status: 6
 success: False
       x: array([0.27557, 0.38912, 0.07314, 0.26217])

I really need your wisdom!

user3666197
  • 1
  • 6
  • 50
  • 92
gillo
  • 1
  • 2
  • Possible duplicate of [scipy minimize SLSQP - 'Singular matrix C in LSQ subproblem'](https://stackoverflow.com/questions/56222292/scipy-minimize-slsqp-singular-matrix-c-in-lsq-subproblem) – csabinho Nov 24 '19 at 23:50
  • I had already tried to look at the post that you suggested, unfortunately I could not connect it to my question! Since I'm not very practical with python if you could help me with the code it would be really appreciated. – gillo Nov 25 '19 at 09:19

0 Answers0