WebCab Options and Futures Demo v2.5 (J2SE Edition)

## webcab.lib.finance.options.exotic
Class FiniteDifference

    java.lang.Object
      |
      +--webcab.lib.finance.options.exotic.FiniteDifference

All Implemented Interfaces:
  Serializable

public class FiniteDifference
extends Object
implements Serializable

Within this class we offer methods by which any option contract can be priced in accordance with the Black-Scholes-Merton model when the contract payoff function and boundary conditions of the resulting price function are given using `setPayoffFunction` and `setBoundaries`. For convenience we also provide particular cases for Asian and Lookback Extoic options which already have the relevant payoff function and boundaries internally set.

General and Specific instances of Pricing

- General Pricing Methods - The following methods are able to price any option contract in accordance with the Black-Scholes Pricing model when the Payoff function and Boundaries are given by `setPayoffFunction` and `setBoundaries`.
  - `finiteDifferencing` - Evaluates the present value of an American or European option contract with a payoff function provided by `setPayoffFunction`, in accdorance with the Black-Scholes-Merton model
  - `finiteDifferencingVector` - Evaluates a vector of `asset_price_steps` options values corresponding to a range of present underlying asset prices between `0` and `max_asset_price`, for any any American or European (single asset) option contract with a payoff function provided by
  - `multiFiniteDifferencing` - Evaluates the present value of any American or European multi-asset option contract with a payoff function provided by `setPayoffFunction`, in accordance with the Black-Scholes-Merton model using finite differencing techniques.
- Particular instances of General Pricing Methods - The following methods have a payoff function and boudaries set for Asian and Lookback options.
  - `finiteDifferencingStronglyPathDependent` - Evaluates the present value of a strongly path dependent Asian or Loopback exotic option according to the Black-Scholes-Merton model using finite difference PDE pricing techniques.
  - `finiteDifferencingVectorStronglyPathDependent` - Evaluates a strongly path dependent Asian or Lookback exotic option for a range of possible strikes in accordance with the Black-Scholes model using finite diifferencing PDE techniques.

Providing the Payoff Function adn Boundaries

When using these methods within clients the main issues which you will need to be careful with is to provide the correct payoff function and appropriate boundary conditions. The payoff function is the primary way of specifying an option contract. There are other contract parameters that are not included within the payoff, such as whether early exercise is possible. That is, whether is the option is European or American, and for strongly path dependent options any updating formulae requires which are both required in order to define an options contract explicitly. We allow you to provide this information to the method directly.

The payoff function and the boundary conditions on the other hand must be set prior to calling any of the options evaluation methods. In order to set the payoff function and boundaries you will have to instantiate some classes (either the standard classes included, or your own, custom designed classes).

Details of the Finite Differencing Approach

We apply the finite differencing approach to evaluate option prices, by solving partial differential equations (PDEs) which result from the Black-Scholes-Merton model. Please read the Mathematical documentation provided in the accompanying PDF documentation for further explanation of the implemented finite differencing techniques used.

Remark: The Programmer's Guide chapter within the accompanying PDF documentation offers further details and examples regarding the construction of the payoff function and boundary conditions and how these classes are sent to the evaluation method.

See Also:
  Serialized Form

Constructor Summary
`FiniteDifference()` Creates a new FiniteDifference instance without registering the payoff function and the boundaries function.
`FiniteDifference(PayoffFunction instanceOfPayoffFunction, Boundaries instanceOfBoundaries)` Creates a new FiniteDifference instance and submits the payoff function and the boundaries function.

Method Summary

`double`

`finiteDifferencing(int algorithm_type, int type, Date evaluationDate, Date maturityDate, double asset_price, double dividend, double interest, double volatility, double max_asset_price, int time_steps, int asset_price_steps, double tolerance, BusinessCalendar businessCalendar)`
Evaluates the present value of an American or European option contract with a payoff function provided by `setPayoffFunction`, in accdorance with the Black-Scholes-Merton model using finite differencing techniques.

`double`

`finiteDifferencing(int algorithm_type, int type, double time2Maturity, double asset_price, double dividend, double interest, double volatility, double max_asset_price, int time_steps, int asset_price_steps, double tolerance)`
Evaluates the present value of an American or European option contract with a payoff function provided by `setPayoffFunction`, in accdorance with the Black-Scholes-Merton model using finite differencing techniques.

`double`

`finiteDifferencingStronglyPathDependent(int algorithm_type, int type, int exotic_type, Date evaluationDate, Date maturityDate, double asset_price, double dividend, double interest, double volatility, double max_asset_price, double max_spd, int time_steps, int asset_price_steps, int spd_steps, double tolerance, int sampling_period, BusinessCalendar businessCalendar)`
Evaluates the present value of a strongly path dependent Asian or Loopback exotic option according to the Black-Scholes-Merton model using finite difference PDE pricing techniques.

`double`

`finiteDifferencingStronglyPathDependent(int algorithm_type, int type, int exotic_type, double time2Maturity, double asset_price, double dividend, double interest, double volatility, double max_asset_price, double max_spd, int time_steps, int asset_price_steps, int spd_steps, double tolerance, int sampling_period)`
Evaluates the present value of a strongly path dependent Asian or Loopback exotic option according to the Black-Scholes-Merton model using finite difference PDE pricing techniques.

`double[]`

`finiteDifferencingVector(int algorithm_type, int type, Date evaluationDate, Date maturityDate, double dividend, double interest, double volatility, double max_asset_price, int time_steps, int asset_price_steps, double tolerance, BusinessCalendar businessCalendar)`
Evaluates a vector of `asset_price_steps` options values corresponding to a range of present underlying asset prices between `0` and `max_asset_price`, for any any American or European (single asset) option contract with a payoff function provided by `setPayoffFunction`, in accordance with the Black-Scholes-Merton model using finite differencing PDE techniques.

`double[]`

