Results 1 to 2 of 2
Thread: Need help with code.
- 10-05-2009, 10:00 PM #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.
- 10-06-2009, 09:31 AM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Similar Threads
-
Convert java code to midlet code
By coldvoice05 in forum New To JavaReplies: 1Last Post: 08-12-2009, 11:14 AM -
Convert java code to midlet code
By coldvoice05 in forum Advanced JavaReplies: 1Last Post: 08-09-2009, 01:21 PM -
Why doesn't this code accept my code?
By PeterFeng in forum New To JavaReplies: 5Last Post: 02-03-2009, 01:39 PM -
I need help fixing my code.. or non code?
By MrHuggykins in forum New To JavaReplies: 1Last Post: 03-19-2008, 10:12 PM -
Generating Code Automatically Using Custom code Template In Eclipse
By JavaForums in forum EclipseReplies: 1Last Post: 04-26-2007, 03:52 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks