Example #1
0
        public void Task_2_8_5()
        {
            // Variance Process Values
            double Kappa = 2;
            double Theta = 0.06;
            double Sigma = 0.4;
            double V0    = 0.04;
            double Rho   = 0.5;

            // Heston Model Params
            double InitialStockPrice = 100;
            double RiskFreeRate      = 0.1;

            // Option Params
            double Maturity = 9;

            // MC Simulation Params
            int NumberOfTrials    = (int)1e5;
            int NumberOfTimeSteps = (int)Math.Ceiling(365 * Maturity);

            VarianceProcessParameters varParams =
                new VarianceProcessParameters(Kappa, Theta, Sigma, V0, Rho);

            HestonModelParameters hestonModel =
                new HestonModelParameters(InitialStockPrice, RiskFreeRate, varParams);

            MonteCarloSettings monteCarloSettings =
                new MonteCarloSettings(NumberOfTrials, NumberOfTimeSteps);

            LookbackOptionMC lookbackOptionMC =
                new LookbackOptionMC(hestonModel, monteCarloSettings, Maturity);

            Assert.AreEqual(13.6299, lookbackOptionMC.Price(1), 1e-1);
        }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the EuropeanOptionMC class.
 /// </summary>
 /// <param name="parameters">Interface holding Heston Model params.</param>
 /// <param name="monteCarloSimulationSettings">Interface holding Monte carlo simulation settings.</param>
 /// <param name="asianOption">Interface holding asian option.</param>
 public AsianOptionMC(HestonModelParameters parameters,
                      MonteCarloSettings monteCarloSimulationSettings,
                      AsianOption asianOption)
     : base(parameters, monteCarloSimulationSettings, asianOption)
 {
     _MonitoringTimes = asianOption.MonitoringTimes;
 }
        public VaccinationSimulation(MonteCarloSettings monteCarloSettings, EventSimulationSettings eventSimulationSettings, VaccinationSettings vaccinationSettings)
            : base(monteCarloSettings, eventSimulationSettings)
        {
            VaccinSettings = vaccinationSettings;

            _afterEventObservables       = new SimulationObservable <AfterEventValues>();
            _afterReplicationObservables = new SimulationObservable <AfterReplicationValues>();
            _experimentObservables       = new SimulationObservable <DoctorsExperimentValues>();

            ExaminationGen  = new ExponentialGenerator(1d / 260);
            VaccinationGen  = new TriangularGenerator(20, 100, 75);
            RegistrationGen = new UniformGenerator(140, 220);

            WaitingGen  = new Random();
            PatientsGen = new Random();
            ArrivalGen  = new Random();

            if (VaccinSettings.DoctorsExperimentEnabled)
            {
                MCSettings.Replications = (VaccinSettings.DoctorsMax - VaccinSettings.DoctorsMin + 1) * VaccinSettings.ExperimentReplications;
                _currentDoctorsCount    = VaccinSettings.DoctorsMin;
            }

            Init();
        }
Example #4
0
 /// <summary>
 /// Initializes a new instance of the EuropeanOptionMC class.
 /// </summary>
 /// <param name="parameters">Interface holding Heston Model params.</param>
 /// <param name="monteCarloSimulationSettings">Interface holding Monte carlo simulation settings.</param>
 /// <param name="europeanOption">Interface holding European option params.</param>
 public EuropeanOptionMC(HestonModelParameters parameters,
                         MonteCarloSettings monteCarloSimulationSettings,
                         EuropeanOption europeanOption)
     : base(parameters, monteCarloSimulationSettings, europeanOption.Maturity)
 {
     _StrikePrice = europeanOption.StrikePrice;
     _Type        = europeanOption.Type;
 }
Example #5
0
 public static void HestonModelParamPrint(VarianceProcessParameters parameters,
                                          HestonModelParameters model,
                                          MonteCarloSettings monteCarloSettings)
 {
     System.Console.WriteLine("k={0}, Theta={1}, Sigma={2}, V0={3}, Rho={4}, r={5}, #Trials={6}, #Steps={7}",
                              parameters.Kappa, parameters.Theta, parameters.Sigma, parameters.V0,
                              parameters.Rho, model.RiskFreeRate, monteCarloSettings.NumberOfTrials,
                              monteCarloSettings.NumberOfTimeSteps);
 }
Example #6
0
 /// <summary>
 /// Initializes a new instance of Heston MC class.
 /// </summary>
 /// <param name="parameters">Interface holding Heston Model params.</param>
 /// <param name="monteCarloSimulationSettings">Interface holding Monte carlo simulation settings.</param>
 public HestonMC(HestonModelParameters parameters,
                 MonteCarloSettings monteCarloSimulationSettings,
                 double Maturity) :
     base(parameters.InitialStockPrice,
          parameters.RiskFreeRate,
          parameters.GetVariance())
 {
     _NumberOfTrials    = monteCarloSimulationSettings.NumberOfTrials;
     _NumberOfTimeSteps = monteCarloSimulationSettings.NumberOfTimeSteps;
     _Maturity          = Maturity;
 }
Example #7
0
        public void Task_2_7_1()
        {
            // Variance Process Values
            double Kappa = 2;
            double Theta = 0.06;
            double Sigma = 0.4;
            double V0    = 0.04;
            double Rho   = 0.5;

            // Heston Model Params
            double InitialStockPrice = 100;
            double RiskFreeRate      = 0.1;

            // Option Params
            double        StrikePrice     = 100;
            PayoffType    Type            = PayoffType.Call;
            double        Maturity        = 1;
            List <double> MonitoringTimes = new List <double>
            {
                0.75,
                1.00
            };

            // MC Simulation Params
            int NumberOfTrials    = (int)1e5;
            int NumberOfTimeSteps = (int)Math.Ceiling(365 * Maturity);

            VarianceProcessParameters varParams =
                new VarianceProcessParameters(Kappa, Theta, Sigma, V0, Rho);

            HestonModelParameters hestonModel =
                new HestonModelParameters(InitialStockPrice, RiskFreeRate, varParams);

            AsianOption asianOption =
                new AsianOption(StrikePrice, Type, Maturity, MonitoringTimes);

            MonteCarloSettings monteCarloSettings =
                new MonteCarloSettings(NumberOfTrials, NumberOfTimeSteps);

            AsianOptionMC asianOptionMC =
                new AsianOptionMC(hestonModel, monteCarloSettings, asianOption);

            Assert.AreEqual(13.6299, asianOptionMC.Price(1), 1e-1);
        }
Example #8
0
        public void Task_2_3_3()
        {
            // Variance Process Values
            double Kappa = 2;
            double Theta = 0.06;
            double Sigma = 0.4;
            double V0    = 0.04;
            double Rho   = 0.5;

            // Heston Model Params
            double InitialStockPrice = 100;
            double RiskFreeRate      = 0.1;

            // Option Params
            double     StrikePrice = 100;
            PayoffType Type        = PayoffType.Call;
            double     Maturity    = 3;

            // MC Simulation Params
            int NumberOfTrials    = (int)1e5;
            int NumberOfTimeSteps = (int)Math.Ceiling(365 * Maturity);

            VarianceProcessParameters varParams =
                new VarianceProcessParameters(Kappa, Theta, Sigma, V0, Rho);

            HestonModelParameters hestonModel =
                new HestonModelParameters(InitialStockPrice, RiskFreeRate, varParams);

            EuropeanOption euOption =
                new EuropeanOption(StrikePrice, Type, Maturity);

            MonteCarloSettings monteCarloSettings =
                new MonteCarloSettings(NumberOfTrials, NumberOfTimeSteps);

            EuropeanOptionMC euOptionMC = new EuropeanOptionMC(hestonModel,
                                                               monteCarloSettings, euOption);

            Assert.AreEqual(29.9957, euOptionMC.Price(1), 1e-1);
        }
Example #9
0
        public VaccineSimulationService()
        {
            MCSettings = new MonteCarloSettings
            {
                Replications = 100
            };

            ESSettings = new EventSimulationSettings
            {
                SimulationTime = 60 * 60 * 9
            };

            VacSettings = new VaccinationSettings
            {
                RegistrationWorkers     = 5,
                ExaminationWorkers      = 6,
                VaccinationWorkers      = 3,
                Patients                = 540,
                NotCommingLowerBoundry  = 5,
                NotCommingHigherBoundry = 25
            };

            _simulation = new VaccinationSimulation(MCSettings, ESSettings, VacSettings);
        }
