Exemplo n.º 1
0
        /// <summary>
        /// Method for calibrating the heston model.
        /// </summary>
        /// <param name="guessModelParameters">Object implementing IHestonModelParameters interface containing the risk-free rate, initial stock price
        /// and initial guess parameters to be used in the calibration.</param>
        /// <param name="referenceData">A collection of objects implementing IOptionMarketData<IEuropeanOption> interface. These should contain the reference data used for calibration.</param>
        /// <param name="calibrationSettings">An object implementing ICalibrationSettings interface.</param>
        /// <returns>Object implementing IHestonCalibrationResult interface which contains calibrated model parameters and additional diagnostic information</returns>
        public static IHestonCalibrationResult CalibrateHestonParameters(IHestonModelParameters guessModelParameters, IEnumerable <IOptionMarketData <IEuropeanOption> > referenceData, ICalibrationSettings calibrationSettings)
        {
            try
            {
                // Copy Linked List
                LinkedList <OptionMarketData <EuropeanOption> > data =
                    new LinkedList <OptionMarketData <EuropeanOption> >();
                foreach (OptionMarketData <IEuropeanOption> marketData in referenceData)
                {
                    OptionMarketData <EuropeanOption> newMarketData =
                        new OptionMarketData <EuropeanOption>((EuropeanOption)marketData.Option, marketData.Price);
                    data.AddLast(newMarketData);
                }
                // Heston Calibrator
                HestonCalibrator calibrator =
                    new HestonCalibrator((HestonModelParameters)guessModelParameters,
                                         data,
                                         (CalibrationSettings)calibrationSettings);
                // Calibration procedure
                calibrator.Calibrate();
                // Retrieve outcome
                double             error   = 0;
                CalibrationOutcome outcome = CalibrationOutcome.NotStarted;
                calibrator.GetCalibrationStatus(ref outcome, ref error);
                HestonModelParameters parameters = calibrator.GetCalibratedModel();
                // Form calibration result object
                HestonCalibrationResult result = new HestonCalibrationResult(error, outcome, parameters);

                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Method for calibrating the heston model.
        /// </summary>
        /// <param name="guessModelParameters">Object implementing IHestonModelParameters interface containing the risk-free rate, initial stock price
        /// and initial guess parameters to be used in the calibration.</param>
        /// <param name="referenceData">A collection of objects implementing IOptionMarketData<IEuropeanOption> interface. These should contain the reference data used for calibration.</param>
        /// <param name="calibrationSettings">An object implementing ICalibrationSettings interface.</param>
        /// <returns>Object implementing IHestonCalibrationResult interface which contains calibrated model parameters and additional diagnostic information</returns>
        public static IHestonCalibrationResult CalibrateHestonParameters(IHestonModelParameters guessModelParameters,
                                                                         IEnumerable <IOptionMarketData <IEuropeanOption> > referenceData,
                                                                         ICalibrationSettings calibrationSettings)
        {
            HestonCalibrator calibrator = new HestonCalibrator(guessModelParameters.RiskFreeRate,
                                                               guessModelParameters.InitialStockPrice,
                                                               calibrationSettings.Accuracy,
                                                               calibrationSettings.MaximumNumberOfIterations);

            calibrator.SetGuessParameters(guessModelParameters.VarianceParameters.V0,
                                          guessModelParameters.VarianceParameters.Kappa,
                                          guessModelParameters.VarianceParameters.Theta,
                                          guessModelParameters.VarianceParameters.Rho,
                                          guessModelParameters.VarianceParameters.Sigma);
            foreach (IOptionMarketData <IEuropeanOption> M in referenceData)
            {
                calibrator.AddObservedOption(M.Option.StrikePrice, M.Option.Maturity, M.Price);
            }
            calibrator.Calibrate();
            double             error   = 0;
            CalibrationOutcome outcome = CalibrationOutcome.NotStarted;

            calibrator.GetCalibrationStatus(ref outcome, ref error);
            var calibratedModel = calibrator.GetCalibratedModel();

            Console.WriteLine("Calibration outcome: {0} and error: {1}", outcome, error);
            return(new HestonCalibrationResult(outcome, error, new HestonParametersGrading(guessModelParameters.InitialStockPrice, guessModelParameters.RiskFreeRate,
                                                                                           calibratedModel.GetK(), calibratedModel.GetTheta(), calibratedModel.GetSigma(), calibratedModel.GetRho(), calibratedModel.GetNv())));
            /*foreach (CalibrationOutcome MinimizerStatus in sss)*/
            /*object[,] ansTable =*/
        }