# Is the code of my binary call option pricer (using explicit finite difference, backward scheme) correct? [closed]

I am using explicit finite difference (backward scheme) to price a binary call option.

Here is my MATLAB code:

clear
clc

S=100;
K=100;
R=0.05;
Sigma=0.2;
T=1;

% Binary Option
d1=(log(S/K)+(R+0.5*Sigma^2)*T)/(Sigma*sqrt(T));
d2=d1-(Sigma*sqrt(T));

Binary_BS=normcdf(d2)*exp(-R*T);

%% Finite Difference Method

% Stability Condition

Asset_Steps=400;
ds=2*K/Asset_Steps;
dt=0.9/(Asset_Steps*Asset_Steps)/(Sigma*Sigma);
NTS=round(T/dt)+1;
dt=T/NTS;

% Allocation Memory
V_New=zeros(Asset_Steps+1,1);

% Setting The Payoff Function
Stock=(1:(Asset_Steps+1))*ds;
Payoff(Stock>K,1)=1;
V_Old=Payoff;

%Solving The Grid

for k=NTS:-1:0

for i=(Asset_Steps):-1:2

% Discretizing The Option Value and Computing The Greeks

Delta= (V_Old(i + 1) - V_Old(i - 1)) / (2*ds);

Gamma= (V_Old(i + 1) - 2 * V_Old(i) + V_Old(i - 1)) / (ds*ds);

Theta = -0.5 * Sigma * Sigma * Stock(i) * Stock(i) * Gamma + ...
R*(V_Old(i)-(Stock(i) * Delta));  % Black Scholes PDE Solving

V_New(i) = V_Old(i) - dt * Theta; % Explicit Scheme

end

% Boundary Conditions

V_New(1) = V_Old(1) * (1 - R * dt); % Lower Boundary

V_New(Asset_Steps+1) = 2 * V_New(Asset_Steps) - V_New(Asset_Steps - 1); % Upper Boundary

%Marching Backwards in T

V_Old=V_New;

end

% Interpolate the Grid to find the Option Value for the Stock Price

FDM_Binary=spline(Stock,V_New,S);


Is the way how I code the boundary conditions correct?

## closed as too broad by chollida, SRKXOct 8 '15 at 1:03

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• We're not going to review your code for you here... do you have any reason to doubt the correctness of your pricer? if so, why? – SRKX Oct 7 '15 at 7:28
• I can review the code if you bother to tell me why you think it's wrong. To check your results, just compare your price with a closed formula. – SmallChess Oct 7 '15 at 7:29
• @StudentT, I am newbie when it comes to matlab, I want to be sure if I have done the right thing. I would appreciate if you can help me out, I want to be sure if my boundary conditions are right. I am just learner. thank you – user161976 Oct 7 '15 at 8:20
• @SRKX, thanks for editing. please can you verify for me? – user161976 Oct 7 '15 at 12:27
• No we won't, unless you provide example of inputs and outputs and tell us what seems wrong. Otherwise the question is just too broad, and if you don't know how to proceed, then ask another question on how to verify an option pricer's code... – SRKX Oct 8 '15 at 1:04