Está en la página 1de 2

binomialprice.

java 6/7/2010

/**
*
* Prepared by Ganesh R. Hegde
*MTech - Semester 2,2009-11 batch
*Roll Number - A109006
*
*
*/

import java.util.*;

class calculate {

class binomialprice {

public static void main(String[] args) {

Scanner keyboard=new Scanner(System.in);

double S0; //current stock price


System.out.println("Enter the current stock price");
S0=keyboard.nextDouble();

double K; //strike price


System.out.println("Enter the exercise price or strike price");
K=keyboard.nextDouble();

double volatility; //volatility


System.out.println("Enter the volatility in percentage");
volatility=keyboard.nextDouble();

volatility=volatility/100 ; //converted for the ease of


calculation purpose

int time; //time period in months


System.out.println("Enter the life span (time period) of the
option in months");
time=keyboard.nextInt();

int time_num; //number of time steps


System.out.println("Enter the number of time steps");
time_num=keyboard.nextInt();

double rate; //risk-free interest rate


System.out.println("Enter the risk-free interest rate per
annum");
rate=keyboard.nextDouble();
rate=rate*0.01; //simplified for calculation

int comp_type=1; //type of compounding

while(comp_type!=0)
{
System.out.println("Enter 1 for discrete compounding OR
enter 2 for continous compounding");
comp_type=keyboard.nextInt();

if(comp_type==1 || comp_type==2)
break;
}

int option=1; //type of European option

while(option!=0)
{

1
binomialprice.java 6/7/2010

System.out.println("Enter 1 for European put option OR enter


2 for European call option");
option=keyboard.nextInt();

if(option==1 || option==2)
break;
}

double u,d; //u=upper price movement, d=lower price movement


u=(double)time/(time_num*12) ;
u=Math.sqrt(u);
u=Math.exp(volatility*u );
d=1/u;

double p; //probability of upward movement


if(comp_type==1)
p=((1+rate)- d) / (u-d);
else
{
p=rate*(double)time/ (double) (12*time_num);
p=(Math.exp(p)- d ) / (u-d);
}

//System.out.println("u=" + u + "d=" +d + "p=" +p);

También podría gustarte