org.akutan.numerics
Class FiniteDifferenceSolver

java.lang.Object
  extended by org.akutan.numerics.FiniteDifferenceSolver

public class FiniteDifferenceSolver
extends java.lang.Object

This class implements several numerical methods to compute the one dimensional solution to the Black-Scholes european call option. As a check it also uses an external implementation of an analytic solution to Black-Scholes. The methods include a simple binomial tree, explicit finite differences, implicit finite differences and Crank-Nicolson method. TODO Implement a more direct solution to the tridiagonal matrix problem so as to introduce fewer errors into the solution (because of inverting the matrix). TODO Improve the Crank-Nicolson code, it doesn't seem to work so well. TODO Implement better algorithms from the Finite Differences school, perhaps ADI?


Constructor Summary
FiniteDifferenceSolver()
          Constructs
 
Method Summary
 double binomialOption(double asset, double strike, double expiry, double volatility, double rate, int steps)
          Uses binomial model to compute price of european call option
 double crankNicolson(double asset, double strike, double expiry, double volatility, double rate, int param, int steps)
          Uses Crank-Nicolson Finite differences method to compute price of call option.
 double explicitOptionValue(double asset, double strike, double expiry, double volatility, double rate, int param, int steps)
          Uses explicit Finite differences method to compute price of call option
 double implicitOptionValue(double asset, double strike, double expiry, double volatility, double rate, int param, int steps)
          Uses implicit Finite differences method to compute price of call option.
static void main(java.lang.String[] args)
          Example code to illustrate the calling sequence for the various methods within this class.
 cern.colt.matrix.DoubleMatrix2D solveTridiagonal(cern.colt.matrix.DoubleMatrix2D Min, cern.colt.matrix.DoubleMatrix2D Din)
          Solves a tri-diagonal system of equations parsimoniusly using Gaussian Elimination.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FiniteDifferenceSolver

public FiniteDifferenceSolver()
Constructs

Method Detail

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Example code to illustrate the calling sequence for the various methods within this class. TODO Should be moved into a JUnit test case.

Parameters:
args -
Throws:
java.lang.Exception

solveTridiagonal

public cern.colt.matrix.DoubleMatrix2D solveTridiagonal(cern.colt.matrix.DoubleMatrix2D Min,
                                                        cern.colt.matrix.DoubleMatrix2D Din)
Solves a tri-diagonal system of equations parsimoniusly using Gaussian Elimination. This algorithm is taken from the paper "A Note on the Numerical Solution of the Black-Scholes-Merton PDE" by Christensen and Munk.

Parameters:
Min - Input matrix (left side)
Din - Input vector (right side)
Returns:
Vector (returned as single column matrix) containing the solution to the tri-diagonal system

binomialOption

public double binomialOption(double asset,
                             double strike,
                             double expiry,
                             double volatility,
                             double rate,
                             int steps)
Uses binomial model to compute price of european call option

Parameters:
asset - Current price of the asset
strike - Option strike price
expiry - Time to expiry in years
volatility - Volatility of the asset price
rate - Risk free interest rate - rate of dividends
steps - Number of steps to use to solve
Returns:
Value of the option given the parameters

explicitOptionValue

public double explicitOptionValue(double asset,
                                  double strike,
                                  double expiry,
                                  double volatility,
                                  double rate,
                                  int param,
                                  int steps)
                           throws java.lang.Exception
Uses explicit Finite differences method to compute price of call option

Parameters:
asset - Current price of asset
strike - Strike price of option
expiry - Time to expiry in years
volatility - Volatility of the asset price
rate - Risk free rate - dividend rate
param - Indicates which quantity to compute, 0 = Price, 1 = Delta, 2 = Gamma, 3 = Theta
steps -
Returns:
Returns the parameter specified
Throws:
java.lang.Exception

implicitOptionValue

public double implicitOptionValue(double asset,
                                  double strike,
                                  double expiry,
                                  double volatility,
                                  double rate,
                                  int param,
                                  int steps)
                           throws java.lang.Exception
Uses implicit Finite differences method to compute price of call option. Taken from Hull and White.

Parameters:
asset - Current price of asset
strike - Strike price of option
expiry - Time to expiry in years
volatility - Volatility of the asset price
rate - Risk free rate - dividend rate
param - Indicates which quantity to compute, 0 = Price, 1 = Delta, 2 = Gamma, 3 = Theta
steps -
Returns:
Returns the parameter specified
Throws:
java.lang.Exception

crankNicolson

public double crankNicolson(double asset,
                            double strike,
                            double expiry,
                            double volatility,
                            double rate,
                            int param,
                            int steps)
                     throws java.lang.Exception
Uses Crank-Nicolson Finite differences method to compute price of call option. Taken from Hull and White, and from Christensen and Munk, 2004.

Parameters:
asset - Current price of asset
strike - Strike price of option
expiry - Time to expiry in years
volatility - Volatility of the asset price
rate - Risk free rate - dividend rate
param - Indicates which quantity to compute, 0 = Price, 1 = Delta, 2 = Gamma, 3 = Theta
steps -
Returns:
Returns the parameter specified
Throws:
java.lang.Exception