Hello lists,
I have this problem with the values returned after calling a function
handler. Below are the handler definitions.
----this is the handler that calls the function cum1_compute
on compute_prices
-- global variable declarations
global s, x, vola, rate, div, days
global vola1, rate1, div1, timeperiod, d1, d2
global cvalue1, cvalue2, callprice, putprice
global pvalue1, pvalue2, pargu1, pargu2
--set the floatprecision that is the number of decimals to be displayed
the floatPrecision = 4
--convert field to numeric values
s = float(value(member("StkP").text))
x = float(value(member("Strike Price").text))
vola = float(value(member("Volatility").text))
rate = float(value(member("Interest rate").text))
div = float(value(member("Dividends").text))
days = float(value(member("day").text))
vola1 = vola/100.0
rate1 = rate/100.0
divi1 = div/100.0
timeperiod =days/365.0
d1 = float((log(s/x) + ((rate1 - divi1 + 0.5 * vola1 * vola1) *
timeperiod))/(vola1 * power(timeperiod, 2)))
d2 = float(d1 - vola1 * power(timeperiod,2))
---computes for call price
cvalue1 = float(1.0 * (s * exp(-(divi1) * timeperiod)) *\
cum1_comput(1.0 * d1)) -- this part calls the function
cvalue2 = float(1.0 * (x * exp(-(rate1) * timeperiod)) *\
cum1_compute(1.0 * d2)) --- calls the function again with
diff.
value of parameter passed
callprice = float(cvalue1 - cvalue2)
--computes for put price
pvalue1 = float(-(1.0) * s * exp(-(divi1) * timeperiod) * \
cum1_compute(-(1.0) * d1))
pvalue2 = float(-(1.0) * x * exp(-(rate1) * timeperiod) * \
cum1_compute(-(1.0) * d2))
putprice = float(pvalue1 - pvalue2)
--display answer to fields
put putprice into field "Put Price"
put callprice into field "Call Price"
end
-----the function handler definition
on cum1_compute value_param
--make a list of constant yy values
yy=[:]
yy = ["0.31938153","-(0.356563782)","1.781477937",\
"-(1.821255978)","1.330274429"]
gamma=0.2316419
pi2 = float(2*pi)
expovalue = float(-(value_param)*(value_param*0.5))
fak = float(1/power(pi2, 2)) * float(exp(expovalue))
z = float(1/(1+(gamma * abs(value_param))))
fak1 = float(z * value(yy[5]))
repeat with i = 4 down to 1
fak1 = float(z * float(fak1 + value(yy[i])))
end repeat
cum1 = float(1.0 - fak*fak1)
if (value_param < 0) then
cum1 = float(1.0 - cum1)
end if
--returns value to compute_prices handler
return cum1
end cum1_compute
I tried to display the actual value computed with the function handler and
also the value actually computed in the calling handler, and i noticed that
the calling function is using a different value in the computation than what
was passed by the function handler.
I really am confused why is this so? Is there something wrong with the
computation or the passing of values?
The original formula for this computation is given to us in Visual Basic
code.
Also, is it really a must to declare variables used in computation to be
global in scope? I tried declaring the variable vola1 as local (set vola1 =
0.0) but when i test the value in the message window it returned a <VOID>
value. Why is this?
I would really appreciate it if you experts can help me solve this problem.
thanks in advance,
ellen
[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/lingo-l.cgi To post messages to the list,
email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo. Thanks!]