Example #10
0
        public static void TaskThreadScaling()
        {
            // Variance Process Values
            Console.WriteLine("Task Thread Scaling");
            // Variance Process Values
            double Kappa = 2.0;
            double Theta = 0.06;
            double Sigma = 0.4;
            double V0    = 0.04;
            double Rho   = 0.5;

            // Heston Model Params
            double InitialStockPrice = 100;
            double RiskFreeRate      = 0.1;

            // Option Params
            double     StrikePrice = 100;
            PayoffType Type        = PayoffType.Call;
            double     Maturity    = 3;

            VarianceProcessParameters varParams =
                new VarianceProcessParameters(Kappa, Theta, Sigma, V0, Rho);

            HestonModelParameters hestonModel =
                new HestonModelParameters(InitialStockPrice, RiskFreeRate, varParams);

            // ************Task 3 Print****************
            System.Console.WriteLine("*********************");
            HestonModelParamPrint(varParams, hestonModel);

            //Prepare csv
            var    csv     = new StringBuilder();
            String newLine = string.Format("Number of Trials, cores, time");

            csv.AppendLine(newLine);
            int[] cores = new int[5] {
                1, 2, 4, 8, 16
            };
            for (int i = 0; i < 5; i++)
            {
                // MC Simulation Params
                int NumberOfTrials    = (int)1e6;
                int NumberOfTimeSteps = (int)Math.Ceiling(365 * Maturity);

                EuropeanOption euOption =
                    new EuropeanOption(StrikePrice, Type, Maturity);

                MonteCarloSettings monteCarloSettings =
                    new MonteCarloSettings(NumberOfTrials, NumberOfTimeSteps);
                double priceForm = Heston.HestonEuropeanOptionPrice(hestonModel, euOption);

                // Create Monte Carlo EU option object
                EuropeanOptionMC euOptionMC = new EuropeanOptionMC(hestonModel, monteCarloSettings, euOption);

                var stopwatch = new Stopwatch();
                stopwatch.Start();
                double price = euOptionMC.Price(cores[i]);
                stopwatch.Stop();
                long elapsed_time = stopwatch.ElapsedMilliseconds;

                System.Console.WriteLine("K={0}, T={1}, cores={2}, C_MC={3}, C_form={4}, time={5}",
                                         StrikePrice, Maturity, cores[i], price, priceForm, elapsed_time);

                newLine = string.Format("{0}, {1}, {2}", NumberOfTrials, cores[i], elapsed_time);
                csv.AppendLine(newLine);
            }

            //Write to csv
            File.WriteAllText(@"./taskThreadScaling.csv", csv.ToString());

            System.Console.WriteLine("*********************");
            System.Console.WriteLine("\n\n");
        }
Example #11
0
        public static void Task8()
        {
            // Variance Process Values
            Console.WriteLine("Task 8");
            // Variance Process Values
            double Kappa = 2.0;
            double Theta = 0.06;
            double Sigma = 0.4;
            double V0    = 0.04;
            double Rho   = 0.5;

            // Heston Model Params
            double InitialStockPrice = 100;
            double RiskFreeRate      = 0.1;

            // Option Params
            double[] Maturity = new double[5] {
                1, 3, 5, 7, 9
            };

            VarianceProcessParameters varParams =
                new VarianceProcessParameters(Kappa, Theta, Sigma, V0, Rho);

            HestonModelParameters hestonModel =
                new HestonModelParameters(InitialStockPrice, RiskFreeRate, varParams);

            // ************Task 7 Print****************
            System.Console.WriteLine("*********************");
            HestonModelParamPrint(varParams, hestonModel);

            //Prepare csv
            var    csv     = new StringBuilder();
            String newLine = string.Format("T, Price");

            csv.AppendLine(newLine);

            for (int i = 0; i < 5; i++)
            {
                // MC Simulation Params
                int NumberOfTrials    = (int)1e5;
                int NumberOfTimeSteps = (int)Math.Ceiling(365 * Maturity[i]);

                MonteCarloSettings monteCarloSettings =
                    new MonteCarloSettings(NumberOfTrials, NumberOfTimeSteps);

                Option maturity = new Option(Maturity[i]);
                double price    = Heston.HestonLookbackOptionPriceMC(hestonModel, maturity, monteCarloSettings);

                System.Console.WriteLine("T={0}, C_MC={1}",
                                         Maturity[i], price);

                newLine = string.Format("{0}, {1}", Maturity[i], price);
                csv.AppendLine(newLine);
            }

            //Write to csv
            File.WriteAllText(@"./task8.csv", csv.ToString());

            System.Console.WriteLine("*********************");
            System.Console.WriteLine("\n\n");
        }
