This demo shows how to use Physics-Informed Neural Networks (PINNs) to find the market value of call options in MATLAB®. In this example, we utilize the Optimization Toolbox™ and Deep Learning Toolbox™.
The Black-Scholes equation is a widely used mathematical model for pricing options and other financial derivatives. It describes the price evolution of an option over time, taking into account factors such as the underlying asset price, volatility, risk-free interest rate, and the option's strike price and maturity.
The Black-Scholes equation is a partial differential equation (PDE) of the form:
where
The Black-Scholes equation has an analytical solution, known as the Black-Scholes formula, which gives the exact option price under certain assumptions. However, in more complex scenarios or when the assumptions are violated, numerical methods are often employed to solve the equation.
Physics-Informed Neural Networks (PINNs) are a class of deep learning models that incorporate physical laws and domain knowledge into the neural network training process. PINNs are particularly useful for solving PDEs and other physical systems, as they can learn the solution while respecting the underlying governing equations.
The key idea behind PINNs is to use the neural network to represent the solution to the PDE and then define a loss function that consists of two parts:
- The mismatch between the neural network predictions and the initial and boundary conditions.
- The residual of the PDE, which measures how well the neural network satisfies the governing equation.
By minimizing this composite loss function, the neural network learns to approximate the solution to the PDE while adhering to the physical constraints.
In this example, we demonstrate how to solve the Black-Scholes equation using PINNs in MATLAB. The main steps involved are:
- Generate training data: We create a set of input points (stock prices and times) and corresponding initial and boundary conditions based on the Black-Scholes formula.
- Define the neural network architecture: We construct a fully connected neural network with a suitable number of layers and neurons to represent the option price function.
- Customize the loss function: We implement a customized loss function that includes the mismatch between the neural network predictions and the initial and boundary conditions, as well as the residual of the Black-Scholes equation.
- Train the neural network: We use the Adam optimizer algorithm to minimize the loss function and learn the optimal network parameters.
- Evaluate the trained model: We compare the neural network predictions with the analytical solutions.
We can visualize and change the settings from Deep Network Designer. In this app, you easily build deep learning networks interactively. Analyze the neural networks to check if the defined architecture is correct and detect problems before training.
In this section, we compare the numerical solutions with the analytic solutions to Black Scholes PDE at different maturity time
Comparing the prediction and analytical solutions, the PINNs approximation has the accuracy in the shape of the true solutions. However, the PINNs perform underestimates from the analytic solutions as the maturity time increases. The accuracy could be improved by considering different types of loss functions. In the current settings, the total loss function is consisted by three components: PDE loss, initial value loss, and boundary value loss. The results may be improved by trying smooth
- Solve Partial Differential Equation with L-BFGS Method and Deep Learning
- Solve Poisson Equation on Unit Disk Using Physics-Informed Neural Network
- A. Dhiman, Y. Hu, Physics Informed Neural Network for Option Pricing, arXiv:2312.06711
- S. Wang, S. Sanharan, H. Wang, and P. Perdikaris, An expert's guide to training physics-informed neural networks, arXiv:2308.08468
- SciML-and-Physics-Informed-Machine-Learning-Examples