Inheritance: IExtensibleProcess, IFullSimulator, IParsable, IPopulable, IGreeksDerivativesInfo, ISerializable, IExportableContainer
        public void Test()
        {
            double nu = 0.6;
            double theta = -0.2;
            double sigma = 0.2;
            double rate = 0.02;
            double dy = 0.01;
            double s0 = 1;
            double maturity = 2.0;
            double strike = 1.2;
            Vector mat = new Vector(1) + maturity;
            Vector k = new Vector(1) + strike;

            // Calculates the theoretical value of the call.
            double theoreticalPrice = VarianceGammaOptionsCalibration.VGCall(theta, sigma, nu,
                                                                             maturity, strike,
                                                                             dy, s0, rate);

            Engine.MultiThread = true;
            Document doc = new Document();
            ProjectROV rov = new ProjectROV(doc);
            doc.Part.Add(rov);
            doc.DefaultProject.NMethods.m_UseAntiteticPaths = true;

            int n_sim = 50000;
            int n_steps = 512;

            ModelParameter paramStrike = new ModelParameter(strike, "strike");
            paramStrike.VarName = "strike";
            rov.Symbols.Add(paramStrike);

            ModelParameter paramRate = new ModelParameter(rate, "rfrate");
            paramRate.VarName = "rfrate";
            rov.Symbols.Add(paramRate);

            AFunction payoff = new AFunction(rov);
            payoff.VarName = "payoff";
            payoff.m_IndependentVariables = 1;
            payoff.m_Value = (RightValue)("max(x1 - strike ; 0)");
            rov.Symbols.Add(payoff);

            VarianceGamma process = new VarianceGamma(s0, theta, sigma, nu, rate, dy);

            StochasticProcessExtendible s = new StochasticProcessExtendible(rov, process);
            rov.Processes.AddProcess(s);

            // Set the discounting.
            RiskFreeInfo rfi = rov.GetDiscountingModel() as RiskFreeInfo;
            rfi.ActualizationType = EActualizationType.RiskFree;
            rfi.m_deterministicRF = rate;

            OptionTree op = new OptionTree(rov);
            op.PayoffInfo.PayoffExpression = "payoff(v1)";
            op.PayoffInfo.Timing.EndingTime.m_Value = (RightValue)maturity;
            op.PayoffInfo.European = true;
            rov.Map.Root = op;

            rov.NMethods.Technology = ETechType.T_SIMULATION;
            rov.NMethods.PathsNumber = n_sim;
            rov.NMethods.SimulationSteps = n_steps;

            ROVSolver solver = new ROVSolver();
            solver.BindToProject(rov);
            solver.DoValuation(-1);

            if (rov.HasErrors)
            {
                rov.DisplayErrors();
            }

            Assert.IsFalse(rov.HasErrors);

            ResultItem price = rov.m_ResultList[0] as ResultItem;

            double samplePrice = price.value;
            double sampleDevSt = price.stdDev / Math.Sqrt((double)n_sim);

            Console.WriteLine("Theoretical Price = " + theoreticalPrice);
            Console.WriteLine("Monte Carlo Price = " + samplePrice);
            Console.WriteLine("Standard Deviation = " + sampleDevSt.ToString());
            double tol = 4.0 * sampleDevSt;
            Assert.Less(Math.Abs(theoreticalPrice - samplePrice), tol);
        }
Example #2
0
        public void Test()
        {
            double nu       = 0.6;
            double theta    = -0.2;
            double sigma    = 0.2;
            double rate     = 0.02;
            double dy       = 0.01;
            double s0       = 1;
            double maturity = 2.0;
            double strike   = 1.2;
            Vector mat      = new Vector(1) + maturity;
            Vector k        = new Vector(1) + strike;

            // Calculates the theoretical value of the call.
            double theoreticalPrice = VarianceGammaOptionsCalibration.VGCall(theta, sigma, nu,
                                                                             maturity, strike,
                                                                             dy, s0, rate);

            Engine.MultiThread = true;
            Document   doc = new Document();
            ProjectROV rov = new ProjectROV(doc);

            doc.Part.Add(rov);
            doc.DefaultProject.NMethods.m_UseAntiteticPaths = true;

            int n_sim   = 50000;
            int n_steps = 512;

            ModelParameter paramStrike = new ModelParameter(strike, "strike");

            paramStrike.VarName = "strike";
            rov.Symbols.Add(paramStrike);

            ModelParameter paramRate = new ModelParameter(rate, "rfrate");

            paramRate.VarName = "rfrate";
            rov.Symbols.Add(paramRate);

            AFunction payoff = new AFunction(rov);

            payoff.VarName = "payoff";
            payoff.m_IndependentVariables = 1;
            payoff.m_Value = (RightValue)("max(x1 - strike ; 0)");
            rov.Symbols.Add(payoff);

            VarianceGamma process = new VarianceGamma(s0, theta, sigma, nu, rate, dy);

            StochasticProcessExtendible s = new StochasticProcessExtendible(rov, process);

            rov.Processes.AddProcess(s);

            // Set the discounting.
            RiskFreeInfo rfi = rov.GetDiscountingModel() as RiskFreeInfo;

            rfi.ActualizationType = EActualizationType.RiskFree;
            rfi.m_deterministicRF = rate;

            OptionTree op = new OptionTree(rov);

            op.PayoffInfo.PayoffExpression          = "payoff(v1)";
            op.PayoffInfo.Timing.EndingTime.m_Value = (RightValue)maturity;
            op.PayoffInfo.European = true;
            rov.Map.Root           = op;

            rov.NMethods.Technology      = ETechType.T_SIMULATION;
            rov.NMethods.PathsNumber     = n_sim;
            rov.NMethods.SimulationSteps = n_steps;

            ROVSolver solver = new ROVSolver();

            solver.BindToProject(rov);
            solver.DoValuation(-1);

            if (rov.HasErrors)
            {
                rov.DisplayErrors();
            }

            Assert.IsFalse(rov.HasErrors);

            ResultItem price = rov.m_ResultList[0] as ResultItem;

            double samplePrice = price.value;
            double sampleDevSt = price.stdDev / Math.Sqrt((double)n_sim);

            Console.WriteLine("Theoretical Price = " + theoreticalPrice);
            Console.WriteLine("Monte Carlo Price = " + samplePrice);
            Console.WriteLine("Standard Deviation = " + sampleDevSt.ToString());
            double tol = 4.0 * sampleDevSt;

            Assert.Less(Math.Abs(theoreticalPrice - samplePrice), tol);
        }