Hello lists,
First i would like to thank you Irv for your help and explanation. I
did use the debugger while i was tracing the content of the variables. That
problem was solved already. A very simple mistake was causing the problem.
I was thinking that the sqr function of VB is sqr also of Lingo which is not
at all. It is the sqrt function of lingo!
But anyways, i have this other program code in VB which will compute
for a Price Binomial (part of our project). The VB code contains part which
is having a negative value for the index of the array. I was making a
linear list as its equivalent code in Lingo but the big problem is Lingo
does not allow zero or negative index values for the list, am i right?
Below is the VB code which needs to be converted to Lingo.
------
Function binom_opt(ameuro As String, callput As String, spot As Double,
strike As Double, vola As Double, rate As Double, divi As Double, days As
Double, n As Integer)
Dim delta_t As Double, disc As Double
Dim up As Double, dn As Double
Dim p1 As Double, p2 As Double, a As Double
Dim i As Integer, j As Integer, phi As Integer
Dim f10 As Double, f11 As Double, f20 As Double
Dim f21 As Double, f22 As Double
Dim price As Double, delta As Double, gamma As Double, theta As Double
Dim vega As Double, rho As Double
Dim t1 As Double, t2 As Double
Dim vola1 As Double
Dim rate1 As Double
Dim divi1 As Double
Dim time As Double
Dim values(4, 1) As Double
ReDim v(-n To n) As Double ' option price
ReDim s(-n To n) As Double ' stock price
vola1 = vola / 100
rate1 = rate / 100
divi1 = divi / 100
time = days / 365
If callput = "c" Then
phi = 1
ElseIf callput = "p" Then
phi = -1
End If
delta_t = time / n
up = Exp(vola1 * Sqr(delta_t))
dn = 1 / up
a = Exp((rate1 - divi1) * delta_t)
p1 = (a - dn) / (up - dn)
p2 = 1 - p1
disc = Exp(-rate1 * delta_t)
p1 = p1 * disc
p2 = p2 * disc
--this is the part where the problem starts
s(0) = spot
For j = 1 To n Step 1
s(j) = s(j - 1) * up
s(-j) = s(-j + 1) * dn
Next j
' at end nodes
For j = -n To n Step 2
v(j) = dmax(phi * (s(j) - strike), 0)
Next j
For i = n - 1 To 0 Step -1 ' time loop
For j = -i To i Step 2 ' space loop
v(j) = p1 * v(j + 1) + p2 * v(j - 1) ' european
If ameuro = "a" Then ' american
t1 = phi * (s(j) - strike)
t2 = v(j)
v(j) = dmax(t1, t2)
End If
If i = 1 And j = 1 Then
f11 = v(j)
ElseIf i = 1 And j = -1 Then
f10 = v(j)
ElseIf i = 2 And j = -2 Then
f20 = v(j)
ElseIf i = 2 And j = 0 Then
f21 = v(j)
ElseIf i = 2 And j = 2 Then
f22 = v(j)
End If
Next j
Next i
price = v(0)
binom_opt = price
End Function
Any suggestion or help is greatly appreciated.
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!]