Example #1
0
        //Runs monte carlo for the "other values" in Task 2.1 using the answer designed for Task 2.2
        static void doTask22(SSVIparametrisasion ssvi, int timesteps, int nrofpaths)
        {
            Console.WriteLine("\nTask 2.2 compared to task 2.1");

            double price = 0;

            double[]  K  = new double[] { 102.5313, 105.1271, 103.8212, 80, 80, 90, 120, 90 }; //Values to test
            double[]  T  = new double[] { 1, 2, 1.5, 1, 2, 1, 1, 2 };                          //Compare with Task 2.1
            Stopwatch sw = new Stopwatch();                                                    //for measuring how long this simulation takes

            sw.Start();
            for (int i = 0; i < T.Length; ++i)
            {
                if (i < 6) //Call options
                {
                    price = ssvi.MonteCarloEuropeanCall(T[i], K[i], nrofpaths, timesteps);
                    Console.WriteLine("For K = {0}, T = {1}, Call option price = {2}", K[i], T[i], Math.Round(price, 2));
                }
                else  //Put options
                {
                    price = ssvi.MonteCarloEuropeanPut(T[i], K[i], nrofpaths, timesteps);
                    Console.WriteLine("For K = {0}, T = {1}, Put option price = {2}", K[i], T[i], Math.Round(price, 2));
                }
            }
            sw.Stop();

            Console.WriteLine("\nTime with parallel for loops elapsed = {0}", sw.Elapsed);
        }
Example #2
0
        public double T, K, S; // Parameters needed for path

        public GeneratePath(SSVIparametrisasion ssvi)
        {
            numericalDerivative = new MathNet.Numerics.Differentiation.NumericalDerivative(); //to approximate derivaties with the finite diff method.
            this.ssvi           = ssvi;                                                       //The surface we are working with
            this.S = ssvi.S;
            this.T = ssvi.T;
        }
Example #3
0
        //Do monte carlo simulations for lookback options as described in task 2.5
        static void doTask25(SSVIparametrisasion ssvi, int timesteps, int nrofpaths)
        {
            Console.WriteLine("\nValues for Task 2.5");
            double[] T = new double[] { 0.5, 1, 1.5 };
            double   K = 100;

            foreach (double t in T)
            {
                double MCprice = ssvi.PricingLookbackOpt(t, K, nrofpaths, timesteps);
                Console.WriteLine("Pricing lookback option MC price: {0} for T: {1} ", Math.Round(MCprice, 2), t);
            }
        }
Example #4
0
        //Compare performance of monte carlo wtih parallel for loops and regular loops
        static void doTaskExtra(SSVIparametrisasion ssvi, int timesteps, int nrofpaths)
        {
            Console.WriteLine("\nCompare speed of parallel Monte Carlo and regular Monte Carlo");
            double price;                                      //option price

            double[] K = new double[] { 80, 80, 90, 120, 90 }; //Values to test
            double[] T = new double[] { 1, 2, 1, 1, 2 };       //Compare with Task 2.1

            for (int pths = 100; pths <= nrofpaths; pths *= 10)
            {
                Stopwatch sw = new Stopwatch(); //Object to time this method
                Console.WriteLine("\nRunning European option price monte carlo simulation with {0} paths using regular loops", pths);
                sw.Start();
                for (int i = 0; i < T.Length; ++i)
                {
                    if (i < 3) //Call options
                    {
                        price = ssvi.MonteCarloEuropeanCallSlow(T[i], K[i], pths, timesteps);
                    }
                    else  //Put options
                    {
                        price = ssvi.MonteCarloEuropeanPutSlow(T[i], K[i], pths, timesteps);
                    }
                }
                sw.Stop();
                Console.WriteLine("\nTask 2.2 completed with number of paths {0}", pths);
                Console.WriteLine("Time with regular loops elapsed = {0}", sw.Elapsed);
                sw = new Stopwatch(); //Object to time this method
                Console.WriteLine("\nRunning European option price monte carlo simulation with {0} paths using parallel loops", pths);
                sw.Start();
                for (int i = 0; i < T.Length; ++i)
                {
                    if (i < 3) //Call options
                    {
                        price = ssvi.MonteCarloEuropeanCall(T[i], K[i], pths, timesteps);
                    }
                    else  //Put options
                    {
                        price = ssvi.MonteCarloEuropeanPut(T[i], K[i], pths, timesteps);
                    }
                }
                sw.Stop();
                Console.WriteLine("\nTask 2.2 completed with number of pths {0}", pths);
                Console.WriteLine("Time with parallel loops elapsed = {0}", sw.Elapsed);
            }
        }
Example #5
0
        //Does monte carlo simulation to get asian arithmetic call options as described in task 2.4
        static void doTask24(SSVIparametrisasion ssvi, int timesteps, int nrofpaths)
        {
            Console.WriteLine("\nValues for Task 2.4");

            double[][] Tsteps = new double[][]
            {
                new double[] { 0.1, 0.2, 0.3, 0.4, 0.5 },
                new double[] { 0.25, 0.50, 0.75, 1.00 },
                new double[] { 0.5, 1 }
            };
            double[] T = { 0.5, 1, 1.5 };
            double   K = 100;

            for (int i = 0; i < T.Length; i++)
            {
                double MCprice = ssvi.AsianArithmeticCallMonteCarlo(T[i], Tsteps[i], K, nrofpaths, timesteps);
                Console.WriteLine("Asian arithmetic call option MC price: {0} for T: {1} ", Math.Round(MCprice, 2), string.Join(", ", Tsteps[i]));
            }
        }
Example #6
0
        //Method that does everything needed in task 2.1 gives the values for the table
        static void doTask21(SSVIparametrisasion ssvi)
        {
            double sigma;

            double[] K = new double[] { 102.5313, 105.1271, 103.8212 }; //Ks for on the money
            double[] T = new double[] { 1, 2, 1.5 };                    //Ts for on the money
            Console.WriteLine("Task 2.1");
            Console.WriteLine("On the money prices");

            //Loop to get call option prices "on the money"
            for (int i = 0; i < K.Length; ++i)
            {
                ssvi.T = T[i];
                sigma  = ssvi.SSVI_Impliedvolatility(T[i], 0);
                double call_price = (BlackScholesFormula.CalculateCallOptionPrice(ssvi.S, ssvi.r, sigma, K[i], T[i]));
                Console.WriteLine("For K = {0}, T = {1}, C(0, S) = {2}", K[i], T[i], Math.Round(call_price, 2));
            }
            double k;

            Console.WriteLine("\nOther prices");
            //Values for "other prices"
            K = new double[] { 80, 80, 90, 120, 90 };
            T = new double[] { 1, 2, 1, 1, 2 };
            //Loop that gets call option prices where k is not 0
            for (int i = 0; i < K.Length; ++i)
            {
                ssvi.T = T[i];
                k      = ssvi.Log_moneyness(K[i]);

                sigma = ssvi.SSVI_Impliedvolatility(T[i], k);
                double price;
                if (i < 3) //call options
                {
                    price = (BlackScholesFormula.CalculateCallOptionPrice(ssvi.S, ssvi.r, sigma, K[i], T[i]));
                    Console.WriteLine("For K = {0}, T = {1}, Call option price = {2}", K[i], T[i], Math.Round(price, 2));
                }
                else //put options
                {
                    price = (BlackScholesFormula.CalculatePutOptionPrice(ssvi.S, ssvi.r, sigma, K[i], T[i]));
                    Console.WriteLine("For K = {0}, T = {1}, Put option price = {2}", K[i], T[i], Math.Round(price, 2));
                }
            }
        }
Example #7
0
        //Use main to call other methods
        static void Main(string[] args)
        {
            //Declare parameters
            double S = 100;
            double n = 0.2, rho = 0.3, gamma = 0.7, alpha = Math.Sqrt(0.1), beta = 1, r = 0.025;  //constants given in assignment description
            SSVIparametrisasion ssvi = new SSVIparametrisasion(n, gamma, rho, alpha, beta, r, S); //create the surface
            int timesteps = 128, nrofpaths = 100000;                                              //Change this to make code faster

            //Use static methods to complete task in a organized way
            //doTask21(ssvi);
            Console.WriteLine("\nMonte Carlo methods using {0} different paths with {1} time steps", nrofpaths, timesteps);

            doTask22(ssvi, timesteps, nrofpaths);
            doTask24(ssvi, timesteps, nrofpaths);
            doTask25(ssvi, timesteps, nrofpaths);

            doTaskExtra(ssvi, timesteps, nrofpaths);

            Console.WriteLine("\nProgram execution completed press any key to continue");
            Console.ReadKey();
        }