public double CashBpvAverage(double start, double end)
 {
     if (end > start)
     {
         return((cashBpvIntegral.Eval(end) - cashBpvIntegral.Eval(start)) / (end - start));
     }
     return(cashBpvIntegral.Eval(start));
 }
        public override RnRFunction Zc(DateTime date, DateTime maturity, double fwdZc)
        {
            Contract.Requires(date <= maturity);
            double d     = time[date];
            var    drift = driftTerm.Eval(d);

            return(HwModelUtils.ZcFunction(time[maturity] - d, fwdZc, new[] { meanReversion }, new[, ] {
                { drift }
            }));
        }
Ejemplo n.º 3
0
        private static Func <double, double> StepLocalVol(DateTime startDate, DateTime endDate, LocalVolatilityModel model)
        {
            var    time  = model.Time;
            double start = time[startDate];
            double end   = time[endDate];

            VolatilitySurface volSurface        = model.VolSurface;
            RrFunction        stepLocalVariance = volSurface.LocalVariance.TimeAveragedSlice(start, end);
            var moneyness = model.Moneyness.Moneyness(start);
            Func <double, double> localVol = logSpot => Math.Sqrt(stepLocalVariance.Eval(moneyness(Math.Exp(logSpot))));

            var gridLocalVol = LocalVolDiscretization(localVol, volSurface, 0.5 * (start + end));

            return(gridLocalVol.Eval);
        }
Ejemplo n.º 4
0
        public double Eval(double t, double y)
        {
            var    stepIndex = maturityStepSearcher.LocateLeftIndex(t);
            double v, dVdY, d2Vd2Y, dVdT;

            if (stepIndex < 0)
            {
                double w = t / maturities[0];

                if (Math.Abs(w) < 1.0e-10)
                {
                    return(shortLocalVar.Eval(y));
                }

                v      = w * vs[0].Eval(y);
                dVdY   = w * dVdYs[0].Eval(y);
                d2Vd2Y = w * d2Vd2Ys[0].Eval(y);
                dVdT   = vs[0].Eval(y) / maturities[0];
            }
            else if (stepIndex == maturities.Length - 1)
            {
                double w = t / maturities[maturities.Length - 1];
                v      = vs[stepIndex].Eval(y) * w;
                dVdY   = dVdYs[stepIndex].Eval(y) * w;
                d2Vd2Y = d2Vd2Ys[stepIndex].Eval(y) * w;
                dVdT   = dVdTs[stepIndex].Eval(y);
            }
            else
            {
                double w = (t - maturities[stepIndex]) / (maturities[stepIndex + 1] - maturities[stepIndex]);
                v      = (1.0 - w) * vs[stepIndex].Eval(y) + w * vs[stepIndex + 1].Eval(y);
                dVdY   = (1.0 - w) * dVdYs[stepIndex].Eval(y) + w * dVdYs[stepIndex + 1].Eval(y);
                d2Vd2Y = (1.0 - w) * d2Vd2Ys[stepIndex].Eval(y) + w * d2Vd2Ys[stepIndex + 1].Eval(y);
                dVdT   = dVdTs[stepIndex].Eval(y);
            }

            //                                                  dv/dt
            // local variance = ------------------------------------------------------------------------------------
            //                   (y * (dv/dy) / (2 * v) - 1)^2 + 1/2 * (d^2 v/dy^2) - 1/4 * (1/4 + 1/v) * (dv/dy)^2

            double localVar = 0.5 * y * dVdY / v - 1.0;

            localVar = localVar * localVar + 0.5 * d2Vd2Y - 0.25 * (0.25 + 1.0 / v) * dVdY * dVdY;
            localVar = dVdT / localVar;
            return(localVar);
        }
Ejemplo n.º 5
0
 public override double Zc(double d)
 {
     return Math.Exp(-zcRate.Eval(d) * d);
 }