`finiteDifferencingVector(int algorithm_type, int type, double time2Maturity, double dividend, double interest, double volatility, double max_asset_price, int time_steps, int asset_price_steps, double tolerance)`
Evaluates a vector of `asset_price_steps` options values corresponding to a range of present underlying asset prices between `0` and `max_asset_price`, for any any American or European (single asset) option contract with a payoff function provided by `setPayoffFunction`, in accordance with the Black-Scholes-Merton model using finite differencing PDE techniques.

`double[]`

`finiteDifferencingVectorStronglyPathDependent(int algorithm_type, int type, int exotic_type, Date evaluationDate, Date maturityDate, double dividend, double interest, double volatility, double max_asset_price, double max_spd, int time_steps, int asset_price_steps, int spd_steps, double tolerance, int sampling_period, BusinessCalendar businessCalendar)`
Evaluates a strongly path dependent Asian or Lookback exotic options for a range of possible strikes in accordance with the Black-Scholes model using finite diifferencing PDE techniques.

`double[]`

`finiteDifferencingVectorStronglyPathDependent(int algorithm_type, int type, int exotic_type, double time2Maturity, double dividend, double interest, double volatility, double max_asset_price, double max_spd, int time_steps, int asset_price_steps, int spd_steps, double tolerance, int sampling_period)`
Evaluates a strongly path dependent Asian or Lookback exotic options for a range of possible strikes in accordance with the Black-Scholes model using finite diifferencing PDE techniques.

`double`

`multiFiniteDifferencing(int type, Date evaluationDate, Date maturityDate, double[] asset_prices, int n_assets, double[] dividends, double interest, double[] volatility, double[][] correlation, double max_asset_price, int time_steps, int asset_price_steps, BusinessCalendar businessCalendar)`
Evaluates the present value of any American or European multi-asset option contract with a payoff function provided by `setPayoffFunction`, in accordance with the Black-Scholes-Merton model using finite differencing techniques.

`double`

`multiFiniteDifferencing(int type, double time2Maturity, double[] asset_prices, int n_assets, double[] dividends, double interest, double[] volatility, double[][] correlation, double max_asset_price, int time_steps, int asset_price_steps)`
Evaluates the present value of any American or European multi-asset option contract with a payoff function provided by `setPayoffFunction`, in accordance with the Black-Scholes-Merton model using finite differencing techniques.

`void` `setBoundaries(Boundaries instanceOfBoundaries)` Submits a new Boundary function to the FiniteDifference instance, by replacing the previous one, as sent at creation time or with a previous call to this method.
`void` `setPayoffFunction(PayoffFunction instanceOfPayoffFunction)` Submits a new Payoff Function to the FiniteDifference instance, by replacing the previous one, as sent at creation time or with a previous call to this method.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### FiniteDifference

    public FiniteDifference()

  Creates a new FiniteDifference instance without registering the payoff function and the boundaries function. Before submitting these functions using the corresponding methods you will not be able to properly use any other method.

### FiniteDifference

    public FiniteDifference(PayoffFunction instanceOfPayoffFunction,
                            Boundaries instanceOfBoundaries)

  Creates a new FiniteDifference instance and submits the payoff function and the boundaries function.

Method Detail

### setPayoffFunction

    public void setPayoffFunction(PayoffFunction instanceOfPayoffFunction)
                           throws FiniteDifferenceDemoException

  Submits a new Payoff Function to the FiniteDifference instance, by replacing the previous one, as sent at creation time or with a previous call to this method.

    `FiniteDifferenceDemoException`

### setBoundaries

    public void setBoundaries(Boundaries instanceOfBoundaries)
                       throws FiniteDifferenceDemoException

  Submits a new Boundary function to the FiniteDifference instance, by replacing the previous one, as sent at creation time or with a previous call to this method.

    `FiniteDifferenceDemoException`

### finiteDifferencing

    public double finiteDifferencing(int algorithm_type,
                                     int type,
                                     Date evaluationDate,
                                     Date maturityDate,
                                     double asset_price,
                                     double dividend,
                                     double interest,
                                     double volatility,
                                     double max_asset_price,
                                     int time_steps,
                                     int asset_price_steps,
                                     double tolerance,
                                     BusinessCalendar businessCalendar)
                              throws ExoticOptionsException,
                                     FiniteDifferenceDemoException

  Evaluates the present value of an American or European option contract with a payoff function provided by `setPayoffFunction`, in accdorance with the Black-Scholes-Merton model using finite differencing techniques. Note, that in order to apply these finite differencing PDE techniques some boundaries conditions of the pricing function on the finite differencing grid chosen much have been set using `setBoundaries`.

  Setting the boundaries

  In order to price the (European or American) option contract we are required to solve the PDE resulting from Black-Scholes-Merton model for the given payoff function (i.e. contract) under consideration. This is handled internally by the method but the whether the option being considered is American or European the values of the pricing function is going to depend on the following two variables:

  - Time until the option expires
  - Current price of the asset on which the option is defined
  The types of boundaries which you given for the price function which depends on these two coordinaites is up to you. However the following choose is popular and effective:
  - When `Time = maturity`, on this boundary the pricing function is just the payoff function.
  - When Option is deap out of the money, here we usually assume that the option will not be exercised and hence the pricing function is assumed to be zero.
  - When Option is deep in the money, here we usually assume that the option is certain to be exercised.

  Supports all Options

  This method allows (in principle) any option to be priced is accordance with the Black-Scholes model via finite differencing methods for which the user can provide the contracts payoff function using `setPayoffFunction(webcab.lib.finance.options.exotic.PayoffFunction)` and the boundary conditions of the price function on the finite differencing grid boundaries at set using `setBoundaries(webcab.lib.finance.options.exotic.Boundaries)`.

  Overview of the Algorithm
  The algorithm constructs a grid consisting of a total of time_steps x asset_price_steps points. At each iteration a new line from this grid is calculated. The last line of the grid corresponds to the option values at the current moment of time, for a range of prices varying between 0 and max_asset_price. From this vector the element corresponding to the current asset price is returned.

  Remark If you want the vector of option values corresponding to a range of the asset prices you should use `finiteDifferencingVector` to avoid a huge amount of order to guarantee redundant computation.

  Parameters:
    `type` - this parameter specifies whether the option is European or American. That is, whether the option can exercise prior to the maturity (i.e. American) or can only be exercised at the maturity (i.e. European).
    `asset_price` - the current price of the asset
    `dividend` - the continuous dividend yield the underlying asset pays
    `interest` - the continuously compounded risk-free interest rate
    `volatility` - the volatility (in years) of the asset price
    `max_asset_price` - the asset price corresponding to the last item of the finite differencing grid
    `time_steps` - the total number of iterations (the dimension of the grid on the time axis)
    `asset_price_steps` - the dimension of the grid on the price axis
    `algorithm_type` - the type of finite differencing algorithm to be used; possible values are EXPLICIT, FULLY_IMPLICIT and CRANCK_NICHOLSON.
    `tolerance` - the tolerance for the SOR iterative algorithm. This parameter is used only when American options are priced using an implicit algorithm (i.e. FULLY_IMPLICIT or CRANCK_NICHOLSON). A reasonable value for this parameter is `1E-7`.
    `evaluationDate` - the date when the value of the option is evaluated
    `maturityDate` - the date when the contract matures
    `businessCalendar` - The instance of a `BusinessCalendar` interface implementation. Specify `null` to select the London business calendar.
  Returns:
    the value of the option
    `ExoticOptionsException`
    `FiniteDifferenceDemoException`

