<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi Richard,<div><br></div><div>CMPL is intended to formulate and solve linear programs. Therefore all objectives and constraints have to be formulated as linear expressions.&nbsp;</div><div>The only nonlinear term that is allowed are products of variables if at least one of the factors is an integer variable.</div><div><br></div><div>Your model must fail because there a couple of nonlinear terms.&nbsp;</div><div><br></div><div>e.g.:</div><div><i>spotRateAprox: sum{j:=1(1)dim(coupon): ((actualPrice[j]-linApproxPrice[j]))^2} -&gt;min;&nbsp;</i></div><div><br></div><div>It is not permitted that variables are imbedded in brackets (at the moment). Therefore you have to reformulate your objective function into a polynomial of the second degree.&nbsp;</div><div><br></div><div><i>sum{j: =1(1)count(coupon): &nbsp;&nbsp;</i><i>actualPrice[j]^2 + &nbsp;2 *&nbsp;</i><i>actualPrice[j] * linApproxPrice[j] +&nbsp;</i><i>linApproxPrice[j] *&nbsp;</i><i>linApproxPrice[j] &nbsp; } -&gt;min;</i></div><div><i><br></i></div><div>This polynomial contains the products&nbsp;<i>linApproxPrice[j]*</i><i>linApproxPrice[j]&nbsp;</i>that can be used if the variables&nbsp;<i>linApproxPrice[j]</i>&nbsp;are integers and lower and upper bounds have been specified. To avoid accuracy problems it would make sense to scale the variables&nbsp;<i>linApproxPrice[j] </i>(e.g. by a factor 100)<i>.</i>&nbsp;But this leads to a increased amount of artificial variables which are automatically generated by CMPL for the reformulation of the products of variables.&nbsp;</div><div><br></div><div>It seems that is is possible to formulate your problem in form of a MIP but you have to "pay" it with a huge amount of variables or a lack in the accuracy.</div><div><br></div><div>We are planning to support nonlinear programs but this will be a long-term process.<br><br></div><div>Thanks,</div><div><br></div><div>Mike</div><div><i><br></i></div><div><br></div><div><br><br></div><div><br></div><div><br><div><div>Am 27.12.2012 um 07:37 schrieb Richard Baverstock:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr">Hi,<div><br></div><div style="">I'm trying to learn how to use cmpl by writing a small model that approximates a polynomial to bond spot rates.&nbsp;</div><div style=""><br></div><div style="">Things are looking good, but calculation of some intermediate variables seems to be causing problems. I'm placing these calculations in the constraints section, as is done in the quadratic-assignment.cmpl example. The errors I see &amp; the .cmpl file I am using are at the end of the email. The SYMBOL_VAR seems related to s[j], but I'm not fluent enough in the language yet to see what the issue is ...</div>
<div style=""><br></div><div style="">I'm also curious - on page 31 of&nbsp;<a href="http://www.coliop.org/download/CMPL.pdf">http://www.coliop.org/download/CMPL.pdf</a>, the constaints and objective sections need to be in linear forms. Is non-linear optimization not supported in the CMPL language?</div>
<div style=""><br></div><div style="">Thanks,</div><div style="">Richard</div><div style=""><br></div><div style="">Errors:</div><div style=""><br></div><div style=""><div>-bash-3.2$ cmpl immunize.cmpl&nbsp;</div><div>CMPL model generation - running</div>
<div><br></div><div>CMPL version: 1.7.1</div><div>Authors: Thomas Schleiff, Mike Steglich</div><div>Distributed under the GPLv3&nbsp;</div><div><br></div><div>create model instance ...</div><div>error (compiler): file immunize.cmpl line 35: syntax error, unexpected SYMBOL_VAR</div>
<div>error (compiler): file immunize.cmpl line 42: syntax error, unexpected DEFS_TMP_ASSIGN, expecting ':'</div><div>error (compiler): file immunize.cmpl line 42: syntax error, unexpected '}', expecting end of file</div>
<div>CMPL model generation - failed</div><div><br></div><div><br></div><div style="">CMPL file immunize.cmpl:</div><div style=""><br></div><div style=""><div>parameters:</div><div>&nbsp; # Car lease payments, 36 month term</div><div>&nbsp; nPayments &nbsp;:= 36;</div>
<div>&nbsp; payments[] := (3927, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, 472, );</div><div><br></div>
<div>&nbsp; # Bonds. Assumes face value of 100, and 2 bonds at each maturity date (to</div><div>&nbsp; # create a zero-coupon bond)</div><div>&nbsp; daysSinceLastCoupon := 131;</div><div>&nbsp; daysInCurrentPeriod := 184;</div><div>&nbsp; nBonds &nbsp; &nbsp; &nbsp; &nbsp;:= 6;</div>
<div>&nbsp; coupon[] &nbsp; &nbsp; &nbsp;:= (0.0388, 0.0063, 0.0075, 0.0313, 0.0400, 0.0125);</div><div>&nbsp; askPrice[] &nbsp; &nbsp;:= (101.531, 100.219, 100.531, 102.781, 105.313, 101.469);</div><div>&nbsp; couponsLeft[] := (1, 1, 2, 2, 3, 3);</div><div><br>
</div><div>&nbsp; aiMultiplier := daysSinceLastCoupon / daysInCurrentPeriod;</div><div><br></div><div>&nbsp; {j:=1(1)dim(coupon): &nbsp;ai[j] &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:= aiMultiplier * coupon[j]/2; }</div><div>&nbsp; {j:=1(1)dim(coupon): &nbsp;actualPrice[j] := askPrice[j] + ai[j] * 100; }</div>
<div><br></div><div>&nbsp; # Create zero-coupon bonds. Assumes all have face values of 100.</div><div>&nbsp; {j:=1(1)dim(coupon)/2: zeroPrice[j] := ( -coupon[2*j]/(coupon[2*j-1] - coupon[2*j]) * actualPrice[2*j-1] + (1-( -coupon[2*j]/(coupon[2*j-1] - coupon[2*j]))) * actualPrice[2*j]); }</div>
<div><br></div><div>&nbsp; # Spot rates for zero-coupon bonds</div><div>&nbsp; {j:=1(1)dim(zeroPrice): zeroSpot[j] := -ln(100/zeroPrice[j]); }</div><div><br></div><div><br></div><div>variables:</div><div>&nbsp; a[1..5]: real;</div><div>
&nbsp; s[1(1)dim(coupon)/2]: real;</div><div>&nbsp; linApproxPrice[1..dim(coupon)]: real;</div><div>&nbsp; d[1(1)dim(coupon)/2]: real;</div><div><br></div><div>objectives:</div><div>&nbsp; # Find a linear approximation to the spot rates</div>
<div>&nbsp; spotRateAprox: sum{j:=1(1)dim(coupon): ((actualPrice[j]-linApproxPrice[j]))^2} -&gt;min;</div><div><br></div><div><br></div><div>constraints:</div><div>&nbsp; -20 &lt;= a[] &lt;= 20;</div><div><br></div><div>&nbsp; # Calculate intermediate variables</div>
<div>&nbsp; {j:=1(1)dim(coupon)/2: &nbsp;s[j] = a[1] + a[2] * ((1 - j)/2) + a[3] * (((1-j)/2)^2) + a[4] * (((1-j)/2)^3) + a[5] * (((1-j)/2)^4); }</div><div>&nbsp; {j:=1(1)dim(coupon)/2: &nbsp;d[j] = (1 / ((1 + (s[j]/2))^couponsLeft[j])); }</div>
<div>&nbsp; {j:=1(1)dim(coupon)/2: &nbsp;facePV[j] = d[j] * 100; }</div><div>&nbsp; {j:=1(1)dim(coupon): &nbsp; &nbsp;cPaymentLeft[j] = coupon[j] * 100 * (1 - d[j]) / s[floor((j + 1)/2)]; }</div><div>&nbsp; {j:=1(1)dim(coupon): &nbsp; &nbsp;linApproxPrice[j] = facePV[floor((j+1)/2)] + cPaymentLeft[j]; }</div>
<div><br></div></div></div></div>
_______________________________________________<br>Cmpl mailing list<br><a href="mailto:Cmpl@list.coin-or.org">Cmpl@list.coin-or.org</a><br>http://list.coin-or.org/mailman/listinfo/cmpl</blockquote></div><br></div></body></html>