In this article, we build a very simple PDE solver for the Black-Scholes Equation. Using the Finite Volume Discretization Method, we derive the equations required for an efficient implementation in Matlab. The implicit Euler time-stepping of the solver guarantees a stable behavior and convergence.
All posts in this series:
- Basics of a PDE solver in Matlab
- Pricing American options with a PDE solver
- Efficient pricing of barrier options
Discretizing the Black-Scholes PDE using a Finite Volume Method
The Black-Scholes PDE is a Cauchy-Problem in backwards time where the initial values are given by the payoff at maturity. We denote the asset price by , the value of the option by
, the volatility of the asset by
and the risk free rate by
. Furthermore, a partial derivative is denoted by a subscript as usual for numerical PDE solutions. The solver is an implicit finite volume discretization of
(1)
working backwards in time from maturity to present time . This equation is defined using the backwards time
. We integrate equation (1) over a finite volume
using the discrete values
, where
.
That means that the cell boundaries are placed half way between the nodes at
After the integration of equation (1) over the th cell, we obtain
.
In the following, we denote the value of the option at time and asset price
as
.
Using approximations we get
Furthermore, we get for the other terms
On the left hand side of equation (1), we get
.
All the above equations finally lead to
where we have to define the time level of the right hand side.
Implicit Euler Discretization
Choosing a time level for the right hand side, we get a so-called explicit discretization; choosing a level of
the discretization is called implicit. The implicit discretization is more stable so that we will use
(2)
in the following. The final algorithm of the PDE solver is obtained by rearranging equation (2) in a matrix such that linear equation
(3)
with the known vector and the unknown
can be solved by Matlab.
The boundary, i.e. the first and the last element of can be assumed as
Translation into M-Code
Now, we write a program which implements the PDE solver. We use equally distant time steps in and a structured mesh in the
direction.
In this implementation, we compute the price of a put option with ,
,
,
and
. Furthermore, we use a start mesh with
S = [0:20:60 65:5:90 92:1:110 115:5:150 160:20:200 300 500 1000];
and set the initial values at maturity time to
V = max(K-S',0);" % value of V at maturity time
, i.e.
.
Generation of the mesh
We use a resolution of 200 time steps. Then, we use an algorithm for refine the mesh and the time steps such that we can easily control the accuracy by changing a single parameter: “refine”.
% Pricing a European Option with a PDE method (finite volumes) % init S with a structured mesh clear; refine = 4; S = [0:20:60 65:5:90 92:1:110 115:5:150 160:20:200 300 500 1000]; for i=1:refine-1 Sn(1:2:length(S)*2) = S; Sn(2:2:length(S)*2-1) = (S(2:length(S)) -S(1:length(S)-1))/2 + S(1:length(S)-1); S = Sn; end
Start parameters
% define parameters for Option sigma = 0.4; r = 0.05; K = 100; T = 2; time_steps = round(400 *2^(refine-1)* T); % calculate size of time step dtau = T/time_steps; % V(t=T) = payoff at maturity V = zeros(length(S),time_steps+1); V(:,1) = max(K-S',0); % Define values for S_i_minus, S_i and S_i_plus for convenient access Sm = S(1:length(S)-2); Si = S(2:length(S)-1); Sp = S(3:length(S));
Assemble discretization matrix
Rearranging equation (2), we find that matrix is a tri-diagonal matrix with the following properties:
% compute values for m_i_minus, m_i and m_i_plus according to the formula given m_i = 1 + (sigma^2*Si.^2*dtau).*(1./( (Sp-Sm).*(Sp-Si) ) +1./( (Sp-Sm).*(Si-Sm) ) ) + r*dtau; m_i = [1+r*dtau m_i 1]; % boundary condition m_iplus =-(sigma^2*Si.^2*dtau)./((Sp-Sm).*(Sp-Si)) - Si.*r*dtau./(Sp-Sm); m_iplus = [0 m_iplus]; m_iminus = -(sigma^2*Si.^2*dtau)./((Sp-Sm).*(Si-Sm)) + Si.*r*dtau./(Sp-Sm); m_iminus = [m_iminus 0]; % assemble matrix M from (sub-) diagonals M = diag(m_i) + diag(m_iminus,-1) + diag(m_iplus,1);
Solve for all time-steps
Now, the solver according to equation (3) is simple. It solves for at each time step
:
% solve for V(t_0) for tau=1:time_steps V(:,tau+1) = M\V(:,tau); end
Analyze results
Finally, we use Matlab to present the computations:
%% plot the option values figure(1); mesh(S,0:dtau:T,V'); title('V(S,t)','FontWeight','bold'); xlabel('asset price S','FontWeight','bold'); ylabel('time','FontWeight','bold'); zlabel('option value V','FontWeight','bold');
And we can zoom in on , the strike price of the option:
figure(2); index= find((S>60) & (S<120)); mesh(S(index),0:dtau:T,V(index,:)'); title('V(S,t) zoomed on S in [60,120]','FontWeight','bold'); xlabel('asset price S','FontWeight','bold'); ylabel('time','FontWeight','bold'); zlabel('option value V','FontWeight','bold');
We can analyze the hedge parameter delta, , the first derivative of
w.r.t.
.
V_S=(V(3:end,time_steps+1)-V(1:end-2,time_steps+1))./(Sp-Sm)'; figure3 = figure(3); axes4 = axes('Parent',figure3,'YGrid','on','XGrid','on','FontWeight','bold','FontSize',12); box(axes4,'on'); hold(axes4,'all'); plot(S(2:length(S)-1),V_S,'LineWidth',2); title('Delta: V_S(S,t_0)','FontWeight','bold'); xlabel('asset price S','FontWeight','bold'); ylabel('option value V','FontWeight','bold');
We can analyze the hedge parameter gamma, , the second derivative of
w.r.t.
.
V_SS=2*(V_S(3:end)-V_S(1:end-2))./(Sp(3:end)-Sm(1:end-2))'; figure4 = figure(4); axes4 = axes('Parent',figure4,'YGrid','on','XGrid','on','FontWeight','bold','FontSize',12); box(axes4,'on'); hold(axes4,'all'); plot(S(3:length(S)-2),V_SS,'LineWidth',2); title('Gamma V_S_S(S,t_0)','FontWeight','bold'); xlabel('asset price S','FontWeight','bold'); ylabel('option gamma V_S_S','FontWeight','bold');
Conclusion
This article presents a simple yet efficient PDE solver for the Black-Scholes Equation. This solver uses a finite volume discretization and an implicit Euler time-stepping.
Update 15.4.2012:
- Improved accuracy for
- Changed formula for time_steps to represent convergence
- General code cleaning
Leave a Reply