### finiteDifferencing

    public double finiteDifferencing(int algorithm_type,
                                     int type,
                                     double time2Maturity,
                                     double asset_price,
                                     double dividend,
                                     double interest,
                                     double volatility,
                                     double max_asset_price,
                                     int time_steps,
                                     int asset_price_steps,
                                     double tolerance)
                              throws ExoticOptionsException,
                                     FiniteDifferenceDemoException

  Evaluates the present value of an American or European option contract with a payoff function provided by `setPayoffFunction`, in accdorance with the Black-Scholes-Merton model using finite differencing techniques. Note, that in order to apply these finite differencing PDE techniques some boundaries conditions of the pricing function on the finite differencing grid chosen much have been set using `setBoundaries`.

  Setting the boundaries

  In order to price the (European or American) option contract we are required to solve the PDE resulting from Black-Scholes-Merton model for the given payoff function (i.e. contract) under consideration. This is handled internally by the method but the whether the option being considered is American or European the values of the pricing function is going to depend on the following two variables:

  - Time until the option expires
  - Current price of the asset on which the option is defined
  The types of boundaries which you given for the price function which depends on these two coordinaites is up to you. However the following choose is popular and effective:
  - When `Time = maturity`, on this boundary the pricing function is just the payoff function.
  - When Option is deap out of the money, here we usually assume that the option will not be exercised and hence the pricing function is assumed to be zero.
  - When Option is deep in the money, here we usually assume that the option is certain to be exercised.

  Supports all Options

  This method allows (in principle) any option to be priced is accordance with the Black-Scholes model via finite differencing methods for which the user can provide the contracts payoff function using `setPayoffFunction(webcab.lib.finance.options.exotic.PayoffFunction)` and the boundary conditions of the price function on the finite differencing grid boundaries at set using `setBoundaries(webcab.lib.finance.options.exotic.Boundaries)`.

  Overview of the Algorithm
  The algorithm constructs a grid consisting of a total of time_steps x asset_price_steps points. At each iteration a new line from this grid is calculated. The last line of the grid corresponds to the option values at the current moment of time, for a range of prices varying between 0 and max_asset_price. From this vector the element corresponding to the current asset price is returned.

  Remark If you want the vector of option values corresponding to a range of the asset prices you should use `finiteDifferencingVector` to avoid a huge amount of order to guarantee redundant computation.

  Parameters:
    `type` - this parameter specifies whether the option is European or American. That is, whether the option can exercise prior to the maturity (i.e. American) or can only be exercised at the maturity (i.e. European).
    `time2Maturity` - the remaining time (in years) until the contract matures
    `asset_price` - the current price of the asset
    `dividend` - the continuous dividend yield the underlying asset pays
    `interest` - the continuously compounded risk-free interest rate
    `volatility` - the volatility (in years) of the asset price
    `max_asset_price` - the asset price corresponding to the last item of the finite differencing grid
    `time_steps` - the total number of iterations (the dimension of the grid on the time axis)
    `asset_price_steps` - the dimension of the grid on the price axis
    `algorithm_type` - the type of finite differencing algorithm to be used; possible values are EXPLICIT, FULLY_IMPLICIT and CRANCK_NICHOLSON.
    `tolerance` - the tolerance for the SOR iterative algorithm. This parameter is used only when American options are priced using an implicit algorithm (i.e. FULLY_IMPLICIT or CRANCK_NICHOLSON). A reasonable value for this parameter is `1E-7`.
  Returns:
    the value of the option
    `ExoticOptionsException`
    `FiniteDifferenceDemoException`

### finiteDifferencingStronglyPathDependent

    public double finiteDifferencingStronglyPathDependent(int algorithm_type,
                                                          int type,
                                                          int exotic_type,
                                                          Date evaluationDate,
                                                          Date maturityDate,
                                                          double asset_price,
                                                          double dividend,
                                                          double interest,
                                                          double volatility,
                                                          double max_asset_price,
                                                          double max_spd,
                                                          int time_steps,
                                                          int asset_price_steps,
                                                          int spd_steps,
                                                          double tolerance,
                                                          int sampling_period,
                                                          BusinessCalendar businessCalendar)
                                                   throws ExoticOptionsException,
                                                          FiniteDifferenceDemoException

  Evaluates the present value of a strongly path dependent Asian or Loopback exotic option according to the Black-Scholes-Merton model using finite difference PDE pricing techniques.

  Supported Options

  This method allows the following four types of exotic options to be evaluated:

  - Asian options with arithmetic average
  - Asian options with geometric average
  - Lookback options with maximum price evaluation
  - Lookback options with minimum price evaluation
  The type of exotic option being considered is selected using the `exotic_type` parameter. You should also specify whether the exotic option is of European or American type by using the parameter type.

  Once the option contract has been specified the options value is a function of three variables:

  - The time until the option expires
  - The present price of the asset on which the option is defined
  - ``asset measure over period" - in the case of the Asian option this is the average of the asset from inception until the present point in time
  Remark The third variable ``asset measure over period", which refers to the path dependent nature of the option contact appears within the pricing model because of the above options are strongly path dependence.

  Overview of the Algorithm
  The algorithm constructs a grid consisting of a total of `time_steps` x `asset_price_steps` x `spd_steps` points. At each iteration a new plane from this grid is calculated. The path dependent value is considered to be updated on every `sampling_period` time steps. This update process corresponds to a jump condition at the differential equation level. The last plane of the grid corresponds to the option values at the current moment of time, for a range of prices varying between `0` and `max_asset_price` and a range of path dependent values between `0` and `spd_max`. From this vector the element corresponding to the current asset price is returned.

  Remarks:

  - To efficiently evaluate the vector of option values corresponding to a range of asset prices you should use `finiteDifferencingVectorStronglyPathDependent`, which renders a large amount of the computations redundant.
  - For an option of European type the tolerance parameter will have no effect since the SOR algorithm will not be used.

  Parameters:
    `type` - this parameter specifies whether the option is European or American. That is, whether the option can exercise prior to the maturity (i.e. American) or can only be exercised at the maturity (i.e. European).
    `asset_price` - the current price of the asset
    `dividend` - the continuous dividend yield the underlying asset pays
    `interest` - the continuously compounded risk-free interest rate in the domestic currency
    `volatility` - the volatility (in years) of the asset price
    `max_asset_price` - the asset price corresponding to the last item of the finite differencing grid on the price axis
    `time_steps` - the total number of iterations (the dimension of the grid on the time axis)
    `asset_price_steps` - the dimension of the grid on the price axis
    `exotic_type` - this parameter specifies the type of exotic (ASIAN_ARITHMETIC, ASIAN_GEOMETRIC, LOOKBACK_MAX or LOOKBACK_MIN)
    `max_spd` - the path dependent value corresponding to the last item of the finite differencing grid on the path dependent value axis
    `spd_steps` - the dimension of the grid on the path dependent value axis
    `sampling_period` - the number of time steps before the path dependent value is updated
    `algorithm_type` - the type of finite differencing algorithm to be used; can be EXPLICIT, FULLY_IMPLICIT or CRANCK_NICHOLSON.
    `tolerance` - the tolerance for the SOR algorithm of solving systems of linear equations.
    `evaluationDate` - the date when the value of the option is evaluated
    `maturityDate` - the date when the contract matures
    `businessCalendar` - The instance of a `BusinessCalendar` interface implementation. Specify `null` to select the London business calendar.
  Returns:
    the present value of the option contract according to the Black-Scholes-Merton model
    `ExoticOptionsException`
    `FiniteDifferenceDemoException`

### finiteDifferencingStronglyPathDependent

    public double finiteDifferencingStronglyPathDependent(int algorithm_type,
                                                          int type,
                                                          int exotic_type,
                                                          double time2Maturity,
                                                          double asset_price,
                                                          double dividend,
                                                          double interest,
                                                          double volatility,
                                                          double max_asset_price,
                                                          double max_spd,
                                                          int time_steps,
                                                          int asset_price_steps,
                                                          int spd_steps,
                                                          double tolerance,
                                                          int sampling_period)
                                                   throws ExoticOptionsException,
                                                          FiniteDifferenceDemoException

  Evaluates the present value of a strongly path dependent Asian or Loopback exotic option according to the Black-Scholes-Merton model using finite difference PDE pricing techniques.

  Supported Options

  This method allows the following four types of exotic options to be evaluated:

  - Asian options with arithmetic average
  - Asian options with geometric average
  - Lookback options with maximum price evaluation
  - Lookback options with minimum price evaluation
  The type of exotic option being considered is selected using the `exotic_type` parameter. You should also specify whether the exotic option is of European or American type by using the parameter type.

  Once the option contract has been specified the options value is a function of three variables:

  - The time until the option expires
  - The present price of the asset on which the option is defined
  - ``asset measure over period" - in the case of the Asian option this is the average of the asset from inception until the present point in time
  Remark The third variable ``asset measure over period", which refers to the path dependent nature of the option contact appears within the pricing model because of the above options are strongly path dependence.

  Overview of the Algorithm
  The algorithm constructs a grid consisting of a total of `time_steps` x `asset_price_steps` x `spd_steps` points. At each iteration a new plane from this grid is calculated. The path dependent value is considered to be updated on every `sampling_period` time steps. This update process corresponds to a jump condition at the differential equation level. The last plane of the grid corresponds to the option values at the current moment of time, for a range of prices varying between `0` and `max_asset_price` and a range of path dependent values between `0` and `spd_max`. From this vector the element corresponding to the current asset price is returned.

  Remarks:

  - To efficiently evaluate the vector of option values corresponding to a range of asset prices you should use `finiteDifferencingVectorStronglyPathDependent`, which renders a large amount of the computations redundant.
  - For an option of European type the tolerance parameter will have no effect since the SOR algorithm will not be used.

  Parameters:
    `type` - this parameter specifies whether the option is European or American. That is, whether the option can exercise prior to the maturity (i.e. American) or can only be exercised at the maturity (i.e. European).
    `time2Maturity` - the remaining time (in years) until the contract matures
    `asset_price` - the current price of the asset
    `dividend` - the continuous dividend yield the underlying asset pays
    `interest` - the continuously compounded risk-free interest rate in the domestic currency
    `volatility` - the volatility (in years) of the asset price
    `max_asset_price` - the asset price corresponding to the last item of the finite differencing grid on the price axis
    `time_steps` - the total number of iterations (the dimension of the grid on the time axis)
    `asset_price_steps` - the dimension of the grid on the price axis
    `exotic_type` - this parameter specifies the type of exotic (ASIAN_ARITHMETIC, ASIAN_GEOMETRIC, LOOKBACK_MAX or LOOKBACK_MIN)
    `max_spd` - the path dependent value corresponding to the last item of the finite differencing grid on the path dependent value axis
    `spd_steps` - the dimension of the grid on the path dependent value axis
    `sampling_period` - the number of time steps before the path dependent value is updated
    `algorithm_type` - the type of finite differencing algorithm to be used; can be EXPLICIT, FULLY_IMPLICIT or CRANCK_NICHOLSON.
    `tolerance` - the tolerance for the SOR algorithm of solving systems of linear equations.
  Returns:
    the present value of the option contract according to the Black-Scholes-Merton model
    `ExoticOptionsException`
    `FiniteDifferenceDemoException`

### finiteDifferencingVector

    public double[] finiteDifferencingVector(int algorithm_type,
                                             int type,
                                             Date evaluationDate,
                                             Date maturityDate,
                                             double dividend,
                                             double interest,
                                             double volatility,
                                             double max_asset_price,
                                             int time_steps,
                                             int asset_price_steps,
                                             double tolerance,
                                             BusinessCalendar businessCalendar)
                                      throws ExoticOptionsException,
                                             FiniteDifferenceDemoException

  Evaluates a vector of `asset_price_steps` options values corresponding to a range of present underlying asset prices between `0` and `max_asset_price`, for any any American or European (single asset) option contract with a payoff function provided by `setPayoffFunction`, in accordance with the Black-Scholes-Merton model using finite differencing PDE techniques. Note, that in order to apply these finite differencing PDE techniques some boundaries conditions of the pricing function on the finite differencing grid chosen much have been set using `setBoundaries`.

  Supports all Options

  This method allows (in principle) any option to be priced is accordance with the Black-Scholes model via finite differencing methods for which the user can provide the contracts payoff function using `setPayoffFunction(webcab.lib.finance.options.exotic.PayoffFunction)` and the boundary conditions of the price function on the finite differencing grid boundaries at set using `setBoundaries(webcab.lib.finance.options.exotic.Boundaries)`.

  Overview of Algorithm
  The algorithm constructs a grid consisting of a total of `time_steps` x `asset_price_steps` points. At each iteration a new line from this grid is calculated. The last line of the grid corresponds to the option values at the current moment of time, for a range of prices varying between `0` and `max_asset_price`. The method returns this last line of the grid, and not a single value like the method `finiteDifferencing` does.

  Remark: This full finite differencing algorithm is used only when evaluating American options with implicit or Cranck-Nicholson algorithms. For options of European type since the SOR algorithm in not used the tolerance parameter will have no effect on either the result or computation time.

  Setting the boundaries

  In order to price the (European or American) option contract we are required to solve the PDE resulting from Black-Scholes-Merton model for the given payoff function (i.e. contract) under consideration. This is handled internally by the method but the whether the option being considered is American or European the values of the pricing function is going to depend on the following two variables:

  - Time until the option expires
  - Current price of the asset on which the option is defined
  The types of boundaries which you given for the price function which depends on these two coordinaites is up to you. However the following choose is popular and effective:
  - When `Time = maturity`, on this boundary the pricing function is just the payoff function.
  - When Option is deap out of the money, here we usually assume that the option will not be exercised and hence the pricing function is assumed to be zero.
  - When Option is deep in the money, here we usually assume that the option is certain to be exercised.

  Parameters:
    `type` - this parameter specifies whether the option is European or American. That is, whether the option can exercise prior to the maturity (i.e. American) or can only be exercised at the maturity (i.e. European).
    `dividend` - the continuous dividend yield the underlying asset pays
    `interest` - the continuously compounded risk-free interest rate in the domestic currency
    `volatility` - the volatility (in years) of the asset price
    `max_asset_price` - the asset price corresponding to the last item of the finite differencing grid
    `time_steps` - the total number of iterations (the dimension of the grid on the time axis)
    `asset_price_steps` - the dimension of the grid on the price axis
    `algorithm_type` - the type of finite differencing algorithm to be used; can be EXPLICIT, FULLY_IMPLICIT or CRANCK_NICHOLSON.
    `tolerance` - the tolerance for the SOR algorithm of solving systems of linear equations.
    `evaluationDate` - the date when the value of the option is evaluated
    `maturityDate` - the date when the contract matures
    `businessCalendar` - The instance of a `BusinessCalendar` interface implementation. Specify `null` to select the London business calendar.
  Returns:
    a vector of `asset_price_steps` option values corresponding to a range of asset prices between `0` and `max_asset_price`
    `ExoticOptionsException`
    `FiniteDifferenceDemoException`

### finiteDifferencingVector

    public double[] finiteDifferencingVector(int algorithm_type,
                                             int type,
                                             double time2Maturity,
                                             double dividend,
                                             double interest,
                                             double volatility,
                                             double max_asset_price,
                                             int time_steps,
                                             int asset_price_steps,
                                             double tolerance)
                                      throws ExoticOptionsException,
                                             FiniteDifferenceDemoException

  Evaluates a vector of `asset_price_steps` options values corresponding to a range of present underlying asset prices between `0` and `max_asset_price`, for any any American or European (single asset) option contract with a payoff function provided by `setPayoffFunction`, in accordance with the Black-Scholes-Merton model using finite differencing PDE techniques. Note, that in order to apply these finite differencing PDE techniques some boundaries conditions of the pricing function on the finite differencing grid chosen much have been set using `setBoundaries`.

  Supports all Options

  This method allows (in principle) any option to be priced is accordance with the Black-Scholes model via finite differencing methods for which the user can provide the contracts payoff function using `setPayoffFunction(webcab.lib.finance.options.exotic.PayoffFunction)` and the boundary conditions of the price function on the finite differencing grid boundaries at set using `setBoundaries(webcab.lib.finance.options.exotic.Boundaries)`.

  Overview of Algorithm
  The algorithm constructs a grid consisting of a total of `time_steps` x `asset_price_steps` points. At each iteration a new line from this grid is calculated. The last line of the grid corresponds to the option values at the current moment of time, for a range of prices varying between `0` and `max_asset_price`. The method returns this last line of the grid, and not a single value like the method `finiteDifferencing` does.

  Remark: This full finite differencing algorithm is used only when evaluating American options with implicit or Cranck-Nicholson algorithms. For options of European type since the SOR algorithm in not used the tolerance parameter will have no effect on either the result or computation time.

  Setting the boundaries

  In order to price the (European or American) option contract we are required to solve the PDE resulting from Black-Scholes-Merton model for the given payoff function (i.e. contract) under consideration. This is handled internally by the method but the whether the option being considered is American or European the values of the pricing function is going to depend on the following two variables:

  - Time until the option expires
  - Current price of the asset on which the option is defined
  The types of boundaries which you given for the price function which depends on these two coordinaites is up to you. However the following choose is popular and effective:
  - When `Time = maturity`, on this boundary the pricing function is just the payoff function.
  - When Option is deap out of the money, here we usually assume that the option will not be exercised and hence the pricing function is assumed to be zero.
  - When Option is deep in the money, here we usually assume that the option is certain to be exercised.

  Parameters:
    `type` - this parameter specifies whether the option is European or American. That is, whether the option can exercise prior to the maturity (i.e. American) or can only be exercised at the maturity (i.e. European).
    `time2Maturity` - the remaining time (in years) until the contract matures
    `dividend` - the continuous dividend yield the underlying asset pays
    `interest` - the continuously compounded risk-free interest rate in the domestic currency
    `volatility` - the volatility (in years) of the asset price
    `max_asset_price` - the asset price corresponding to the last item of the finite differencing grid
    `time_steps` - the total number of iterations (the dimension of the grid on the time axis)
    `asset_price_steps` - the dimension of the grid on the price axis
    `algorithm_type` - the type of finite differencing algorithm to be used; can be EXPLICIT, FULLY_IMPLICIT or CRANCK_NICHOLSON.
    `tolerance` - the tolerance for the SOR algorithm of solving systems of linear equations.
  Returns:
    a vector of `asset_price_steps` option values corresponding to a range of asset prices between `0` and `max_asset_price`
    `ExoticOptionsException`
    `FiniteDifferenceDemoException`

### finiteDifferencingVectorStronglyPathDependent

    public double[] finiteDifferencingVectorStronglyPathDependent(int algorithm_type,
                                                                  int type,
                                                                  int exotic_type,
                                                                  Date evaluationDate,
                                                                  Date maturityDate,
                                                                  double dividend,
                                                                  double interest,
                                                                  double volatility,
                                                                  double max_asset_price,
                                                                  double max_spd,
                                                                  int time_steps,
                                                                  int asset_price_steps,
                                                                  int spd_steps,
                                                                  double tolerance,
                                                                  int sampling_period,
                                                                  BusinessCalendar businessCalendar)
                                                           throws ExoticOptionsException,
                                                                  FiniteDifferenceDemoException

  Evaluates a strongly path dependent Asian or Lookback exotic options for a range of possible strikes in accordance with the Black-Scholes model using finite diifferencing PDE techniques.

  Overview

  We use a finite differencing algorithm in order to solve the resulting Black-Scholes PDE which will return the present values of the strongly path dependent exotic option as a vector. The vector which is returned represents the value of the option contract at the range of possible strikes which where considered.

  Options Supported

  This method covers four types of exotic options:

  - Asian options with arithmetic average
  - Asian options with geometric average
  - Lookback options with maximum price evaluation
  - Lookback options with minimum price evaluation

  The type of option is selected by using the `exotic_type` parameter. Since these options are strongly path dependent there present value is a function which will depend on three variables:

  - The time until the option expires
  - The present price of the asset
  - ``asset measure over period" - in the case of the Asian option this is the average of the asset from inception until the present point in time

  Overview of Algorithm
  The algorithm constructs a grid consisting of a total of `time_steps` x `asset_price_steps` x `spd_steps` points. At each iteration a new plane from this grid is calculated. The path dependent value is considered to be updated on every `sampling_period` time steps. This update process corresponds to a jump condition at the differential equation level. The last plane of the grid corresponds to the option values at the current moment of time, for a range of prices varying between `0` and max_asset_price and a range of path dependent values between `0` and `spd_max`. The method returns this last line of the grid, and not a single value which is the case for the method `finiteDifferencingStronglyPathDependent`.

  Remark: Full finite differencing algorithms are used only when evaluating American options in which case implicit or Cranck-Nicholson algorithms are used. In the case of European options since the full SOR algorithm is not used the value given for the `tolerance` will not effect the results or the computational time required.

  Parameters:
    `algorithm_type` - the type of finite differencing algorithm to be used; can be EXPLICIT, FULLY_IMPLICIT or CRANCK_NICHOLSON.
    `type` - this parameter specifies whether the option is European or American. That is, whether the option can exercise prior to the maturity (i.e. American) or can only be exercised at the maturity (i.e. European).
    `dividend` - the continuous dividend yield the asset underlying asset pays
    `interest` - the continuously compounded risk-free interest rate in the domestic currency
    `volatility` - the volatility (in years) of the asset price
    `max_asset_price` - the asset price corresponding to the last item of the finite differencing grid
    `time_steps` - the total number of iterations (the dimension of the grid on the time axis)
    `asset_price_steps` - the dimension of the grid on the price axis
    `exotic_type` - this parameter specifies the type of exotic (ASIAN_ARITHMETIC, ASIAN_GEOMETRIC, LOOKBACK_MAX or LOOKBACK_MIN)
    `max_spd` - the path dependent value corresponding to the last item of the finite differencing grid on the path dependent value axis.
    `spd_steps` - the dimension of the grid on the path dependent value axis.
    `tolerance` - the tolerance for the SOR algorithm of solving systems of linear equations.
    `sampling_period` - the number of time steps before the path dependent value is updated.
    `evaluationDate` - the date when the value of the option is evaluated
    `maturityDate` - the date when the contract matures
    `businessCalendar` - The instance of a `BusinessCalendar` interface implementation. Specify `null` to select the London business calendar.
  Returns:
    a vector of `asset_price_steps` option values corresponding to a range of asset prices between `0` and `max_asset_price`
    `ExoticOptionsException`
    `FiniteDifferenceDemoException`

