Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package application;
- import javafx.application.Application;
- import javafx.scene.control.ToggleGroup;
- import java.net.URL;
- import java.util.ResourceBundle;
- import java.util.Scanner;
- import cern.jet.random.Normal;
- import javafx.event.ActionEvent;
- import javafx.event.EventHandler;
- import javafx.fxml.FXML;
- import javafx.fxml.Initializable;
- import javafx.scene.control.RadioButton;
- import javafx.scene.control.RadioMenuItem;
- import javafx.scene.control.TextField;
- public class MainController implements Initializable{
- group2=new ToggleGroup();
- inputCALL.setToggleGroup(group2);
- inputPUT.setToggleGroup(group2);
- @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;
- Scanner input = new Scanner(System.in);
- Normal a = new Normal(0,1, null);
- Double s= Double.parseDouble(inputCSP.getText());
- Double e = 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);
- System.out.println("Enter 'call' or 'put' :");
- String callorput = input.next();
- // Calculation of d1
- Double t = Math.log(s/e) + (r2 + 0.5*Math.pow(v2, 2))*t2;
- Double b = v2*Math.sqrt(t2);
- Double d1 = t/b;
- // Calculation of d2
- double root = Math.pow(t2, 0.5);
- double d2 = d1 - (v2*root);
- // 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) - (((e/Math.pow(e2, r2*t2))*roundc2));
- double value2 = Math.round(value*1000)/1000.0;
- //calculating the put
- double value3 = (value2 + (e/Math.pow(e2, r2*t2)) - s);
- if(callorput.equalsIgnoreCase("call")){
- System.out.println("The value of the european call option is: " + value2);
- }
- else if(callorput.equalsIgnoreCase("put")){
- System.out.println("The value of the european put option is: " + value3);
- }
- else {
- System.out.println("error, please check call/put is entered correctly");
- input.close();
- }
- @Override
- public void initialize(URL location, ResourceBundle resources) {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement