Esempio n. 1
0
        //This method is used to calculate gamma.
        //Inputs are same with above.
        public static double Gamma(Boolean isput, double K, double S0, double sigma, double r, double T, int steps, int N, double[,] R)
        {
            double d = 0.0001 * S0;
            //We creat an object with the same property of user's input.
            EuroOption O1 = new EuroOption();

            O1.isput = isput;
            O1.S0    = S0 + d;
            O1.K     = K;
            O1.sigma = sigma;
            O1.T     = T;
            O1.r     = r;
            O1.R     = R;
            //Define a is the option price with initial underlying price (1+d)*S0.
            double a = O1.PriceEuro(steps, N);

            O1.S0 = S0;
            //Define b is the option price with initial underlying price S0.
            double b = O1.PriceEuro(steps, N);

            O1.S0 = S0 - d;
            //Define c is the option price with initial underlying price (1-d)*S0.
            double c = O1.PriceEuro(steps, N);

            //Return the value of gamma.
            return((a + c - b - b) / (d * d));
        }
Esempio n. 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Use the user input as the property of an object O1.
            EuroOption O1 = new EuroOption();

            O1.S0    = Convert.ToDouble(txtS.Text);
            O1.K     = Convert.ToDouble(txtK.Text);
            O1.sigma = Convert.ToDouble(txtsigma.Text);
            O1.r     = Convert.ToDouble(txtr.Text);
            O1.T     = Convert.ToDouble(txtT.Text);

            //Generate a matrix with random values.
            int N, steps;

            N           = Convert.ToInt32(txtN.Text);
            steps       = Convert.ToInt32(txtsteps.Text);
            double[,] R = new double[N, steps + 1];
            R           = RandGenerator.Randn(N, steps);

            O1.R = R;

            //Define the option is call option or put option.
            if (radioCall.Checked == true)
            {
                O1.isput = false;
            }
            else if (radioPut.Checked == true)
            {
                O1.isput = true;
            }

            //The following gives the value of option price, greek values, and standard error.
            //We used Math.Truncate to keep only 4 number after the decimal.
            lblPrice.Text = Convert.ToString(Math.Truncate(O1.PriceEuro(steps, N) * 10000) / 10000);
            lblDelta.Text = Convert.ToString(Math.Truncate(GreeksCalculator.Delta(O1.isput, O1.K, O1.S0, O1.sigma, O1.r, O1.T, steps, N, R) * 10000) / 10000);
            lblGamma.Text = Convert.ToString(Math.Truncate(GreeksCalculator.Gamma(O1.isput, O1.K, O1.S0, O1.sigma, O1.r, O1.T, steps, N, R) * 10000) / 10000);
            lblRho.Text   = Convert.ToString(Math.Truncate(GreeksCalculator.Rho(O1.isput, O1.K, O1.S0, O1.sigma, O1.r, O1.T, steps, N, R) * 10000) / 10000);
            lblTheta.Text = Convert.ToString(Math.Truncate(GreeksCalculator.Theta(O1.isput, O1.K, O1.S0, O1.sigma, O1.r, O1.T, steps, N, R) * 10000) / 10000);
            lblVega.Text  = Convert.ToString(Math.Truncate(GreeksCalculator.Vega(O1.isput, O1.K, O1.S0, O1.sigma, O1.r, O1.T, steps, N, R) * 10000) / 10000);
            lblStd.Text   = Convert.ToString(Math.Truncate(O1.Std(steps, N) * 10000) / 10000);
        }
Esempio n. 3
0
        //This method is used to calculate theta.
        //Inputs are same with above.
        public static double Theta(Boolean isput, double K, double S0, double sigma, double r, double T, int steps, int N, double[,] R)
        {
            //We creat an object with the same property of user's input.
            EuroOption O1 = new EuroOption();

            O1.isput = isput;
            O1.S0    = S0;
            O1.K     = K;
            O1.sigma = sigma;
            O1.T     = T - T / steps;
            O1.r     = r;
            O1.R     = R;
            //Define p1 as the option price with tenor T-T/steps.
            double p1 = O1.PriceEuro(steps - 1, N);

            O1.T = T;
            //Define p2 as the option price with tenor T.
            double p2 = O1.PriceEuro(steps, N);

            //Return the value of theta.
            return((p1 - p2) / (T / steps));
        }
Esempio n. 4
0
        //This method is used to calculate rho.
        //Inputs are same with above.
        public static double Rho(Boolean isput, double K, double S0, double sigma, double r, double T, int steps, int N, double[,] R)
        {
            double d = 0.0001 * r;
            //We creat an object with the same property of user's input.
            EuroOption O1 = new EuroOption();

            O1.isput = isput;
            O1.S0    = S0;
            O1.K     = K;
            O1.sigma = sigma;
            O1.T     = T;
            O1.r     = r + d;
            O1.R     = R;
            //Define a is the option price with risk free rate (1+d)*r.
            double a = O1.PriceEuro(steps, N);

            O1.r = r - d;
            //Define b is the option price with risk free rate (1-d)*r.
            double b = O1.PriceEuro(steps, N);

            //Return the value of rho.
            return((a - b) / (2 * d));
        }
Esempio n. 5
0
        //This method is used to calculate vega.
        //Input includes, isput (call or put), underlying price S0, strike price K, volatility sigma, risk free rate r, tenor T, steps, number of trails N, and random variable matrix R.
        public static double Vega(Boolean isput, double K, double S0, double sigma, double r, double T, int steps, int N, double[,] R)
        {
            double d = 0.0001 * sigma;
            //We creat an object with the same property of user's input.
            EuroOption O1 = new EuroOption();

            O1.isput = isput;
            O1.S0    = S0;
            O1.K     = K;
            O1.sigma = sigma + d * sigma;
            O1.T     = T;
            O1.r     = r;
            //This R is same with the random matrix we used in calculating PriceEuro.
            O1.R = R;
            //Define p1 as the option price with volatility (1+d)*digma
            double p1 = O1.PriceEuro(steps, N);

            O1.sigma = sigma - d * sigma;
            //Define p2 as the option price with volatility (1-d)*digma
            double p2 = O1.PriceEuro(steps, N);

            //Return vega.
            return((p1 - p2) / (2 * d * sigma));
        }