コード例 #1
0
        static void Main(string[] args)
        {
            //input needed information from keyboard
            Console.WriteLine("Input spot price of underlying asset:");
            double spotPrice = Convert.ToDouble(Console.ReadLine());
            int    oType;

            do
            {
                Console.WriteLine("Input European option type (0 for call, 1 for put):");
                oType = Convert.ToInt32(Console.ReadLine());
            }while (oType != 0 & oType != 1);
            OptionType optionType = (oType == 0 ? OptionType.Call : OptionType.Put);

            Console.WriteLine("Input option strike price:");
            double strikePrice = Convert.ToDouble(Console.ReadLine());

            Console.WriteLine("Input time to maturity of this option:");
            double timeToMaturity = Convert.ToDouble(Console.ReadLine());

            Console.WriteLine("Input drift parameter for brownian motion:");
            double Mu = Convert.ToDouble(Console.ReadLine());

            Console.WriteLine("Input volatility parameter for brownian motion:");
            double sigma = Convert.ToDouble(Console.ReadLine());

            Console.WriteLine("Input number of scenarios generated by MC simulation:");
            int numOfScenarios = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Input number of time steps for Euler discretization:");
            int timeSteps = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Input whether to use antithetic variance reduction technique " +
                              "(true for yes,false for no): ");
            bool                  antithetic = Convert.ToBoolean(Console.ReadLine());
            EuropeanOption        Option     = new EuropeanOption(timeToMaturity, strikePrice, optionType);
            EulerSchemeForBSModel Euler      = new EulerSchemeForBSModel();
            StochasticAssetPrice  Asset      = new StochasticAssetPrice(Mu, sigma, spotPrice);

            if (antithetic)
            {
                double[] s1 = Option.PricingByMCSim(Asset, Euler, numOfScenarios, timeSteps,
                                                    true);
                Console.WriteLine("Option price estimated by Monte Carlo Simulation and " +
                                  "antithetic variance reduction is:\n {0:#0.00} \n Standard error is:\n {1:#0.000} ",
                                  s1[0], s1[1]);
            }
            else
            {
                double[] s2 = Option.PricingByMCSim(Asset, Euler, numOfScenarios, timeSteps, false);
                Console.WriteLine("Option price estimated by Monte Carlo Simulation is:\n {0:#0.00} \n" +
                                  "Standard error is:\n {1:#0.000} ", s2[0], s2[1]);
            }
            Console.ReadLine();
        }
