turloughmack

0 Reputation

2 Badges

13 years, 357 days

MaplePrimes Activity


These are questions asked by turloughmack

Can anybody please help me I posted this question last week and didnt get the response I was looking for. It is a question about explicit finite difference methods for pricing an option.

I understand the mathematics behind this and everything but I am not able to code it. This is where the probelem lies.

Can somebody show me how to input this into maple please

f_i+1,j := (a_j)(f_i,j-1) + (b_j)(f_i,j) + (c_j)(f_i,j+1)

 

where 

a_j := [1/2 (r-q) j Delta t - 1/2 sigma^2 j^2 Delta t] 

b_j := [1 + sigma^2 j^2 Delta t + r Delta t] 

c_j := [-1/2 (r-q) j Delta t - 1/2 sigma^2 j^2 Delta t] 

 

with r:= 0.05, Delta t:= T/N , Delta S:=S/M, T:=0.4, q:=0, K:=1.1, S:=2, M=N:=10

Can anybody please help :

a_j := [-1/2 (r-q) j Delta t + 1/2 sigma^2 j^2 Delta t] / 1 + r Delta t

b_j := [1 - sigma^2 j^2 Delta t] / 1 + r Delta t

c_j := [1/2 (r-q) j Delta t + 1/2 sigma^2 j^2 Delta t] / 1 + r Delta t

 

with r:= 0.05, Delta t:= T/N , Delta S:=S/M, T:=0.4, q:=0, K:=1.1, S:=2, M=N:=10

 

Then I defined i:=N; such that f_{i,j}:=max(K - j*Delta S, 0);

And next I defined g_{k,j}:=f_{i,j}...

Could somebody help me I am having trouble with an if statement.

I have defined three functions a.b and c in terms of one variable j.

I have correctly defined g_{k,j} as well as other functions and now I have run into trouble with my if statement.

p:=(k,j)->if k=0 then max(K-j*S,0) else g_{k,j} end if

I think its clear what i am trying to achieve in the if statement as I want to be able to enter p(1,4), p(4,3) etc. . .  after the if statement...

I need to define a tridiagonal matrix in maple in such a way that

 

[1 0 0 0 0. . . . . . . . . . . . . . . . 0]

[a(1) b(1) c(1) 0 0 . . . . . . . . . .0]

[0    a(2)  b(2)  c(2) 0 0 0 . . . . .0]

[0     0     a(3)  b(3) c(3) 0 0  . . 0]

[0 . . . . . . . . . . . . . . . . . . . . . . .]

[0.. . . . . . . . . . . . . . . . . . . . . . .]

1 2 Page 1 of 2