Exemple #1
0
        public ColumnVector VIXfuture_HybridMethod(double T, Func <double, double> epsilon)
        {
            //Result
            ColumnVector VIXFutures;
            //For Exécution Time
            DateTime start = DateTime.Now;
            //Input:
            int kappa = 2;

            // the Gri t_0 ..... t_{100} = T
            int  n    = 500;
            Grid grid = new Grid(0, T, (int)Math.Abs(T * n));

            int n_T = grid.get_timeNmbrStep();

            n_tH = Math.Pow(n_T, H - 0.5); //optimizeMC

            //The second Grid  t_0=T, t_1 ..... t_N = T + Delta
            int Nbstep = 20;

            //Correlation :
            SymmetricMatrix correl         = MakeCorrel(n, grid);
            SquareMatrix    choleskyCorrel = correl.CholeskyDecomposition().SquareRootMatrix();

            int period = 100;

            VIXFutures = new ColumnVector(grid.get_timeNmbrStep() / period);


            //--------------------------------------------------------------------------------------------------------------------------------------------------------------
            //-----------------------------------MC----------------------------------------------------------------------------------------------------------------------
            //-----------------------------------------------------------------------------------------------------------------------------------------------------------
            var          MCnbofSimulation = 3.0E4;
            HybridScheme hybridscheme     = new HybridScheme(choleskyCorrel, grid, kappa, H);

            for (int mc = 1; mc <= MCnbofSimulation; mc++)
            {
                // 1-simulation of volterra Hybrid Scheme
                ColumnVector Z;
                ColumnVector volterra;
                ColumnVector Z_Brownian;

                hybridscheme.simulateFFT(out Z, out volterra);

                //2 - extract the path of the Brownian motion Z driving the Volterra process
                Z_Brownian = ExtractBrownian(kappa, n_T, Z, volterra);

                //Grid secondGrid2 = new Grid(grid.t(n_T), grid.t(n_T) + Delta, 20);
                //ColumnVector volterraT2 = EulerMEthode(grid, secondGrid2, n_T, volterra, Z_Brownian);
                //double VIX_future_i2 = VIX_Calculate(epsilon, secondGrid2, volterraT2);
                //VIXFutures[0] += VIX_future_i2;


                //DateTime starttestM = DateTime.Now;
                //for (int zz = 1; zz <= 1.0E4; zz++)
                //{
                //    hybridscheme.simulateFFT(out Z, out volterra);
                //}
                //TimeSpan timeExecutiontestM = DateTime.Now - starttestM;

                //DateTime starttest = DateTime.Now;
                //for (int zz = 1; zz <= 1.0E4; zz++)
                //{
                //    for (int i = 1; i <= volterra.Count() / period; i++)
                //    {
                //        int N_i2 = i * period;

                //        //3- approximate the continuous-time process V^T by the discrete-time version V^T~ defined via the  forward Euler scheme
                //        double[] volterraT2 = EulerMEthode(grid, secondGrid, N_i2, volterra, Z_Brownian);
                //        //double VIX_future_i2 = VIX_Calculate(epsilon, secondGrid, volterraT2);
                //        //VIXFutures[i - 1] += VIX_future_i2;
                //    }
                //}
                //TimeSpan timeExecutiontest = DateTime.Now - starttest;

                for (int i = 1; i <= volterra.Count() / period; i++)
                {
                    int  N_i        = i * period;
                    Grid secondGrid = new Grid(grid.t(N_i), grid.t(N_i) + Delta, Nbstep);
                    //3- approximate the continuous-time process V^T by the discrete-time version V^T~ defined via the  forward Euler scheme
                    double[] volterraT    = EulerMEthode(grid, secondGrid, N_i, volterra, Z_Brownian);
                    double   VIX_future_i = VIX_Calculate(epsilon, secondGrid, volterraT);
                    VIXFutures[i - 1] += VIX_future_i;
                }
            }// ENd of MC
            //MC Mean
            for (int i = 0; i < VIXFutures.Count(); i++)
            {
                VIXFutures[i] /= MCnbofSimulation;
            }
            TimeSpan timeExecution = DateTime.Now - start;

            return(VIXFutures);
        }
Exemple #2
0
        public double PriceVIXOption(VIXOption Option, Func <double, double> epsilon, double stock_0)
        {
            int    n    = 500;
            double T    = Option.maturity;
            Grid   grid = new Grid(0, T, (int)Math.Abs(T * n));
            int    n_T  = grid.get_timeNmbrStep();

            int kappa = 2;
            //Correlation :
            SymmetricMatrix correl         = MakeCorrel(n, grid);
            SquareMatrix    choleskyCorrel = correl.CholeskyDecomposition().SquareRootMatrix();

            double rho = 0.1;//correlation between the two Brownian
            Func <double, double> payoff;

            switch (Option.type)
            {
            case VIXOption.OptionType.Call:
                payoff = S => Math.Max(S - Option.strike, 0);
                break;

            case VIXOption.OptionType.Put:
                payoff = S => Math.Max(Option.strike - S, 0);
                break;

            default:
                payoff = S => Math.Max(S - Option.strike, 0);
                break;
            }

            double price          = 0.0;
            double McNbSimulation = 1E5;

            for (int mc = 1; mc <= McNbSimulation; mc++)
            {
                // 1-simulation of volterra Hybrid Scheme
                ColumnVector Z;
                ColumnVector volterra;
                //ColumnVector Z_Brownian;

                HybridScheme hybridscheme = new HybridScheme(choleskyCorrel, grid, kappa, H);
                hybridscheme.simulate(out Z, out volterra);

                GaussianSimulator simulator = new GaussianSimulator();
                //Z_Brownian = ExtractBrownian(kappa, n_T, Z, volterra);

                ColumnVector Variance = new ColumnVector(n_T + 1);
                Variance[0] = epsilon(grid.t(0));
                for (int i = 1; i <= grid.get_timeNmbrStep(); i++)
                {
                    Variance[i] = epsilon(grid.t(i)) * Math.Exp(2 * vi * Ch * volterra[i - 1] - Math.Pow(vi * Ch, 2) * Math.Pow(grid.t(i), 2 * H));
                }
                double X = Math.Log(stock_0);
                for (int i = 0; i < n_T; i++)
                {
                    double dW = (rho * Z[i] + Math.Sqrt(1 - Math.Pow(rho, 2)) * Math.Sqrt(grid.get_Step()) * simulator.Next());
                    X = X - 0.5 * Variance[i] * grid.get_Step() + Math.Sqrt(Variance[i]) * dW;
                }

                double S = Math.Exp(X);
                price += payoff(S);
            }
            price /= McNbSimulation;
            return(price);
        }