<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>