Iteration of a finite difference scheme in a two-dimensional array with three boundary conditions

In the intermediate step to completing my thesis, I am trying to solve the Black-Scholes PDE in R using an explicit difference-difference scheme. At the moment, I constantly focus on the simultaneous repetition in time (as time is discretized) and on discretization of stock prices. I applied the boundary conditions for the European challenge and am trying to decide my way back in accordance with the description of Phil Goddard for the model.

R <- matrix(NA, ncol=length(t), nrow=length(S)) # Value at Maturity: R[,length(t)] <- Vold <- pmax(S - K,0) # Value at S = S_max; V = fwd R[length(S),] <- V_max <- S_max - K * exp(-r_yr * (t_T - t)) # Value at S = S_0; V = 0 R[1,] = V_min <- t - t # Run Model # ----------------------------------------------------------------------------------------- # Define Coefficient-Functions a_j, b_j, and c_j a_ <- function(j){ a_j <- (1/2) * dt * (r*j - sigma^2 * j^2) return(a_j) } b_ <- function(j){ b_j <- 1 + dt * (sigma^2 * j^2 + r) return(b_j) } c_ <- function(j){ c_j <- -(1/2) * dt * (r*j + sigma^2 * j^2) return(c_j) } # Move backward in time stepping on each stock price within the BCs S = S_0, S = S_max for (i in length(t):2){ for (j in (length(S)-1):2){ R[,(length(i)-1)][j] <- b_(j) * R[,length(i)][j] + c_(j) * R[,length(i)][j+1] + a_(j) * R[,length(i)][j-1] } } 

I discretized the time and price of shares, so that the user can specify the desired number of grid points (as a result, the nodes are "length (t)" and "length (S)"). Since I indicate 3 outer edges of the matrix R (2 through time in S_max and S_0 along the columns of R; 1 through the initial value of the parameter at the time of maturity, the last column of R), I repeat the length of the columns minus 1 and the length of the rows minus 2.
(see chart link for further description)

Link to BC image at bottom of page

When I run the model, the boundary conditions will take effect correctly, but I can’t move further in time ... Any manual on my (probably filled with news) code would be very useful. Please let me know if there is anything else I can add (code or description) to clarify.

Thanks,

Jake

+6
source share

All Articles