Beispiel #1
0
 public static double[,] optionprice(double S0, double K, double vol, double T, int N, double r, double del, bool type, bool optiontype)
 {
     double[,] intrinsic = IntriValues.intrinsicvalues(S0, K, vol, T, N, r, del, type, optiontype);
     double[,] Option    = new double[N + 1, 2 * N + 1];
     double[,] american  = American.amer(S0, K, vol, T, N, r, del, type, optiontype);
     if (optiontype)//European: Option price is the same as intrinstic prices
     {
         for (int i = 0; i < intrinsic.GetLength(0); i++)
         {
             for (int j = 0; j < intrinsic.GetLength(1); j++)
             {
                 Option[i, j] = intrinsic[i, j];
             }
         }
     }
     else//American: Option price is the same as american prices
     {
         for (int i = 0; i < intrinsic.GetLength(0); i++)
         {
             for (int j = 0; j < intrinsic.GetLength(1); j++)
             {
                 Option[i, j] = american[i, j];
             }
         }
     }
     return(Option);
 }
Beispiel #2
0
            public static double[,] amer(double S0, double K, double vol, double T, int N, double r, double del, bool type, bool optiontype)
            {
                double[,] intrinsic = IntriValues.intrinsicvalues(S0, K, vol, T, N, r, del, type, optiontype);
                double[,] american  = new double[N + 1, 2 * N + 1];
                //the probabilities using during the discount process
                double pu   = GetValues.getvalues(S0, K, vol, T, N, r, del, type, optiontype)[4];
                double pm   = GetValues.getvalues(S0, K, vol, T, N, r, del, type, optiontype)[5];
                double pd   = GetValues.getvalues(S0, K, vol, T, N, r, del, type, optiontype)[6];
                double disc = GetValues.getvalues(S0, K, vol, T, N, r, del, type, optiontype)[7];

                //use the same price as intrinstic price in the last row
                for (int j = 0; j < intrinsic.GetLength(1); j++)
                {
                    int i = intrinsic.GetLength(0) - 1;
                    american[i, j] = intrinsic[i, j];
                }
                // Option price is the larger one of intrinstic prices and discounted prices
                double[,] underlyvalues = UnderlyingValues.underlyingvalues(S0, K, vol, T, N, r, del, type, optiontype);
                for (int i = intrinsic.GetLength(0) - 2; i >= 0; i--)
                {
                    for (int j = N - i; j <= N + i; j++)
                    {
                        american[i, j] = disc * (pu * american[i + 1, j + 1] + pm * american[i + 1, j] + pd * american[i + 1, j - 1]);
                        if (type)//call
                        {
                            american[i, j] = Math.Max(underlyvalues[i, j] - K, american[i, j]);
                        }
                        else//put
                        {
                            american[i, j] = Math.Max(K - underlyvalues[i, j], american[i, j]);
                        }
                    }
                }
                return(american);
            }