예제 #1
0
        //now we figure out the difference
        /// <summary>
        /// calculate the mean square error
        /// </summary>
        /// <param name="m">the array contained the parameters</param>
        /// <returns></returns>
        public double CalcMeanSquareErrorBetweenModelAndMarket(Hestonformula m)
        {
            double meanSqErr = 0;

            foreach (HMCallOptionMarketData option in marketOptionsList)
            {
                double optionExercise = option.optionExercise;
                double strike         = option.strike;
                double modelPrice     = m.CalculateCallOptionPrice(S, strike, r, optionExercise);
                double difference     = modelPrice - option.marketMidPrice;
                meanSqErr += difference * difference;
            }
            return(meanSqErr);
        }
예제 #2
0
        //now we figure out the difference
        /// <summary>
        /// calculate the mean square error
        /// </summary>
        /// <param name="m">the array contained the parameters</param>
        /// <returns>the mean square error between Model and Market</returns>
        public double CalcMeanSquareErrorBetweenModelAndMarket(Hestonformula m)
        {
            double meanSqErr = 0;

            foreach (HMCallOptionMarketData option in marketOptionsList)
            {
                calibratedParams[0] = nv;
                calibratedParams[1] = k;
                calibratedParams[2] = theta;
                calibratedParams[3] = rho;
                calibratedParams[4] = sigma;
                double optionExercise = option.optionExercise;
                double strike         = option.strike;
                double modelPrice     = m.CalculateCallOptionPrice(S, strike, r, optionExercise);
                double difference     = modelPrice - option.marketMidPrice;
                meanSqErr += difference * difference;
            }
            return(meanSqErr);
        }
예제 #3
0
        /// <summary>
        /// Price a European option in the Heston model using the Heston formula. This should be accurate to 5 decimal places
        /// </summary>
        /// <param name="parameters">Object implementing IHestonModelParameters interface, containing model parameters.</param>
        /// <param name="europeanOption">Object implementing IEuropeanOption interface, containing the option parameters.</param>
        /// <returns>Option price</returns>
        public static double HestonEuropeanOptionPrice(IHestonModelParameters parameters,
                                                       IEuropeanOption europeanOption)
        {
            Hestonformula r1 = new Hestonformula(parameters.VarianceParameters.V0,
                                                 parameters.VarianceParameters.Kappa,
                                                 parameters.VarianceParameters.Theta,
                                                 parameters.VarianceParameters.Rho,
                                                 parameters.VarianceParameters.Sigma);

            if (europeanOption.Type == PayoffType.Call)
            {
                return(Math.Round(r1.CalculateCallOptionPrice(parameters.InitialStockPrice,
                                                              europeanOption.StrikePrice,
                                                              parameters.RiskFreeRate,
                                                              europeanOption.Maturity), 5));
            }
            else
            {
                return(Math.Round(r1.CalculatePutOptionPrice(parameters.InitialStockPrice,
                                                             europeanOption.StrikePrice,
                                                             parameters.RiskFreeRate,
                                                             europeanOption.Maturity), 5));
            }
        }