Advertisement
javaprogrammer1996

updated3

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