Binomial Trees Angkor Wat

Binomial Trees

When pricing options, we don’t know whether the price will go up or down. This simple model captures that uncertainty.

Read More

Monte Carlo Simulation Angkor Wat

Monte Carlo Simulation

The behaviour of a stock price is like a random walk. Let’s simulate a very large number of these to predict our option price.

Read More

Black Scholes equation Sauðárkrókur

Black Scholes equation

Read More

Class Diagram


The main class is, which reads pricingtypes.txt. This file contains the following strings:

American Binomial Tree
Asian Monte Carlo
European Binomial Tree
European Monte Carlo
Black Scholes


public class OptionPricer extends Utils {

    public static void main(String[] args) {
        String[] Name = readTxt("pricingtypes.txt");
        PricingFactory factory = new PricingFactory();
        for (String str : Name) {
            PricingType pricing = factory.getPricingType(str);

            double call = pricing.getCall();
            double put = pricing.getPut();

            System.out.printf("%s\n\tCall:%.14f\n\tPut:%.14f\n", str, call, put);


This is used by to construct the appropriate concrete class from the interface class. Classes that implement this interface are:

  • BlackScholes
  • MC_Abstract
  • TreeAbstract

Methods presecribes the following methods to be implemented:

double getCall()
double getPut()

Abstract Classes

Monte Carlo

In certain cases, we are concerned with comparing the different type of pay-offs that can be utilised under each pricing method. For instance, when pricing via Monte Carlo, we are able to compare the difference in option prices that result from considering both Asian and European pay-off.


As such, we have an abstract class which is extended by and Both these concrete classes must define their own implementations of the following method:

 public double simulateRandomwalk (int N, double S0, double dt, double interest, double sigma)

Binomial Tree

We have a similar relationship with the abstract class and its concrete classes.


The difference between an American and European option is that an American put can be exercised at any time up to maturity. The European put can only be exercised at maturity. There is no difference between American and European calls.

As such, the concrete classes must implement their own version of the following method:

public double setPut(double[][] stockPrice, double strike, double interest, double p, double dt, int T)


In addition to pricingtypes.txt, we have a number of input .txt files.

  • Binomial.txt
  • BlackScholes.txt
  • MonteCarlo.txt

These files contain the following:


Each file contain identical data. But the user is free to modify the data for each implmentation.

On each line is a comma separated key-value-pair such that this data is mapped accordingly: HashMap<String, Double>. This allows for the following convenience:

double stock          = hashMap.get("stock");
double strike         = hashMap.get("strike");
double volatility     = hashMap.get("volatility");
double interest       = hashMap.get("interest");
double timehorizon    = hashMap.get("timehorizon");