コード例 #2
0
 static void Main(string[] args)
 {
     //input needed information from keyboard
     Console.WriteLine("Input spot price of underlying asset:");
     double spotPrice = Convert.ToDouble(Console.ReadLine());
     int oType;
     do
     {
         Console.WriteLine("Input European option type (0 for call, 1 for put):");
         oType = Convert.ToInt32(Console.ReadLine());
     }
     while (oType != 0 & oType != 1);
     OptionType optionType = (oType == 0 ? OptionType.Call : OptionType.Put);
     Console.WriteLine("Input option strike price:");
     double strikePrice = Convert.ToDouble(Console.ReadLine());
     Console.WriteLine("Input time to maturity of this option:");
     double timeToMaturity = Convert.ToDouble(Console.ReadLine());
     Console.WriteLine("Input drift parameter for brownian motion:");
     double Mu = Convert.ToDouble(Console.ReadLine());
     Console.WriteLine("Input volatility parameter for brownian motion:");
     double sigma = Convert.ToDouble(Console.ReadLine());
     Console.WriteLine("Input number of scenarios generated by MC simulation:");
     int numOfScenarios = Convert.ToInt32(Console.ReadLine());
     Console.WriteLine("Input number of time steps for Euler discretization:");
     int timeSteps = Convert.ToInt32(Console.ReadLine());
     Console.WriteLine("Input whether to use antithetic variance reduction technique " +
         "(true for yes,false for no): ");
     bool antithetic = Convert.ToBoolean(Console.ReadLine());
     Console.WriteLine("Input whether to visualize price path (true for yes,false for no): ");
     bool visualizationFlag = Convert.ToBoolean(Console.ReadLine());
     EuropeanOption Option = new EuropeanOption(timeToMaturity, strikePrice, optionType);
     EulerSchemeForBSModel Euler = new EulerSchemeForBSModel();
     StochasticAssetPrice Asset = new StochasticAssetPrice(Mu, sigma, spotPrice);
     if (antithetic)
     {
         Form1 s1form = new Form1("MC Simulation with Antithetic Variance Reduction");
         double[] s1 = Option.PricingByMCSim(Asset, Euler, numOfScenarios, timeSteps,
             true, visualizationFlag, s1form);
         Console.WriteLine("Option price estimated by Monte Carlo Simulation and " +
             "antithetic variance reduction is:\n {0:#0.00} \n Standard error is:\n {1:#0.000} ",
             s1[0], s1[1]);
         if (visualizationFlag)
         {
             // display the graph
             Application.Run(s1form.Display());
         }
     }
     else
     {
         Form1 s2form = new Form1("MC Simulation without Antithetic Variance Reduction");
         double[] s2 = Option.PricingByMCSim(Asset, Euler, numOfScenarios, timeSteps, false,
             visualizationFlag, s2form);
         Console.WriteLine("Option price estimated by Monte Carlo Simulation is:\n {0:#0.00} \n" +
             "Standard error is:\n {1:#0.000} ", s2[0], s2[1]);
         if (visualizationFlag)
         {
             // display the graph
             Application.Run(s2form.Display());
         }
     }
     Console.ReadLine();
 }
コード例 #3
0
 static void Main(string[] args)
 {
     //input needed information from keyboard
     Console.WriteLine("Input spot price of underlying asset:");
     double spotPrice = Convert.ToDouble(Console.ReadLine());
     Console.WriteLine("Input option strike price:");
     double strikePrice = Convert.ToDouble(Console.ReadLine());
     Console.WriteLine("Input time to maturity of this option:");
     double timeToMaturity = Convert.ToDouble(Console.ReadLine());
     Console.WriteLine("Input drift parameter for brownian motion:");
     double Mu = Convert.ToDouble(Console.ReadLine());
     Console.WriteLine("Input volatility parameter for brownian motion:");
     double sigma = Convert.ToDouble(Console.ReadLine());
     Console.WriteLine("Input number of scenarios generated by MC simulation:");
     int numOfScenarios = Convert.ToInt32(Console.ReadLine());
     Console.WriteLine("Input number of time steps for Euler discretization:");
     int timeSteps = Convert.ToInt32(Console.ReadLine());
     Console.WriteLine("Input whether to use antithetic variance reduction technique " +
         "(true for yes,false for no): ");
     bool antithetic = Convert.ToBoolean(Console.ReadLine());
     EuropeanCallOption Option = new EuropeanCallOption(timeToMaturity, strikePrice);
     EulerSchemeForBSModel Euler = new EulerSchemeForBSModel();
     StochasticAssetPrice Asset = new StochasticAssetPrice(Mu, sigma, spotPrice);
     if (antithetic)
     {
         double[] s1 = Option.PricingByMCSim(Asset, Euler, numOfScenarios, timeSteps,
             true);
         Console.WriteLine("Option price estimated by Monte Carlo Simulation and " +
             "antithetic variance reduction is:\n {0:#0.00} \n Standard error is:\n {1:#0.000} ",
             s1[0], s1[1]);
     }
     else
     {
         double[] s2 = Option.PricingByMCSim(Asset, Euler, numOfScenarios, timeSteps, false);
         Console.WriteLine("Option price estimated by Monte Carlo Simulation is:\n {0:#0.00} \n" +
             "Standard error is:\n {1:#0.000} ", s2[0], s2[1]);
     }
     Console.ReadLine();
 }