### finiteDifferencingVectorStronglyPathDependent

    public double[] finiteDifferencingVectorStronglyPathDependent(int algorithm_type,
                                                                  int type,
                                                                  int exotic_type,
                                                                  double time2Maturity,
                                                                  double dividend,
                                                                  double interest,
                                                                  double volatility,
                                                                  double max_asset_price,
                                                                  double max_spd,
                                                                  int time_steps,
                                                                  int asset_price_steps,
                                                                  int spd_steps,
                                                                  double tolerance,
                                                                  int sampling_period)
                                                           throws ExoticOptionsException,
                                                                  FiniteDifferenceDemoException

  Evaluates a strongly path dependent Asian or Lookback exotic options for a range of possible strikes in accordance with the Black-Scholes model using finite diifferencing PDE techniques.

  Overview

  We use a finite differencing algorithm in order to solve the resulting Black-Scholes PDE which will return the present values of the strongly path dependent exotic option as a vector. The vector which is returned represents the value of the option contract at the range of possible strikes which where considered.

  Options Supported

  This method covers four types of exotic options:

  - Asian options with arithmetic average
  - Asian options with geometric average
  - Lookback options with maximum price evaluation
  - Lookback options with minimum price evaluation

  The type of option is selected by using the `exotic_type` parameter. Since these options are strongly path dependent there present value is a function which will depend on three variables:

  - The time until the option expires
  - The present price of the asset
  - ``asset measure over period" - in the case of the Asian option this is the average of the asset from inception until the present point in time

  Overview of Algorithm
  The algorithm constructs a grid consisting of a total of `time_steps` x `asset_price_steps` x `spd_steps` points. At each iteration a new plane from this grid is calculated. The path dependent value is considered to be updated on every `sampling_period` time steps. This update process corresponds to a jump condition at the differential equation level. The last plane of the grid corresponds to the option values at the current moment of time, for a range of prices varying between `0` and max_asset_price and a range of path dependent values between `0` and `spd_max`. The method returns this last line of the grid, and not a single value which is the case for the method `finiteDifferencingStronglyPathDependent`.

  Remark: Full finite differencing algorithms are used only when evaluating American options in which case implicit or Cranck-Nicholson algorithms are used. In the case of European options since the full SOR algorithm is not used the value given for the `tolerance` will not effect the results or the computational time required.

  Parameters:
    `algorithm_type` - the type of finite differencing algorithm to be used; can be EXPLICIT, FULLY_IMPLICIT or CRANCK_NICHOLSON.
    `type` - this parameter specifies whether the option is European or American. That is, whether the option can exercise prior to the maturity (i.e. American) or can only be exercised at the maturity (i.e. European).
    `time2Maturity` - the remaining time (in years) until the contract matures
    `dividend` - the continuous dividend yield the asset underlying asset pays
    `interest` - the continuously compounded risk-free interest rate in the domestic currency
    `volatility` - the volatility (in years) of the asset price
    `max_asset_price` - the asset price corresponding to the last item of the finite differencing grid
    `time_steps` - the total number of iterations (the dimension of the grid on the time axis)
    `asset_price_steps` - the dimension of the grid on the price axis
    `exotic_type` - this parameter specifies the type of exotic (ASIAN_ARITHMETIC, ASIAN_GEOMETRIC, LOOKBACK_MAX or LOOKBACK_MIN)
    `max_spd` - the path dependent value corresponding to the last item of the finite differencing grid on the path dependent value axis.
    `spd_steps` - the dimension of the grid on the path dependent value axis.
    `tolerance` - the tolerance for the SOR algorithm of solving systems of linear equations.
    `sampling_period` - the number of time steps before the path dependent value is updated.
  Returns:
    a vector of `asset_price_steps` option values corresponding to a range of asset prices between `0` and `max_asset_price`
    `ExoticOptionsException`
    `FiniteDifferenceDemoException`

