# Thread: Need help with code.

1. Member
Join Date
Oct 2009
Posts
1
Rep Power
0

## Need help with code.

Hi,

I'm working on writing a code to solve for the Black Sholes call option problem. Below is my code

import java.text.DecimalFormat;
import static java.lang.Math.*;
class CallOption

{

public CallOption (double p0, double ex, double rf, double sigmaSq, double t)
{

double pvex = Math.exp(-r*t);
}

// Method to calculate the present Value of ex
public double setPvex()
{
return ex * Math.exp(-r * t);
}
//Method to set d1
public double setDOne ()
{
return Math.log(p0/pvex)/sigma * Math.sqrt(t) + sigma * Math.sqrt(t) / 2;
}
//Method to set d2
public double setDTwo ()
{
return (Math.log(p0/pvex)/sigma * Math.sqrt(t) + sigma * Math.sqrt(t) / 2) - sigma * Math.sqrt(t);

}
//Method to calculate call option
public double computeCall()
{
d1 = new setDOne();
d2 = new setDOne() ;
pv = new Pvex();
return p0 * normal(d1) - pv * normal(d2);
}

}

public class BS

{
public static void main (String [] arg) throws Exception

{

CallOption ca = new CallOption (164, 165, 0.0521, 0.0841, 35.0/365);
System.out.println ( "price of call option is " + ca.computeCall());
}

}

What i've tried to do is create a CallOption class that also has certain methods. The methods also call the values from the previous methods to use in the calculation. This is confusing for me. I'm very new to java and am trying to figure this out for class. If anyone can help me figure out how to get this to work it would be great. Thanks in advance.

2. Senior Member
Join Date
Aug 2009
Posts
2,388
Rep Power
10
Read about variable scope to understand which variables are accessible inside which methods.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•