Example #12
0
        public static void Task7()
        {
            // Variance Process Values
            Console.WriteLine("Task 7");
            // Variance Process Values
            double Kappa = 2.0;
            double Theta = 0.06;
            double Sigma = 0.4;
            double V0    = 0.04;
            double Rho   = 0.5;

            // Heston Model Params
            double InitialStockPrice = 100;
            double RiskFreeRate      = 0.1;

            // Option Params
            double     StrikePrice = 100;
            PayoffType Type        = PayoffType.Call;

            double[] Maturity = new double[3] {
                1, 2, 3
            };

            VarianceProcessParameters varParams =
                new VarianceProcessParameters(Kappa, Theta, Sigma, V0, Rho);

            HestonModelParameters hestonModel =
                new HestonModelParameters(InitialStockPrice, RiskFreeRate, varParams);

            // ************Task 7 Print****************
            System.Console.WriteLine("*********************");
            HestonModelParamPrint(varParams, hestonModel);

            // Monitoring Times
            List <double> monTimes1 = new List <double>
            {
                0.75,
                1.00
            };
            List <double> monTimes2 = new List <double>
            {
                0.25, 0.5, 0.75, 1.00, 1.25, 1.5, 1.75
            };
            List <double> monTimes3 = new List <double>
            {
                1.00, 2.00, 3.00
            };
            List <List <double> > MonitoringTimes = new List <List <double> >
            {
                monTimes1, monTimes2, monTimes3
            };

            //Prepare csv
            var    csv     = new StringBuilder();
            String newLine = string.Format("K, T, Price");

            csv.AppendLine(newLine);

            for (int i = 0; i < 3; i++)
            {
                // MC Simulation Params
                int NumberOfTrials    = (int)1e5;
                int NumberOfTimeSteps = (int)Math.Ceiling(365 * Maturity[i]);

                AsianOption asianOption =
                    new AsianOption(StrikePrice, Type, Maturity[i], MonitoringTimes[i]);

                MonteCarloSettings monteCarloSettings =
                    new MonteCarloSettings(NumberOfTrials, NumberOfTimeSteps);

                double price = Heston.HestonAsianOptionPriceMC(hestonModel,
                                                               asianOption, monteCarloSettings);

                System.Console.WriteLine("K={0}, T={1}, C_MC={2}", StrikePrice,
                                         Maturity[i], price);

                newLine = string.Format("{0}, {1}, {2}", StrikePrice, Maturity[i], price);
                csv.AppendLine(newLine);
            }

            //Write to csv
            File.WriteAllText(@"./task7.csv", csv.ToString());

            System.Console.WriteLine("*********************");
            System.Console.WriteLine("\n\n");
        }
Example #13
0
        public static void Task4()
        {
            // Variance Process Values
            Console.WriteLine("Task 4");
            // Variance Process Values
            double Kappa = 2.0;
            double Theta = 0.06;
            double Sigma = 0.4;
            double V0    = 0.04;
            double Rho   = 0.5;

            // Heston Model Params
            double InitialStockPrice = 100;
            double RiskFreeRate      = 0.1;

            // Option Params
            double     StrikePrice = 100;
            PayoffType Type        = PayoffType.Call;
            double     Maturity    = 1;

            VarianceProcessParameters varParams =
                new VarianceProcessParameters(Kappa, Theta, Sigma, V0, Rho);

            HestonModelParameters hestonModel =
                new HestonModelParameters(InitialStockPrice, RiskFreeRate, varParams);

            // ************Task 4 Print****************
            System.Console.WriteLine("*********************");
            HestonModelParamPrint(varParams, hestonModel);

            EuropeanOption euOption =
                new EuropeanOption(StrikePrice, Type, Maturity);

            double priceForm = Heston.HestonEuropeanOptionPrice(hestonModel, euOption);

            System.Console.WriteLine("K={0}, T={1}, refPrice={2}", StrikePrice,
                                     Maturity, priceForm);

            //Prepare csv
            var    csv     = new StringBuilder();
            String newLine = string.Format("Trials, Time Steps, relError");

            csv.AppendLine(newLine);

            for (int i = 3; i < 5; i++)
            {
                // MC Simulation Params
                int      NumberOfTrials = (int)Math.Pow(10, i);
                double[] factor         = new double[3] {
                    0.5, 1, 2
                };
                for (int j = 0; j < 3; j++)
                {
                    int NumberOfTimeSteps = (int)Math.Ceiling(factor[j] * 365 * Maturity);
                    MonteCarloSettings monteCarloSettings =
                        new MonteCarloSettings(NumberOfTrials, NumberOfTimeSteps);

                    double price = Heston.HestonEuropeanOptionPriceMC(hestonModel, euOption, monteCarloSettings);
                    System.Console.WriteLine("K={0}, T={1}, #Trials={2}, #TimeSteps={3}, rel_error={4}", StrikePrice,
                                             Maturity, NumberOfTrials, NumberOfTimeSteps, Math.Abs(priceForm - price) / priceForm);
                    newLine = string.Format("{0}, {1}, {2}", NumberOfTrials, NumberOfTimeSteps, Math.Abs(priceForm - price) / priceForm);
                    csv.AppendLine(newLine);
                }
            }

            //Write to csv
            File.WriteAllText(@"./task4.csv", csv.ToString());

            System.Console.WriteLine("*********************");
            System.Console.WriteLine("\n\n");
        }
