Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package application;
- import java.io.IOException;
- import java.io.OutputStream;
- import java.net.URL;
- import java.util.ResourceBundle;
- import cern.jet.random.Normal;
- import javafx.application.Application;
- import javafx.fxml.FXML;
- import javafx.fxml.FXMLLoader;
- import javafx.fxml.Initializable;
- import javafx.stage.Stage;
- import javafx.scene.Parent;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.control.Label;
- import javafx.scene.control.RadioButton;
- import javafx.scene.control.TextArea;
- import javafx.scene.control.TextField;
- import javafx.event.EventHandler;
- import java.awt.event.*
- ;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- public class Main extends Application implements Initializable {
- @FXML
- private static RadioButton callBox1;
- @FXML
- private static RadioButton putBox1;
- @FXML
- private static TextField inputCSP;
- @FXML
- private static TextField inputEP;
- @FXML
- private static TextField inputRFIR;
- @FXML
- private static TextField inputTUE;
- @FXML
- private static TextField inputV;
- @FXML
- private Button calculatebtn;
- @FXML
- private TextField outputarea;
- public static void main(String[] args) {
- launch(args);
- }
- @Override
- public void start(Stage primaryStage) throws Exception {
- Parent root = FXMLLoader.load(getClass().getResource("/application/GUI.fxml"));
- Scene scene = new Scene(root,640,400);
- primaryStage.setResizable(false);
- primaryStage.setScene(scene);
- primaryStage.show();
- primaryStage.setTitle("Black-Scholes Pricer (European Options)");
- System.out.println("hi");
- }
- @Override
- public void initialize(URL arg0, ResourceBundle arg1) {
- }
- public void mathsStart(ActionEvent event) {
- System.out.println("hi");
- Normal a = new Normal(0,1, null);
- Double s= Double.parseDouble(inputCSP.getText());
- Double ep = Double.parseDouble(inputEP.getText());
- Double risk = Double.parseDouble(inputRFIR.getText());
- Double r2 = (risk/100);
- Double time = Double.parseDouble(inputTUE.getText());
- Double t2 = (time/365);
- Double volatility = Double.parseDouble(inputV.getText());
- Double v2 = (volatility/100);
- // Calculation of d1
- Double t = Math.log(s/ep) + (r2 + 0.5*Math.pow(v2, 2))*t2;
- Double b = v2*Math.sqrt(t2);
- Double d1 = t/b;
- // Calculation of d2
- double root2 = Math.pow(t2, 0.5);
- double d2 = d1 - (v2*root2);
- // Rounding d1 and d2 to 2 decimal places for use in normal distribution
- double roundedd1 = Math.round(d1*100)/100.0;
- double roundedd2 = Math.round(d2 *100)/100.0;
- double cumulatived1 = a.cdf(roundedd1);
- double cumulatived2 = a.cdf(roundedd2);
- double roundc1 = Math.round(cumulatived1*10000)/10000.0;
- double roundc2 = Math.round(cumulatived2*10000)/10000.0;
- //Use of final formula
- double e2 = Math.E;
- double value = (s*roundc1) - (((ep/Math.pow(e2, r2*t2))*roundc2));
- double value2 = Math.round(value*1000)/1000.0;
- //calculating the put
- double value3 = (value2 + (ep/Math.pow(e2, r2*t2)) - s);
- String valuecall = String.valueOf(value2);
- String valueput = String.valueOf(value3);
- if(callBox1.isSelected()) {
- outputarea.setText(valuecall);
- }
- if(putBox1.isSelected()) {
- outputarea.setText(valueput);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement