Exemplo n.º 1
0
        /// <summary>
        /// Price of a swaption in HW1 model: the holder has the right to pay
        /// the fixed rate and receive floating rate.
        /// This is a different version of the main one to do a double check of the swaption.
        /// </summary>
        /// <param name='a'>
        /// Hull-White alpha parameter.
        /// </param>
        /// <param name='sigma'>
        /// Hull-White sigma parameter.
        /// </param>
        /// <param name='l'>
        /// The Notional.
        /// </param>
        /// <param name='k'>
        /// The Strike.
        /// </param>
        /// <param name='T'>
        /// The maturity.
        /// </param>
        /// <param name='s'>
        /// Vector of swaption payment dates.
        /// </param>
        /// <returns>
        /// The swaptions price.
        /// </returns>
        public double HWSwaption(double a, double sigma, double l, double k, double T, Vector s)
        {
            OptimizationSettings options = new OptimizationSettings();
            options.epsilon = 1e-10;

            this.dt = s[0] - T;
            this.CF = k * this.dt + (new Vector(s.Length));
            this.CF[s.Length - 1] = this.CF[s.Length - 1] + 1;
            this.a = a;
            this.sigma = sigma;
            this.t = T;
            this.T = s;
            this.L = l;
            SolutionInfo sol = Fairmat.Optimization.Helper.FSolve(new ObjFunction(this.Func), (Vector)new double[1] { 0.01 },
                (Vector)new double[1] { -1.0 }, (Vector)new double[1] { 1.0 }, options);
            double RK = (double)sol.x;

            Vector X = this.HWBond(a, sigma, RK, this.T, this.t);
            double result = 0;
            for (int i = 0; i < s.Length; i++)
                result += this.CF[i] * this.ZCBPut(a, sigma, 1.0, X[i], T, s[i]);
            result = result * l;
            return result;
        }