Beispiel #1
0
        /// <summary>
        /// Populate editable fields from name and value vectors
        /// specific to the Heston extended process.
        /// </summary>
        /// <param name="stocProcess">
        /// The stochastic process which is being referenced to.
        /// </param>
        /// <param name="estimate">
        /// The estimation result which contains values and names of parameters.
        /// It will be searched for S0, kappa, theta, sigma, V0 and rho.
        /// </param>
        public void Populate(IStochasticProcess stocProcess, EstimationResult estimate)
        {
            bool found;

            this.S0    = new ModelParameter(PopulateHelper.GetValue("S0", estimate.Names, estimate.Values, out found), this.S0.Description);
            this.k     = new ModelParameter(PopulateHelper.GetValue("kappa", estimate.Names, estimate.Values, out found), this.k.Description);
            this.theta = new ModelParameter(PopulateHelper.GetValue("theta", estimate.Names, estimate.Values, out found), this.theta.Description);
            this.sigma = new ModelParameter(PopulateHelper.GetValue("sigma", estimate.Names, estimate.Values, out found), this.sigma.Description);
            this.V0    = new ModelParameter(PopulateHelper.GetValue("V0", estimate.Names, estimate.Values, out found), this.V0.Description);

            int            index = stocProcess.NoiseIndex;
            ProjectProcess prj   = stocProcess.Context as ProjectProcess;

            // Update the correlation matrix.
            prj.Processes.r.Set(index, index + 1, (RightValue)PopulateHelper.GetValue("rho", estimate.Names, estimate.Values, out found));
            bool errors = RetrieveCurve(stocProcess.Context, false);

            if (!errors)
            {
                this.zrCurve.Expr = (estimate.Objects[0] as Matrix).ToArray();
                this.dyCurve.Expr = (estimate.Objects[1] as Matrix).ToArray();
                //Calibrator assumes dividend yield is a step constant function, the simulation model must be coherent with that assumption.
                (this.dyCurve as PFunction).m_Function.iType = DVPLUtils.EInterpolationType.ZERO_ORDER_LEFT;
            }
        }
Beispiel #2
0
        public void Populate(IStochasticProcess container, EstimationResult estimate)
        {
            bool found;

            this.s0 = new ModelParameter(PopulateHelper.GetValue("S0", estimate.Names, estimate.Values, out found), this.s0.Description);

            bool errors = RetrieveCurve(container.Context, false);

            if (!errors)
            {
                PFunction rFunc     = estimate.Objects[0] as PFunction;
                PFunction rFuncDest = this.r.fVRef() as PFunction;
                rFuncDest.Expr = rFunc.Expr;

                PFunction qFunc     = estimate.Objects[1] as PFunction;
                PFunction qFuncDest = this.q.fVRef() as PFunction;
                qFuncDest.Expr = qFunc.Expr;
                //Calibrator assumes dividend yield is a step constant function, the simulation model must be coherent with that assumption.
                qFuncDest.m_Function.iType = DVPLUtils.EInterpolationType.ZERO_ORDER_LEFT;


                PFunction2D.PFunction2D localVolSrc  = estimate.Objects[2] as PFunction2D.PFunction2D;
                PFunction2D.PFunction2D localVolDest = this.localVol.fVRef() as PFunction2D.PFunction2D;
                localVolDest.Expr          = localVolSrc.Expr;
                localVolDest.Interpolation = localVolSrc.Interpolation;
            }
        }
        /// <summary>
        /// Populate editable fields from name and value vectors
        /// specific to Pelsser.
        /// </summary>
        /// <param name="names">
        /// An array with the names of the variable,
        /// will search for alpha1 (or a), sigma1 (or sigma) and lamba0.
        /// </param>
        /// <param name="values">The values associated to the parameters in names.</param>
        public void Populate(string[] names, double[] values)
        {
            bool found;

            this.a1     = new ModelParameter(PopulateHelper.GetValue("alpha1", "a", names, values, out found), a1Description);
            this.sigma1 = new ModelParameter(PopulateHelper.GetValue("sigma1", "sigma", names, values, out found), sigma1Description);
            this.lamda0 = new ModelParameter(PopulateHelper.GetValue("lambda0", "lambda", names, values, out found), lambda0Description);
        }
Beispiel #4
0
        private void bgCreateScript_DoWork(object sender, DoWorkEventArgs e)
        {
            string[]       sourceLines = (string[])e.Argument;
            PopulateHelper popHelper   = new PopulateHelper(null);
            string         script      = popHelper.GeneratePopulateScriptsFromDataExtractFile(sourceLines);

            e.Result = script;
        }
Beispiel #5
0
        /*
         * /// <summary>
         * /// Populate editable fields from name and value vectors
         * /// specific to HW.
         * /// </summary>
         * /// <param name="names">
         * /// An array with the names of the variable,
         * /// will search for alpha (or a1), sigma (or sigma1).
         * /// </param>
         * /// <param name="values">The values associated to the parameters in names.</param>
         * public void Populate(string[] names, double[] values)
         * {
         *  bool found = false;
         *  this.alpha1 = new ModelParameter(PopulateHelper.GetValue("alpha", "a1", names, values, out found), alphaDescription);
         *  this.sigma1 = new ModelParameter(PopulateHelper.GetValue("sigma", "sigma1", names, values, out found), sigmaDescription);
         *  this.lambda0 = new ModelParameter(PopulateHelper.GetValue("Lambda0", "lambda0", names, values, out found), lambda0Description);
         * }
         */

        /// <summary>
        /// Populate editable fields from name and value vectors
        /// specific to the Heston extended process.
        /// </summary>
        /// <param name="stocProcess">
        /// The stochastic process which is being referenced to.
        /// </param>
        /// <param name="estimate">
        /// The estimation result which contains values and names of parameters.
        /// It will be searched for S0, kappa, theta, sigma, V0 and rho.
        /// </param>
        public void Populate(IStochasticProcess stocProcess, EstimationResult estimate)
        {
            bool found;

            this.alpha1  = new ModelParameter(PopulateHelper.GetValue("alpha", "a1", estimate.Names, estimate.Values, out found), alphaDescription);
            this.sigma1  = new ModelParameter(PopulateHelper.GetValue("sigma", "sigma1", estimate.Names, estimate.Values, out found), sigmaDescription);
            this.lambda0 = new ModelParameter(PopulateHelper.GetValue("Lambda0", "lambda0", estimate.Names, estimate.Values, out found), lambda0Description);
        }
        public void Populate(string[] names, double[] values)
        {
            bool found;

            this.spot   = new ModelParameter(PopulateHelper.GetValue(spotLabel, names, values, out found), spotLabel);
            this.mu     = new ModelParameter(PopulateHelper.GetValue(muLabel, names, values, out found), muLabel);
            this.lambda = new ModelParameter(PopulateHelper.GetValue(lambdaLabel, names, values, out found), lambdaLabel);
            this.sigma  = new ModelParameter(PopulateHelper.GetValue(sigmaLabel, names, values, out found), sigmaLabel);
        }
Beispiel #7
0
        /// <summary>
        /// Populate editable fields from name and value vectors
        /// specific to HW2.
        /// </summary>
        /// <param name="names">
        /// An array with the names of the variable,
        /// will search for alpha1 (or a1), sigma1 (or sigma), alpha2 (or a2), sigma2 and rho.
        /// </param>
        /// <param name="values">The values associated to the parameters in names.</param>
        public void Populate(string[] names, double[] values)
        {
            bool found = false;

            this._a1  = new ModelParameter(PopulateHelper.GetValue("alpha1", "a1", names, values, out found), a1Description);
            this._s1  = new ModelParameter(PopulateHelper.GetValue("sigma1", "sigma", names, values, out found), s1Description);
            this._a2  = new ModelParameter(PopulateHelper.GetValue("alpha2", "a2", names, values, out found), a2Description);
            this._s2  = new ModelParameter(PopulateHelper.GetValue("sigma2", names, values, out found), s2Description);
            this._rho = new ModelParameter(PopulateHelper.GetValue("rho", names, values, out found), rhoDescription);
        }
Beispiel #8
0
        /// <summary>
        /// Populate editable fields from name and value vectors specific to VG.
        /// </summary>
        /// <param name="names">
        /// An array with the names of the variables.
        /// </param>
        /// <param name="values">The values associated to the parameters in names.</param>
        public void Populate(string[] names, double[] values)
        {
            bool found = false;

            this.theta = new ModelParameter(PopulateHelper.GetValue("S0", names, values, out found), thetaDescription);
            this.sigma = new ModelParameter(PopulateHelper.GetValue("theta", names, values, out found), sigmaDescription);
            this.theta = new ModelParameter(PopulateHelper.GetValue("sigma", names, values, out found), thetaDescription);
            this.theta = new ModelParameter(PopulateHelper.GetValue("nu", names, values, out found), thetaDescription);
            this.theta = new ModelParameter(PopulateHelper.GetValue("rate", names, values, out found), thetaDescription);
            this.theta = new ModelParameter(PopulateHelper.GetValue("dividend", names, values, out found), thetaDescription);
        }
Beispiel #9
0
        /// <summary>
        /// Populate editable fields from name and value vectors
        /// specific to the CIR process.
        /// </summary>
        /// <param name="container">
        /// The stochastic process which is being referenced to.
        /// </param>
        /// <param name="estimate">
        /// The estimation result which contains values and names of parameters.
        /// </param>
        public void Populate(IStochasticProcess container, EstimationResult estimate)
        {
            bool found;

            this.parameterValues = new double[4];
            for (int i = 0; i < parameterNames.Length; i++)
            {
                this.parameterValues[i] = PopulateHelper.GetValue(parameterNames[i],
                                                                  estimate.Names, estimate.Values,
                                                                  out found);
                Console.WriteLine("ParameterValues[{0}] = {1}\t ParameterNames[{0}] = {2}",
                                  i, this.parameterValues[i], parameterNames[i]);
            }

            SetParametersValue();
        }
Beispiel #10
0
        /// <summary>
        /// Populate editable fields from name and value vectors
        /// specific to the Heston extended process.
        /// </summary>
        /// <param name="stocProcess">
        /// The stochastic process which is being referenced to.
        /// </param>
        /// <param name="estimate">
        /// The estimation result which contains values and names of parameters.
        /// It will be searched for S0, kappa, theta, sigma, V0, r, q and rho.
        /// </param>
        public void Populate(IStochasticProcess stocProcess, EstimationResult estimate)
        {
            bool found;

            this.S0    = new ModelParameter(PopulateHelper.GetValue("S0", estimate.Names, estimate.Values, out found), this.S0.Description);
            this.k     = new ModelParameter(PopulateHelper.GetValue("kappa", estimate.Names, estimate.Values, out found), this.k.Description);
            this.theta = new ModelParameter(PopulateHelper.GetValue("theta", estimate.Names, estimate.Values, out found), this.theta.Description);
            this.sigma = new ModelParameter(PopulateHelper.GetValue("sigma", estimate.Names, estimate.Values, out found), this.sigma.Description);
            this.V0    = new ModelParameter(PopulateHelper.GetValue("V0", estimate.Names, estimate.Values, out found), this.V0.Description);
            this.r     = new ModelParameter(PopulateHelper.GetValue("r", estimate.Names, estimate.Values, out found), this.r.Description);
            this.q     = new ModelParameter(PopulateHelper.GetValue("q", estimate.Names, estimate.Values, out found), this.q.Description);

            int            index = stocProcess.NoiseIndex;
            ProjectProcess prj   = stocProcess.Context as ProjectProcess;

            // Updates the correlation.
            prj.Processes.r.Set(index, index + 1, (RightValue)PopulateHelper.GetValue("rho", estimate.Names, estimate.Values, out found));
        }
        private void WhereClauseForm_Load(object sender, System.EventArgs e)
        {
            PopulateHelper helper = new PopulateHelper(data, null);

            string[] columns = SqlSync.DbInformation.InfoHelper.GetColumnNames(this.tableName, this.data);
            for (int i = 0; i < columns.Length; i++)
            {
                lstColumns.Items.Add(columns[i]);
            }

            //Pre-check exising "Update key selections"
            for (int i = 0; i < columns.Length; i++)
            {
                lstUpdateKeyColumns.Items.Add(columns[i]);
                for (int j = 0; j < this.checkKeyColumns.Length; j++)
                {
                    if (columns[i].Trim().ToUpper() == this.checkKeyColumns[j].Trim().ToUpper())
                    {
                        lstUpdateKeyColumns.Items[lstUpdateKeyColumns.Items.Count - 1].Checked = true;
                        break;
                    }
                }
            }
        }
        public void TestCalibration()
        {
            InterestRateMarketData IData = InterestRateMarketData.FromFile("../../TestData/IRMD-sample.xml");
            CallPriceMarketData    HData = CallPriceMarketData.FromFile("../../TestData/CallData-sample.xml");
            //InterestRateMarketData IData = InterestRateMarketData.FromFile("../../../EquityModels.Tests/TestData/IRMD-EU-30102012-close.xml");
            //CallPriceMarketData HData = CallPriceMarketData.FromFile("../../../EquityModels.Tests/TestData/30102012-SX5E_Index-HestonData.xml");
            //CallPriceMarketData HData = ObjectSerialization.ReadFromXMLFile("../../../EquityModels.Tests/TestData/FTSE.xml") as CallPriceMarketData;


            List <object> l = new List <object>();

            l.Add(IData.DiscountingCurve);
            l.Add(HData);

            DupireEstimator           DE       = new DupireEstimator();
            DupireCalibrationSettings settings = new DupireCalibrationSettings();

            settings.LocalVolatilityCalculation = LocalVolatilityCalculation.Method1;


            //settings.LocalVolatilityCalculation = LocalVolatilityCalculation.QuantLib;
            EstimationResult res = DE.Estimate(l, settings);
            //int nmat = HData.Maturity.Length;
            //int nstrike = HData.Strike.Length;

            int i = 5; // Maturity.
            int j = 4; // Strike.

            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   = 10000;
            int    n_steps = 500;
            double strike  = HData.Strike[j];
            //double volatility = HData.Volatility[i, j];

            /*
             * PFunction2D.PFunction2D impvolfunc = new PFunction2D.PFunction2D(rov);
             * impvolfunc = res.Objects[3] as PFunction2D.PFunction2D;
             * impvolfunc.VarName = "impvol";
             * rov.Symbols.Add(impvolfunc);
             * double volatility = impvolfunc.Evaluate(HData.Maturity[i], HData.Strike[j]);
             */
            double volatility = 0.2;
            double maturity   = HData.Maturity[i];

            ModelParameter Pstrike = new ModelParameter(strike, string.Empty, "strike");

            rov.Symbols.Add(Pstrike);
            AFunction payoff = new AFunction(rov);

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

            bool           found;
            double         S0  = PopulateHelper.GetValue("S0", res.Names, res.Values, out found);
            ModelParameter PS0 = new ModelParameter(S0, string.Empty, "S0");

            rov.Symbols.Add(PS0);
            PFunction rfunc = new PFunction(rov);

            rfunc         = res.Objects[0] as PFunction;
            rfunc.VarName = "r";
            rov.Symbols.Add(rfunc);

            PFunction qfunc = new PFunction(rov);

            qfunc         = res.Objects[1] as PFunction;
            qfunc.VarName = "q";
            rov.Symbols.Add(qfunc);

            PFunction2D.PFunction2D volfunc = new PFunction2D.PFunction2D(rov);
            volfunc         = res.Objects[2] as PFunction2D.PFunction2D;
            volfunc.VarName = "localvol";
            rov.Symbols.Add(volfunc);
            DupireProcess process = new DupireProcess();

            process.s0       = (ModelParameter)"S0";
            process.r        = (ModelParameter)"@r";
            process.q        = (ModelParameter)"@q";
            process.localVol = (ModelParameter)"@localvol";
            double rate = rfunc.Evaluate(maturity);
            double dy   = qfunc.Evaluate(maturity);

            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("Surf = " + volfunc.Expr);

            // Calculation of the theoretical value of the call.
            double theoreticalPrice = BlackScholes.Call(rate, S0, strike, volatility, maturity, dy);

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

            doc.WriteToXMLFile("Dupire.fair");
            Assert.LessOrEqual(Math.Abs(theoreticalPrice - samplePrice), tol);
        }