Ejemplo n.º 1
0
        public static void TestVasicekCalibration()
        {
            double r0    = 0.01;
            double k     = 0.5;
            double theta = 0.01;
            double sigma = 0.2;

            VasicekModel model = new VasicekModel(r0, k, theta, sigma);

            double[] bondMaturities      = new double[] { 1, 2, 10 };
            double[] optionExerciseTimes = new double[] { 0.5, 1, 2 };
            double[] optionStrikes       = new double[] { 0.9, 0.9, 0.9 };
            double[] prices = new double[bondMaturities.Length];
            //Console.WriteLine("European call options on ZCBs, prices");
            for (int i = 0; i < bondMaturities.Length; ++i)
            {
                double T = bondMaturities[i], S = optionExerciseTimes[i], K = optionStrikes[i];
                //prices[i] = model.PriceZCBCall(S, K, T);
                prices[i] = 0.05;
            }

            VasicekCalibrator calibrator = new VasicekCalibrator(r0, 1e-15, 2000);

            for (int i = 0; i < bondMaturities.Length; ++i)
            {
                calibrator.AddObservedOption(bondMaturities[i], optionExerciseTimes[i], optionStrikes[i], prices[i]);
            }
            calibrator.Calibrate();
            double             error   = 0;
            CalibrationOutcome outcome = CalibrationOutcome.NotStarted;

            calibrator.GetCalibrationStatus(ref outcome, ref error);
            Console.WriteLine("Calibration outcome: {0} and error: {1}", outcome, error);
        }
Ejemplo n.º 2
0
        public static void TestVasicekCalibration()
        {
            double r0    = 0.01;
            double k     = 0.5;
            double theta = 0.01;
            double sigma = 0.2;

            VasicekModel model = new VasicekModel(r0, k, theta, sigma);

            double[] bondMaturities      = new double[] { 1, 2, 10 };
            double[] optionExerciseTimes = new double[] { 0.5, 1, 2 };
            double[] optionStrikes       = new double[] { 0.9, 0.9, 0.9 };
            double[] prices = new double[bondMaturities.Length];
            //Console.WriteLine("European call options on ZCBs, prices");
            for (int i = 0; i < bondMaturities.Length; ++i)
            {
                double T = bondMaturities[i], S = optionExerciseTimes[i], K = optionStrikes[i];
                prices[i] = model.PriceZCBCall(S, K, T);
            }

            VasicekCalibrator calibrator = new VasicekCalibrator(r0, 1e-20, 2000);

            for (int i = 0; i < bondMaturities.Length; ++i)
            {
                // Here you should add the market data to the vasicekCalibrator...
                // .. for that you will need to modify the calibrator appropriately
                // e.g. add an AddObservedOption method to the VasicekCalibrator as follows
                //calibrator.AddObservedOption(bondMaturities[i], optionExerciseTimes[i], optionStrikes[i], prices[i]);
                throw new NotImplementedException("Method not implemented... that's part of the exercise.");
            }
            calibrator.Calibrate();
            double             error   = 0;
            CalibrationOutcome outcome = CalibrationOutcome.NotStarted;

            calibrator.GetCalibrationStatus(ref outcome, ref error);
            Console.WriteLine("Calibration outcome: {0} and error: {1}", outcome, error);
        }