minimize_constrained: SystemError: error return without exception set

asked 2013-12-11 22:48:21 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

The Sage function

# SBI Dom Gov T: Best Fit (Constrained) of Present Values and Yields
# individual yields y0, .., y18 at times t_CHF[0], .., t_CHF[18] (len(t_CHF)==19) 
# bond_present_value_2() - linear interpolation
var('y0 y1 y2 y3 y4 y5 y6 y7 y8 y9 y10 y11 y12 y13 y14 y15 y16 y17 y18')
def R2c(y0,y1,y2,y3,y4,y5,y6,y7,y8,y9,y10,y11,y12,y13,y14,y15,y16,y17,y18):
    Ly=[y0,y1,y2,y3,y4,y5,y6,y7,y8,y9,y10,y11,y12,y13,y14,y15,y16,y17,y18]
    L2y=[]
    for i in range(0,len(t_CHF),1):
        L2y.append((t_CHF[i],Ly[i]))
    R2y=0
    for i in range(0,m_DGT,1):
        bi=bond(100,SBI_DGT[i,4],bond_FCP(SBI_DGT[i,4],1),SBI_DGT[i,1]*100,1)
        pi=bond_present_value_2(bi,L2y)
        R2y=R2y+(pi-SBI_DGT[i,0])^2
    return R2y
L_cnst=[]; eps=0.1
for i in range(0,len(t_CHF),1):
    L_cnst.append((r2_CHF[i]-eps*abs(r2_CHF[i]),r2_CHF[i]+eps*abs(r2_CHF[i])))
L_start=[]
for i in range(0,len(t_CHF),1):
    L_start.append(r2_CHF[i])
ylds3=minimize_constrained(R2c(y0,y1,y2,y3,y4,y5,y6,y7,y8,y9,y10,y11,y12,y13,y14,y15,y16,y17,y18),L_cnst,L_start)
Lylds3=[]
for i in range(0,len(t_CHF),1):
    Lylds3.append((t_CHF[i],ylds3[i]))
Yylds3=spline(Lylds3)
pylds3a=plot(Yylds3,ta2_CHF,tb2_CHF,color="red",thickness=2,linestyle="-")+point(Lylds3,color="red",size=30)
pylds3b=plot(Yylds3,ta2_CHF,tb2_CHF,color="red",thickness=1,linestyle="--")

produces the error message

Traceback (most recent call last):        L2y=[]
  File "", line 1, in <module>

  File "/tmp/tmpZ6oSFc/___code___.py", line 23, in <module>
    ylds3=minimize_constrained(R2c(y0,y1,y2,y3,y4,y5,y6,y7,y8,y9,y10,y11,y12,y13,y14,y15,y16,y17,y18),L_cnst,L_start)
  File "/home/sage/sage-5.12/local/lib/python2.7/site-packages/sage/numerical/optimize.py", line 450, in minimize_constrained
    min= optimize.fmin_tnc(f,x0,gradient,bounds=cons,messages=0,**args)[0]
  File "/home/sage/sage-5.12/local/lib/python2.7/site-packages/scipy/optimize/tnc.py", line 262, in fmin_tnc
    res = _minimize_tnc(fun, x0, args, jac, bounds, callback=callback, **opts)
  File "/home/sage/sage-5.12/local/lib/python2.7/site-packages/scipy/optimize/tnc.py", line 397, in _minimize_tnc
    xtol, pgtol, rescale, callback)
SystemError: error return without exception set

The same function

# eb rexx: Best Fit (Constrained) of Present Values and Yields
# individual yields y0, .., y17 at times t_EUR[0], .., t_EUR[17] (len(t_EUR)==18) 
# bond_present_value_2() - linear interpolation
var('y0 y1 y2 y3 y4 y5 y6 y7 y8 y9 y10 y11 y12 y13 y14 y15 y16 y17')
def R2d(y0,y1,y2,y3,y4,y5,y6,y7,y8,y9,y10,y11,y12,y13,y14,y15,y16,y17):
    Ly=[y0,y1,y2,y3,y4,y5,y6,y7,y8,y9,y10,y11,y12,y13,y14,y15,y16,y17]
    L2y=[]
    for i in range(0,len(t_EUR),1):
        L2y.append((t_EUR[i],Ly[i]))
    R2y=0
    for i in range(0,m_REXX,1):
        bi=bond(100,EB_REXX ...
(more)
edit retag flag offensive close merge delete