[Cmpl] Error messages & some basic syntax questions
Richard Baverstock
richard.baverstock at gmail.com
Thu Dec 27 01:37:53 EST 2012
Hi,
I'm trying to learn how to use cmpl by writing a small model that
approximates a polynomial to bond spot rates.
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 ...
I'm also curious - on page 31 of http://www.coliop.org/download/CMPL.pdf,
the constaints and objective sections need to be in linear forms. Is
non-linear optimization not supported in the CMPL language?
Thanks,
Richard
Errors:
-bash-3.2$ cmpl immunize.cmpl
CMPL model generation - running
CMPL version: 1.7.1
Authors: Thomas Schleiff, Mike Steglich
Distributed under the GPLv3
create model instance ...
error (compiler): file immunize.cmpl line 35: syntax error, unexpected
SYMBOL_VAR
error (compiler): file immunize.cmpl line 42: syntax error, unexpected
DEFS_TMP_ASSIGN, expecting ':'
error (compiler): file immunize.cmpl line 42: syntax error, unexpected '}',
expecting end of file
CMPL model generation - failed
CMPL file immunize.cmpl:
parameters:
# Car lease payments, 36 month term
nPayments := 36;
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, );
# Bonds. Assumes face value of 100, and 2 bonds at each maturity date (to
# create a zero-coupon bond)
daysSinceLastCoupon := 131;
daysInCurrentPeriod := 184;
nBonds := 6;
coupon[] := (0.0388, 0.0063, 0.0075, 0.0313, 0.0400, 0.0125);
askPrice[] := (101.531, 100.219, 100.531, 102.781, 105.313, 101.469);
couponsLeft[] := (1, 1, 2, 2, 3, 3);
aiMultiplier := daysSinceLastCoupon / daysInCurrentPeriod;
{j:=1(1)dim(coupon): ai[j] := aiMultiplier * coupon[j]/2; }
{j:=1(1)dim(coupon): actualPrice[j] := askPrice[j] + ai[j] * 100; }
# Create zero-coupon bonds. Assumes all have face values of 100.
{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]); }
# Spot rates for zero-coupon bonds
{j:=1(1)dim(zeroPrice): zeroSpot[j] := -ln(100/zeroPrice[j]); }
variables:
a[1..5]: real;
s[1(1)dim(coupon)/2]: real;
linApproxPrice[1..dim(coupon)]: real;
d[1(1)dim(coupon)/2]: real;
objectives:
# Find a linear approximation to the spot rates
spotRateAprox: sum{j:=1(1)dim(coupon):
((actualPrice[j]-linApproxPrice[j]))^2} ->min;
constraints:
-20 <= a[] <= 20;
# Calculate intermediate variables
{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); }
{j:=1(1)dim(coupon)/2: d[j] = (1 / ((1 + (s[j]/2))^couponsLeft[j])); }
{j:=1(1)dim(coupon)/2: facePV[j] = d[j] * 100; }
{j:=1(1)dim(coupon): cPaymentLeft[j] = coupon[j] * 100 * (1 - d[j]) /
s[floor((j + 1)/2)]; }
{j:=1(1)dim(coupon): linApproxPrice[j] = facePV[floor((j+1)/2)] +
cPaymentLeft[j]; }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.coin-or.org/pipermail/cmpl/attachments/20121226/5813edea/attachment.html>
More information about the Cmpl
mailing list