Example #14
0
        public static void Task3()
        {
            // Variance Process Values
            Console.WriteLine("Task 3");
            // Variance Process Values
            double Kappa = 2.0;
            double Theta = 0.06;
            double Sigma = 0.4;
            double V0    = 0.04;
            double Rho   = 0.5;

            // Heston Model Params
            double InitialStockPrice = 100;
            double RiskFreeRate      = 0.1;

            // Option Params
            double     StrikePrice = 100;
            PayoffType Type        = PayoffType.Call;

            double[] Maturity = new double[5] {
                1, 2, 3, 4, 15
            };

            VarianceProcessParameters varParams =
                new VarianceProcessParameters(Kappa, Theta, Sigma, V0, Rho);

            HestonModelParameters hestonModel =
                new HestonModelParameters(InitialStockPrice, RiskFreeRate, varParams);

            // ************Task 3 Print****************
            System.Console.WriteLine("*********************");
            HestonModelParamPrint(varParams, hestonModel);

            //Prepare csv
            var    csv     = new StringBuilder();
            String newLine = string.Format("K, T, Price, refPrice");

            csv.AppendLine(newLine);

            for (int i = 0; i < 5; i++)
            {
                // MC Simulation Params
                int NumberOfTrials    = (int)1e5;
                int NumberOfTimeSteps = (int)Math.Ceiling(365 * Maturity[i]);

                EuropeanOption euOption =
                    new EuropeanOption(StrikePrice, Type, Maturity[i]);

                MonteCarloSettings monteCarloSettings =
                    new MonteCarloSettings(NumberOfTrials, NumberOfTimeSteps);
                double priceForm = Heston.HestonEuropeanOptionPrice(hestonModel, euOption);

                double price = Heston.HestonEuropeanOptionPriceMC(hestonModel, euOption, monteCarloSettings);
                System.Console.WriteLine("K={0}, T={1}, C_MC={2}, C_form={3}", StrikePrice,
                                         Maturity[i], price, priceForm);

                newLine = string.Format("{0}, {1}, {2}, {3}", StrikePrice, Maturity[i], price, priceForm);
                csv.AppendLine(newLine);
            }

            //Write to csv
            File.WriteAllText(@"./task3.csv", csv.ToString());

            System.Console.WriteLine("*********************");
            System.Console.WriteLine("\n\n");
        }
Example #15
0
 /// <summary>
 /// Initializes a new instance of the LookbackOptionMC class.
 /// </summary>
 /// <param name="parameters">Interface holding Heston Model params.</param>
 /// <param name="monteCarloSimulationSettings">Interface holding Monte carlo simulation settings.</param>
 /// <param name="maturity">Interface holding maturity.</param>
 public LookbackOptionMC(HestonModelParameters parameters,
                         MonteCarloSettings monteCarloSimulationSettings,
                         double maturity)
     : base(parameters, monteCarloSimulationSettings, maturity)
 {
 }
Example #16
0
 public EventSimulationCore(MonteCarloSettings monteCarloSettings, EventSimulationSettings eventSimulationSettings) : base(monteCarloSettings)
 {
     Settings = eventSimulationSettings;
     Timeline = new PriorityQueue <Event>();
 }