<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. </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. </div><div><br></div><div>e.g.:</div><div><i>spotRateAprox: sum{j:=1(1)dim(coupon): ((actualPrice[j]-linApproxPrice[j]))^2} ->min; </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. </div><div><br></div><div><i>sum{j: =1(1)count(coupon): </i><i>actualPrice[j]^2 + 2 * </i><i>actualPrice[j] * linApproxPrice[j] + </i><i>linApproxPrice[j] * </i><i>linApproxPrice[j] } ->min;</i></div><div><i><br></i></div><div>This polynomial contains the products <i>linApproxPrice[j]*</i><i>linApproxPrice[j] </i>that can be used if the variables <i>linApproxPrice[j]</i> are integers and lower and upper bounds have been specified. To avoid accuracy problems it would make sense to scale the variables <i>linApproxPrice[j] </i>(e.g. by a factor 100)<i>.</i> But this leads to a increased amount of artificial variables which are automatically generated by CMPL for the reformulation of the products of variables. </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. </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 & 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 <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 </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 </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> # Car lease payments, 36 month term</div><div> nPayments := 36;</div>
<div> 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> # Bonds. Assumes face value of 100, and 2 bonds at each maturity date (to</div><div> # create a zero-coupon bond)</div><div> daysSinceLastCoupon := 131;</div><div> daysInCurrentPeriod := 184;</div><div> nBonds := 6;</div>
<div> coupon[] := (0.0388, 0.0063, 0.0075, 0.0313, 0.0400, 0.0125);</div><div> askPrice[] := (101.531, 100.219, 100.531, 102.781, 105.313, 101.469);</div><div> couponsLeft[] := (1, 1, 2, 2, 3, 3);</div><div><br>
</div><div> aiMultiplier := daysSinceLastCoupon / daysInCurrentPeriod;</div><div><br></div><div> {j:=1(1)dim(coupon): ai[j] := aiMultiplier * coupon[j]/2; }</div><div> {j:=1(1)dim(coupon): actualPrice[j] := askPrice[j] + ai[j] * 100; }</div>
<div><br></div><div> # Create zero-coupon bonds. Assumes all have face values of 100.</div><div> {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> # Spot rates for zero-coupon bonds</div><div> {j:=1(1)dim(zeroPrice): zeroSpot[j] := -ln(100/zeroPrice[j]); }</div><div><br></div><div><br></div><div>variables:</div><div> a[1..5]: real;</div><div>
s[1(1)dim(coupon)/2]: real;</div><div> linApproxPrice[1..dim(coupon)]: real;</div><div> d[1(1)dim(coupon)/2]: real;</div><div><br></div><div>objectives:</div><div> # Find a linear approximation to the spot rates</div>
<div> spotRateAprox: sum{j:=1(1)dim(coupon): ((actualPrice[j]-linApproxPrice[j]))^2} ->min;</div><div><br></div><div><br></div><div>constraints:</div><div> -20 <= a[] <= 20;</div><div><br></div><div> # Calculate intermediate variables</div>
<div> {j:=1(1)dim(coupon)/2: 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> {j:=1(1)dim(coupon)/2: d[j] = (1 / ((1 + (s[j]/2))^couponsLeft[j])); }</div>
<div> {j:=1(1)dim(coupon)/2: facePV[j] = d[j] * 100; }</div><div> {j:=1(1)dim(coupon): cPaymentLeft[j] = coupon[j] * 100 * (1 - d[j]) / s[floor((j + 1)/2)]; }</div><div> {j:=1(1)dim(coupon): 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>