Exemplo n.º 1
0
        private double GetFirstDerivativeToStrike(double t, double k)
        {
            double forwardPrice  = PriceBump.BumpForward(k);
            double backwardPrice = PriceBump.BumpBackward(k);

            return((ImpliedVol.GetValue(t, forwardPrice) - ImpliedVol.GetValue(t, backwardPrice)) / (forwardPrice - backwardPrice));
        }
Exemplo n.º 2
0
        // below three functions assume time t and strike k is in good region
        private double GetFirstDerivativeToTime(double t, double k)
        {
            double forwardTime  = TimeBump.BumpForward(t);
            double backwardTime = TimeBump.BumpBackward(t);

            return((ImpliedVol.GetValue(forwardTime, k) - ImpliedVol.GetValue(backwardTime, k)) / (forwardTime - backwardTime));
        }
Exemplo n.º 3
0
        private double GetSecondDerivativeToStrike(double t, double k)
        {
            // there is possibility that the bump sizes are different between forward and backward.
            // we use the minimum of them to calculate the second order derivative.
            double bumpsize = PriceBump.MinBump(k);

            return((ImpliedVol.GetValue(t, k + bumpsize) + ImpliedVol.GetValue(t, k - bumpsize) - 2 * ImpliedVol.GetValue(t, k)) /
                   (bumpsize * bumpsize));
        }
Exemplo n.º 4
0
        private double GetLocalVolFromImpliedVol(double t, double k)
        {
            var forwardPrice   = ImpliedVol.GetForwardPrice(t);
            var sigmaImpl      = ImpliedVol.GetValue(t, k);
            var firstOrderToT  = GetFirstDerivativeToTime(t, k);
            var firstOrderToK  = GetFirstDerivativeToStrike(t, k);
            var secondOrderToK = GetSecondDerivativeToStrike(t, k);
            var d1             = (Math.Log(forwardPrice / k) + 0.5 * sigmaImpl * sigmaImpl * t) / (sigmaImpl * Math.Sqrt(t));
            var sigmaLSquare   = (Math.Pow(sigmaImpl, 2) + 2 * sigmaImpl * t * firstOrderToT) /
                                 (Math.Pow((1 + d1 * Math.Sqrt(t) * k * firstOrderToK), 2) +
                                  sigmaImpl * t * k * k * (secondOrderToK - d1 * Math.Sqrt(t) * Math.Pow(firstOrderToK, 2)));

            return(sigmaLSquare >= 0
                                ? Math.Sqrt(sigmaLSquare)
                                : 0.0);
        }