Advertisement
javaprogrammer1996

mathsStart wont start

Sep 11th, 2015
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.67 KB | None | 0 0
  1. package application;
  2.    
  3.  
  4. import java.io.IOException;
  5. import java.io.OutputStream;
  6. import java.net.URL;
  7. import java.util.ResourceBundle;
  8.  
  9. import cern.jet.random.Normal;
  10. import javafx.application.Application;
  11. import javafx.fxml.FXML;
  12. import javafx.fxml.FXMLLoader;
  13. import javafx.fxml.Initializable;
  14. import javafx.stage.Stage;
  15. import javafx.scene.Parent;
  16. import javafx.scene.Scene;
  17. import javafx.scene.control.Button;
  18. import javafx.scene.control.Label;
  19. import javafx.scene.control.RadioButton;
  20. import javafx.scene.control.TextArea;
  21. import javafx.scene.control.TextField;
  22. import javafx.event.EventHandler;
  23. import java.awt.event.*
  24. ;
  25. import java.awt.event.ActionEvent;
  26. import java.awt.event.ActionListener;
  27. public class Main extends Application implements Initializable {
  28.    
  29.     @FXML
  30.     private static RadioButton callBox1;
  31.    
  32.     @FXML
  33.     private static RadioButton putBox1;
  34.    
  35.     @FXML
  36.     private static TextField inputCSP;
  37.    
  38.     @FXML
  39.     private static TextField inputEP;
  40.    
  41.     @FXML
  42.     private static TextField inputRFIR;
  43.    
  44.     @FXML
  45.     private static TextField inputTUE;
  46.    
  47.     @FXML
  48.     private static TextField inputV;
  49.    
  50.     @FXML
  51.     private Button calculatebtn;
  52.    
  53.     @FXML
  54.     private TextField outputarea;
  55.    
  56.     public static void main(String[] args) {
  57.         launch(args);
  58.     }
  59.    
  60.    
  61.     @Override
  62.     public void start(Stage primaryStage) throws Exception {
  63.        
  64.     Parent root = FXMLLoader.load(getClass().getResource("/application/GUI.fxml"));
  65.     Scene scene = new Scene(root,640,400);
  66.     primaryStage.setResizable(false);
  67.     primaryStage.setScene(scene);
  68.     primaryStage.show();
  69.     primaryStage.setTitle("Black-Scholes Pricer (European Options)");
  70.     System.out.println("hi");
  71.     }
  72.    
  73.     @Override
  74.     public void initialize(URL arg0, ResourceBundle arg1) {
  75.    
  76.     }
  77.    
  78.        
  79.     public void mathsStart(ActionEvent event) {
  80.            System.out.println("hi");
  81.         Normal a = new Normal(0,1, null);
  82.            
  83.         Double s= Double.parseDouble(inputCSP.getText());
  84.        
  85.         Double ep = Double.parseDouble(inputEP.getText());
  86.  
  87.         Double risk = Double.parseDouble(inputRFIR.getText());
  88.         Double r2 = (risk/100);
  89.        
  90.         Double time = Double.parseDouble(inputTUE.getText());
  91.         Double t2 = (time/365);
  92.        
  93.         Double volatility = Double.parseDouble(inputV.getText());
  94.         Double v2 = (volatility/100);  
  95.        
  96.      // Calculation of d1
  97.         Double t = Math.log(s/ep) + (r2 + 0.5*Math.pow(v2, 2))*t2;
  98.         Double b = v2*Math.sqrt(t2);
  99.         Double d1 = t/b;
  100.        
  101.         // Calculation of d2
  102.         double root2 = Math.pow(t2, 0.5);
  103.         double d2 = d1 - (v2*root2);
  104.        
  105.         // Rounding d1 and d2 to 2 decimal places for use in normal distribution
  106.        
  107.         double roundedd1 = Math.round(d1*100)/100.0;
  108.         double roundedd2 = Math.round(d2 *100)/100.0;
  109.        
  110.         double cumulatived1 = a.cdf(roundedd1);
  111.         double cumulatived2 = a.cdf(roundedd2);
  112.        
  113.         double roundc1 = Math.round(cumulatived1*10000)/10000.0;
  114.         double roundc2 = Math.round(cumulatived2*10000)/10000.0;
  115.  
  116.         //Use of final formula
  117.        
  118.         double e2 = Math.E;
  119.         double value = (s*roundc1) - (((ep/Math.pow(e2, r2*t2))*roundc2));
  120.        
  121.         double value2 = Math.round(value*1000)/1000.0;
  122.        
  123.         //calculating the put
  124.        
  125.         double value3 = (value2 + (ep/Math.pow(e2, r2*t2)) - s);
  126.        
  127.         String valuecall = String.valueOf(value2);
  128.         String valueput = String.valueOf(value3);
  129.        
  130.        
  131.        if(callBox1.isSelected()) {
  132.            outputarea.setText(valuecall);
  133.        }
  134.        
  135.        if(putBox1.isSelected()) {
  136.            outputarea.setText(valueput);
  137.            
  138.    
  139.        }
  140.     }
  141.  
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement