Skip to content
All library documents

Boundary Conditions in an Explicit Finite-Difference Binary Option Pricer

Article Quant Q&A · Author: user161976

Summary

The document presents MATLAB code for pricing a cash-or-nothing binary call with an explicit finite-difference scheme and asks whether its boundary conditions are correct. The response questions how the conditions were derived, noting that the strike does not appear in them, and also raises concerns about the calculation of the time-related term in the discretized equation.

The answer does not provide a full correction or derive replacement conditions. It points to standard Black–Scholes finite-difference references, including a C++ example, as ways to compare the implementation with established formulas. The exchange is therefore useful as a diagnostic prompt, but it offers little direct evidence about which boundary treatment is valid. Readers should consult the referenced numerical methods and derive conditions consistent with the binary payoff and chosen grid before relying on the code.

Key ideas

  • The code applies an explicit finite-difference method to a binary call option.
  • The answer questions whether the boundary conditions follow from the option payoff.
  • The response also flags the discretized time evolution formula for review.
  • The exchange does not derive corrected boundary conditions or validate the implementation.

Tags

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


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












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?

## Answer by SmallChess (score 0, accepted)

https://quant.stackexchange.com/a/21108

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

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.