Advertisement
javaprogrammer1996

Maincontroller wont run

Sep 10th, 2015
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.68 KB | None | 0 0
  1. package application;
  2.  
  3. import javafx.application.Application;
  4. import javafx.scene.control.ToggleGroup;
  5. import java.net.URL;
  6. import java.util.ResourceBundle;
  7. import java.util.Scanner;
  8. import cern.jet.random.Normal;
  9. import javafx.event.ActionEvent;
  10. import javafx.event.EventHandler;
  11. import javafx.fxml.FXML;
  12. import javafx.fxml.Initializable;
  13. import javafx.scene.control.RadioButton;
  14. import javafx.scene.control.RadioMenuItem;
  15. import javafx.scene.control.TextField;
  16.  
  17.  
  18. public class MainController implements Initializable{
  19.    
  20.     group2=new ToggleGroup();
  21.     inputCALL.setToggleGroup(group2);
  22.     inputPUT.setToggleGroup(group2);
  23.  
  24.     @FXML
  25.     private static TextField inputCSP;
  26.     @FXML
  27.     private static TextField inputEP;
  28.     @FXML
  29.     private  static TextField inputRFIR;
  30.     @FXML
  31.     private static TextField inputTUE;
  32.     @FXML
  33.     private static TextField inputV;
  34.    
  35.  
  36.     Scanner input = new Scanner(System.in);
  37.  
  38.     Normal a = new Normal(0,1, null);
  39.    
  40.     Double s= Double.parseDouble(inputCSP.getText());
  41.    
  42.     Double e = Double.parseDouble(inputEP.getText());
  43.  
  44.     Double risk = Double.parseDouble(inputRFIR.getText());
  45.     Double r2 = (risk/100);
  46.    
  47.     Double time = Double.parseDouble(inputTUE.getText());
  48.     Double t2 = (time/365);
  49.    
  50.     Double volatility = Double.parseDouble(inputV.getText());
  51.     Double v2 = (volatility/100);
  52.    
  53.     System.out.println("Enter 'call' or 'put' :");
  54.     String callorput = input.next();
  55.    
  56.     // Calculation of d1
  57.     Double t = Math.log(s/e) + (r2 + 0.5*Math.pow(v2, 2))*t2;
  58.     Double b = v2*Math.sqrt(t2);
  59.     Double d1 = t/b;
  60.    
  61.     // Calculation of d2
  62.     double root = Math.pow(t2, 0.5);
  63.     double d2 = d1 - (v2*root);
  64.    
  65.     // Rounding d1 and d2 to 2 decimal places for use in normal distribution
  66.    
  67.     double roundedd1 = Math.round(d1*100)/100.0;
  68.     double roundedd2 = Math.round(d2 *100)/100.0;
  69.    
  70.     double cumulatived1 = a.cdf(roundedd1);
  71.     double cumulatived2 = a.cdf(roundedd2);
  72.    
  73.     double roundc1 = Math.round(cumulatived1*10000)/10000.0;
  74.     double roundc2 = Math.round(cumulatived2*10000)/10000.0;
  75.  
  76.     //Use of final formula
  77.    
  78.     double e2 = Math.E;
  79.     double value = (s*roundc1) - (((e/Math.pow(e2, r2*t2))*roundc2));
  80.    
  81.     double value2 = Math.round(value*1000)/1000.0;
  82.    
  83.     //calculating the put
  84.    
  85.     double value3 = (value2 + (e/Math.pow(e2, r2*t2)) - s);
  86.    
  87.     if(callorput.equalsIgnoreCase("call")){
  88.         System.out.println("The value of the european call option is: " + value2); 
  89.     }
  90.     else if(callorput.equalsIgnoreCase("put")){
  91.         System.out.println("The value of the european put option is: " + value3);
  92.     }
  93.     else {
  94.         System.out.println("error, please check call/put is entered correctly");
  95.         input.close();
  96.     }
  97.     @Override
  98.     public void initialize(URL location, ResourceBundle resources) {
  99.        
  100.     }
  101.  
  102.  
  103. }  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement