Esempio n. 1
0
        private void btn_calculate_Click(object sender, EventArgs e)
        {
            // Define some variables for calculation
            double S0, K, r, T, sigma;
            int    N, trials;

            // use tryparse to check whether the user enterd correct type of value for each text box
            if (double.TryParse(textBox_S.Text, out S0) &&
                double.TryParse(textBox_K.Text, out K) &&
                double.TryParse(textBox_r.Text, out r) &&
                double.TryParse(textBox_T.Text, out T) &&
                double.TryParse(textBox_sigma.Text, out sigma) &&
                int.TryParse(textBox_N.Text, out N) &&
                int.TryParse(textBox_trials.Text, out trials))
            {
                // if all the inputs are correct, do the following calculation
                // Calculating the European call option price and greeks
                if (radioButton_EuropeanCall.Checked)
                {
                    // Define the variables
                    bool isput = false;

                    // Create a instance for RandomGenerator class
                    RandomGenerator RG = new RandomGenerator();
                    double[,] RandomNormal1 = RG.RandomNormal(trials, N);

                    // Create a instance for Option class
                    Option     opt1 = new Option();
                    EuroOption opt2 = new EuroOption();
                    double[,] sims = opt1.GetSimulations(S0, K, r, sigma, T, trials, N, RandomNormal1);

                    // Calculating and outputing the european call option price
                    label_OptionResult.Text = opt2.EUPrice(K, r, T, trials, N, RandomNormal1, sims, isput).ToString();

                    // Calculating and outputing the delta value for European call option
                    Greeks greek1 = new Greeks();
                    label_DeltaResult.Text = greek1.Delta(S0, K, r, sigma, T, N, trials, RandomNormal1, isput).ToString();

                    // Calculating and outputing the gamma value for European call option
                    label_GammaResult.Text = greek1.Gamma(S0, K, r, sigma, T, N, trials, RandomNormal1, isput).ToString();

                    // Calculating and outputing the vega value for European call option
                    label_VegaResult.Text = greek1.Vega(S0, K, r, sigma, T, N, trials, RandomNormal1, isput).ToString();

                    // Calculating and outputing the theta value for European call option
                    label_ThetaResult.Text = greek1.Theta(S0, K, r, sigma, T, N, trials, RandomNormal1, isput).ToString();

                    // Calculating and outputing the rho value for European call option
                    label_RhoResult.Text = greek1.Rho(S0, K, r, sigma, T, N, trials, RandomNormal1, isput).ToString();

                    // Calculating and outputing the SE value for European call option
                    label_SEResult.Text = greek1.SE(S0, K, r, sigma, T, N, trials, RandomNormal1, isput).ToString();
                }

                // Calculating the Euroean put option price and greeks
                else if (radioButton_EuropeanPut.Checked)
                {
                    // Define the variables
                    bool isput = true;

                    // Create a instance for RandomGenerator class
                    RandomGenerator RG = new RandomGenerator();
                    double[,] RandomNormal1 = RG.RandomNormal(trials, N);

                    // Create a instance for Option class
                    Option     opt1 = new Option();
                    EuroOption opt2 = new EuroOption();
                    double[,] sims = opt1.GetSimulations(S0, K, r, sigma, T, trials, N, RandomNormal1);

                    // Calculating and outputing the european put option price
                    label_OptionResult.Text = opt2.EUPrice(K, r, T, trials, N, RandomNormal1, sims, isput).ToString();

                    // Calculating and outputing the delta value for European put option
                    Greeks greek1 = new Greeks();
                    label_DeltaResult.Text = greek1.Delta(S0, K, r, sigma, T, N, trials, RandomNormal1, isput).ToString();

                    // Calculating and outputing the gamma value for European put option
                    label_GammaResult.Text = greek1.Gamma(S0, K, r, sigma, T, N, trials, RandomNormal1, isput).ToString();

                    // Calculating and outputing the vega value for European put option
                    label_VegaResult.Text = greek1.Vega(S0, K, r, sigma, T, N, trials, RandomNormal1, isput).ToString();

                    // Calculating and outputing the theta value for European put option
                    label_ThetaResult.Text = greek1.Theta(S0, K, r, sigma, T, N, trials, RandomNormal1, isput).ToString();

                    // Calculating and outputing the rho value for European put option
                    label_RhoResult.Text = greek1.Rho(S0, K, r, sigma, T, N, trials, RandomNormal1, isput).ToString();

                    // Calculating and outputing the SE value for European put option
                    label_SEResult.Text = greek1.SE(S0, K, r, sigma, T, N, trials, RandomNormal1, isput).ToString();
                }

                // Calculating the American call option price and greeks
                else if (radioButton_AmericanCall.Checked)
                {
                    label_OptionResult.Text = "Sorry. Coming Soon!";
                }

                // Calculating the American put option price and greeks
                else if (radioButton_AmericanPut.Checked)
                {
                    label_OptionResult.Text = "Sorry. Coming Soon!";
                }
            }
            // Output the error message if the user inputs inpropriate data
            else
            {
                label_OptionResult.Text = "Error! Please check your inputs";
            }
        }