public void GetCalibrationStatus(ref CalibrationOutcome calibOutcome, ref double pricingError)
        {
            calibOutcome = outcome;
            VasicekModel m = new VasicekModel(r0, calibratedParams);

            pricingError = CalcMeanSquareErrorBetweenModelAndMarket(m);
        }
        // Calculate difference between observed and model prices
        public double CalcMeanSquareErrorBetweenModelAndMarket(VasicekModel m)
        {
            double meanSqErr = 0;

            foreach (ZCBCallOptionMarketData option in marketOptionsList)
            {
                double bondMaturity   = option.bondMaturity;
                double optionExercise = option.optionExercise;
                double strike         = option.strike;
                double modelPrice     = m.PriceZCBCall(optionExercise, strike, bondMaturity);

                double difference = modelPrice - option.marketMidPrice;
                meanSqErr += difference * difference;
            }
            return(meanSqErr);
        }
        public void SetGuessParameters(double k, double theta, double sigma)
        {
            VasicekModel m = new VasicekModel(r0, k, theta, sigma);

            calibratedParams = m.ConvertVasicekModeCalibrationParamsToArray();
        }
        public VasicekModel GetCalibratedModel()
        {
            VasicekModel m = new VasicekModel(r0, calibratedParams);

            return(m);
        }
        // Used by Alglib minimisation algorithm
        public void CalibrationObjectiveFunction(double[] paramsArray, ref double func, object obj)
        {
            VasicekModel m = new VasicekModel(r0, paramsArray);

            func = CalcMeanSquareErrorBetweenModelAndMarket(m);
        }
Example #6
0
        public static double VasicekZCBPrice(double maturity, double r0, double k, double theta, double sigma)
        {
            VasicekModel m = new VasicekModel(r0, k, theta, sigma);

            return(m.PriceZCB(maturity));
        }
Example #7
0
        public static object[,] CalibrateVasicekParameters(
            double kGuess,
            double thetaGuess,
            double sigmaGuess,
            double r0,
            double[] strikesArray,
            double[] bondMaturitiesArray,
            double[] optionExerciseTimesArray,
            double[] observedPricesArray,
            double accuracy,
            int maxIterations)
        {
            if (strikesArray.Length != bondMaturitiesArray.Length ||
                bondMaturitiesArray.Length != optionExerciseTimesArray.Length ||
                optionExerciseTimesArray.Length != observedPricesArray.Length)
            {
                throw new ArgumentException("CalibrateVasicekParameters: strikes, optionExerciseTimes, bondMaturities and observedPrices must be of same length.");
            }

            VasicekCalibrator vasicekCalibrator = new VasicekCalibrator(r0, accuracy, maxIterations);

            vasicekCalibrator.SetGuessParameters(kGuess, thetaGuess, sigmaGuess);

            int numObservedOptions = strikesArray.Length;

            for (int optionIdx = 0; optionIdx < numObservedOptions; ++optionIdx)
            {
                vasicekCalibrator.AddObservedOption(bondMaturitiesArray[optionIdx],
                                                    optionExerciseTimesArray[optionIdx],
                                                    strikesArray[optionIdx],
                                                    observedPricesArray[optionIdx]);
            }
            vasicekCalibrator.Calibrate();
            CalibrationOutcome outcome          = CalibrationOutcome.NotStarted;
            double             calibrationError = 0;

            vasicekCalibrator.GetCalibrationStatus(ref outcome, ref calibrationError);

            VasicekModel calibratedModel = vasicekCalibrator.GetCalibratedModel();

            // for output
            const int numCols = 2;
            const int numRows = 5;

            object[,] output = new object[numRows, numCols];
            output[0, 0]     = "k"; output[0, 1] = calibratedModel.GetK();
            output[1, 0]     = "theta"; output[1, 1] = calibratedModel.GetTheta();
            output[2, 0]     = "sigma"; output[2, 1] = calibratedModel.GetSigma();
            output[3, 0]     = "Minimizer Status";
            if (outcome == CalibrationOutcome.FinishedOK)
            {
                output[3, 1] = "OK";
            }
            else if (outcome == CalibrationOutcome.FailedMaxItReached)
            {
                output[3, 1] = "Reached max. num. iterations.";
            }
            else if (outcome == CalibrationOutcome.FailedOtherReason)
            {
                output[3, 1] = "Failed.";
            }
            else
            {
                output[3, 1] = "Unknown outcome.";
            }
            {
                output[4, 0] = "Pricing error"; output[4, 1] = Math.Sqrt(calibrationError);
            }
            return(output);
        }
Example #8
0
        public static double VasicekZCBCallPrice(double bondMaturity, double optionExercise, double strike, double r0, double k, double theta, double sigma)
        {
            VasicekModel m = new VasicekModel(r0, k, theta, sigma);

            return(m.PriceZCBCall(optionExercise, strike, bondMaturity));
        }
Example #9
0
 public VasicekModel(VasicekModel otherModel) :
     this(otherModel.r0, otherModel.k, otherModel.theta, otherModel.sigma)
 {
 }
 public VasicekModel(VasicekModel otherModel)
 {
     r0 = otherModel.r0; k = otherModel.k; theta = otherModel.theta; sigma = otherModel.sigma;
 }