-1
$\begingroup$

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?

$\endgroup$
  • $\begingroup$ 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? $\endgroup$ – SRKX Oct 7 '15 at 7:28
  • $\begingroup$ 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. $\endgroup$ – SmallChess Oct 7 '15 at 7:29
  • $\begingroup$ @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 $\endgroup$ – user161976 Oct 7 '15 at 8:20
  • $\begingroup$ @SRKX, thanks for editing. please can you verify for me? $\endgroup$ – user161976 Oct 7 '15 at 12:27
  • $\begingroup$ 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... $\endgroup$ – SRKX Oct 8 '15 at 1:04
0
$\begingroup$

I don't understand how you derived the boundary conditions in your code. You're supposed to get the option price (binary payoff) based on the strike, but I just don't see the variable K is even used in the boundary conditions.

I also don't quite follow how you compute theta. Your implementation looks different to the formulas I see in http://www.goddardconsulting.ca/option-pricing-finite-diff-explicit.html.

There is a good C++ reference implementation if you need help:

https://www.quantstart.com/articles/C-Explicit-Euler-Finite-Difference-Method-for-Black-Scholes

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.