Question: Invalid Subscript Selector

Hi everyone,

I am trying to write a proc for the binomial method for option prices.  I have the following code:

treeStockPrices := proc (s0, X, r, sigma, T, N)

local dt, u, d, a, b, p, L, i, j, k, m;

global f;

dt := evalf(T/N);

u := evalf(exp(sigma*sqrt(dt)));

d := 1/u; a := evalf(exp(r*dt));

b := evalf(exp(-r*dt));

p := (a-d)/(u-d);

L := [[s0]];

for i from 1 to N do L := [op(L), [seq(s0*u^j*d^(i-j), j = 0 .. i)]] end do;

f := L;

for i from 1 to N+1 do f[N+1] := [seq(max(L[N+1, i]-X, 0), i = 1 .. N+1)] end do;

for i from 1 to N do for j from 1 to i do f[N-i+1, j] := b*(p*f[N-i+2, j+1]+(1-p)*f[N-i+2, j]);

L[N, j] := f[N, j] end do end do

end proc

I got no errors pushing enter, but when I write

treeStockPrices(50.0, 50.0, .10, .40, .4167, 5)

and push enter i get invalid subscript selector? 

I have been working on this for a while but I can't make it work!  It seems that maple doesn't know what these are.

 

Please, Please someone help!

Thanks, Manny

Please Wait...