### multiFiniteDifferencing

    public double multiFiniteDifferencing(int type,
                                          Date evaluationDate,
                                          Date maturityDate,
                                          double[] asset_prices,
                                          int n_assets,
                                          double[] dividends,
                                          double interest,
                                          double[] volatility,
                                          double[][] correlation,
                                          double max_asset_price,
                                          int time_steps,
                                          int asset_price_steps,
                                          BusinessCalendar businessCalendar)
                                   throws ExoticOptionsException,
                                          FiniteDifferenceDemoException

  Evaluates the present value of any American or European multi-asset option contract with a payoff function provided by `setPayoffFunction`, in accordance with the Black-Scholes-Merton model using finite differencing techniques. Note, that in order to apply these finite differencing PDE techniques some boundaries conditions of the pricing function on the finite differencing grid chosen much have been set using `setBoundaries`.

  Remark: This method can be very slow and susceptible of instability if the number of assets which the option depends on is larger than three.

  Supports all Options

  This method allows (in principle) any multi-asset option to be priced is accordance with the Black-Scholes model via finite differencing methods for which the user can provide the contracts payoff function using `setPayoffFunction(webcab.lib.finance.options.exotic.PayoffFunction)` and the boundary conditions of the price function on the finite differencing grid boundaries at set using `setBoundaries(webcab.lib.finance.options.exotic.Boundaries)`.

  Setting the boundaries

  In order to price the (European or American) option contract we are required to solve the PDE resulting from Black-Scholes-Merton model for the given payoff function (i.e. contract) under consideration. This is handled internally by the method but the whether the option being considered is American or European the values of the pricing function is going to depend on the following two variables:

  - Time until the option expires
  - Current price of the assets on which the option is defined
  The types of boundaries which you given for the price function which depends on these two coordinaites is up to you. However the following choose is popular and effective:
  - When `Time = maturity`, on this boundary the pricing function is just the payoff function.
  - When Option contract is deap out of the money, here we usually assume that the option will not be exercised and hence the pricing function is assumed to be zero.
  - When Option contract is deep in the money, here we usually assume that the option is certain to be exercised.

  Parameters:
    `type` - this parameter specifies whether the option is European or American. That is, whether the option can exercise prior to the maturity (i.e. American) or can only be exercised at the maturity (i.e. European).
    `asset_prices` - a vector containing the current prices of all the assets
    `n_assets` - the number of assets involved in the definition of the options contract
    `dividends` - a vector containing the continuous dividend yield which each of the underlying assets pays
    `interest` - the continuously compounded risk-free interest rate in the domestic currency
    `volatility` - a vector containing the volatilities (in years) of the asset prices
    `correlation` - N x N matrix. Each element (i,j) represents the correlation coefficient of asset i vs asset j. If i=j (i.e. elements from the first diagonal) then the value should be equal to 1 (an asset is fully correlated with itself).
    `max_asset_price` - the asset price corresponding to the last item of the finite differencing grid
    `time_steps` - the total number of iterations (the dimension of the grid on the time axis)
    `asset_price_steps` - the dimension of the grid on the price axis
    `evaluationDate` - the date when the value of the option is evaluated
    `maturityDate` - the date when the contract matures
    `businessCalendar` - The instance of a `BusinessCalendar` interface implementation. Specify `null` to select the London business calendar.
  Returns:
    the present value of the any multi-asset option contract given by the payoff function set using `setPayoffFunction`
    `ExoticOptionsException`
    `FiniteDifferenceDemoException`

### multiFiniteDifferencing

    public double multiFiniteDifferencing(int type,
                                          double time2Maturity,
                                          double[] asset_prices,
                                          int n_assets,
                                          double[] dividends,
                                          double interest,
                                          double[] volatility,
                                          double[][] correlation,
                                          double max_asset_price,
                                          int time_steps,
                                          int asset_price_steps)
                                   throws ExoticOptionsException,
                                          FiniteDifferenceDemoException

  Evaluates the present value of any American or European multi-asset option contract with a payoff function provided by `setPayoffFunction`, in accordance with the Black-Scholes-Merton model using finite differencing techniques. Note, that in order to apply these finite differencing PDE techniques some boundaries conditions of the pricing function on the finite differencing grid chosen much have been set using `setBoundaries`.

  Remark: This method can be very slow and susceptible of instability if the number of assets which the option depends on is larger than three.

  Supports all Options

  This method allows (in principle) any multi-asset option to be priced is accordance with the Black-Scholes model via finite differencing methods for which the user can provide the contracts payoff function using `setPayoffFunction(webcab.lib.finance.options.exotic.PayoffFunction)` and the boundary conditions of the price function on the finite differencing grid boundaries at set using `setBoundaries(webcab.lib.finance.options.exotic.Boundaries)`.

  Setting the boundaries

  In order to price the (European or American) option contract we are required to solve the PDE resulting from Black-Scholes-Merton model for the given payoff function (i.e. contract) under consideration. This is handled internally by the method but the whether the option being considered is American or European the values of the pricing function is going to depend on the following two variables:

  - Time until the option expires
  - Current price of the assets on which the option is defined
  The types of boundaries which you given for the price function which depends on these two coordinaites is up to you. However the following choose is popular and effective:
  - When `Time = maturity`, on this boundary the pricing function is just the payoff function.
  - When Option contract is deap out of the money, here we usually assume that the option will not be exercised and hence the pricing function is assumed to be zero.
  - When Option contract is deep in the money, here we usually assume that the option is certain to be exercised.

  Parameters:
    `type` - this parameter specifies whether the option is European or American. That is, whether the option can exercise prior to the maturity (i.e. American) or can only be exercised at the maturity (i.e. European).
    `time2Maturity` - the remaining time (in years) until the contract matures
    `asset_prices` - a vector containing the current prices of all the assets
    `n_assets` - the number of assets involved in the definition of the options contract
    `dividends` - a vector containing the continuous dividend yield which each of the underlying assets pays
    `interest` - the continuously compounded risk-free interest rate in the domestic currency
    `volatility` - a vector containing the volatilities (in years) of the asset prices
    `correlation` - N x N matrix. Each element (i,j) represents the correlation coefficient of asset i vs asset j. If i=j (i.e. elements from the first diagonal) then the value should be equal to 1 (an asset is fully correlated with itself).
    `max_asset_price` - the asset price corresponding to the last item of the finite differencing grid
    `time_steps` - the total number of iterations (the dimension of the grid on the time axis)
    `asset_price_steps` - the dimension of the grid on the price axis
  Returns:
    the present value of the any multi-asset option contract given by the payoff function set using `setPayoffFunction`
    `ExoticOptionsException`
    `FiniteDifferenceDemoException`

WebCab Options and Futures Demo v2.5 (J2SE Edition)