Results 1 to 2 of 2
  1. #1
    magshabib is offline Member
    Join Date
    Oct 2009
    Posts
    1
    Rep Power
    0

    Default 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. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Read about variable scope to understand which variables are accessible inside which methods.

Similar Threads

  1. Convert java code to midlet code
    By coldvoice05 in forum New To Java
    Replies: 1
    Last Post: 08-12-2009, 12:14 PM
  2. Convert java code to midlet code
    By coldvoice05 in forum Advanced Java
    Replies: 1
    Last Post: 08-09-2009, 02:21 PM
  3. Why doesn't this code accept my code?
    By PeterFeng in forum New To Java
    Replies: 5
    Last Post: 02-03-2009, 02:39 PM
  4. I need help fixing my code.. or non code?
    By MrHuggykins in forum New To Java
    Replies: 1
    Last Post: 03-19-2008, 11:12 PM
  5. Replies: 1
    Last Post: 04-26-2007, 04:52 PM

Posting Permissions

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