Esempio n. 1
0
        static void Main(string[] args)
        {
            //Ploting results Graph
            //Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new Graph());


            rBergomiVIXfuture     model     = new rBergomiVIXfuture();
            Func <double, double> epsilon_0 = t => Math.Pow(0.235, 2);// *Math.Sqrt(1 + t);
            double T = 2.0;
            //// the Gri t_0 ..... t_{100} = T
            int  n    = 500;
            Grid grid = new Grid(0, T, (int)Math.Abs(T * n));

            //lognormal
            double vixfuture_LogNormal = model.VIXfuture_LogNormal(grid.t(35), epsilon_0);
            // //Mc with hybrid Scheme
            ColumnVector vixfuture_Hybrid = model.VIXfuture_HybridMethod(T, epsilon_0);
            ColumnVector newvixfutures    = new ColumnVector(vixfuture_Hybrid.Count());
            ColumnVector newvixlognorm    = new ColumnVector(vixfuture_Hybrid.Count());
            ColumnVector newvixtruncated  = new ColumnVector(vixfuture_Hybrid.Count());

            ColumnVector ti      = new ColumnVector(vixfuture_Hybrid.Count());
            int          perdiod = 100;

            for (int i = 0; i < vixfuture_Hybrid.Count(); i++)
            {
                int N_i = (i + 1) * perdiod;
                ti[i]              = grid.t((N_i));
                newvixfutures[i]   = vixfuture_Hybrid[i];
                newvixtruncated[i] = model.VIXfuture_TruncatedChlsky(ti[i], epsilon_0);
                newvixlognorm[i]   = model.VIXfuture_LogNormal(ti[i], epsilon_0);
            }
            Application.Run(new Plot(ti, newvixlognorm, newvixfutures, newvixtruncated));
            //Application.Run(new Plot(ti, newvixfutures,newvixlognorm, "Volterra Simulation in hybrid Method", "T + Delta ", "V", "volterra process"));
            //Application.Run(new Plot(ti, newvixlognorm, "Volterra Simulation in hybrid Method", "T + Delta ", "V", "volterra process"));

            // //Mc with trancated Cholesky
            double TrancatedMethode_MCstdDeviation;
            double vixfuture_trancated = model.VIXfuture_TruncatedChlsky(T, epsilon_0, out TrancatedMethode_MCstdDeviation);

            //S&P Option Pricing
            VIXOption option      = new VIXOption(VIXOption.OptionType.Call, 1.0, 100);
            double    optionPrice = model.PriceVIXOption(option, epsilon_0, 100);
        } //Main
Esempio n. 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);
        }