Пример #1
0
 public static void BlackScholesNoReset(ADouble vol, ADouble spot, ADouble rate, ADouble time, ADouble mat, ADouble strike)
 {
     ADouble Help1 = vol * ADouble.Sqrt(mat - time);
     ADouble d1    = 1.0 / Help1 * (ADouble.Log(spot / strike) + (rate + 0.5 * ADouble.Pow(vol, 2)) * (mat - time));
     ADouble d2    = d1 - vol * ADouble.Sqrt(mat - time);
     ADouble Out   = MyMath.NormalCdf(d1) * spot - strike * ADouble.Exp(-rate * (mat - time)) * MyMath.NormalCdf(d2);
 }
Пример #2
0
        public static void FuncExp(ADouble x)
        {
            AADTape.ResetTape();
            AADTape.Initialize(new ADouble[] { x });

            // Derivative: Fx(x) = 3 + 3*exp(3*x)

            ADouble Temp = 3.0 * x + ADouble.Exp(3.0 * x) + 50.0;

            AADTape.InterpretTape();
            AADTape.PrintTape();
            AADTape.ResetTape();
        }
Пример #3
0
        public static void BlackScholes(ADouble vol, ADouble spot, ADouble rate, ADouble time, ADouble mat, ADouble strike)
        {
            AADTape.ResetTape();
            AADTape.Initialize(new ADouble[] { vol, spot, rate, time, mat, strike });

            ADouble Help1 = vol * ADouble.Sqrt(mat - time);
            ADouble d1    = 1.0 / Help1 * (ADouble.Log(spot / strike) + (rate + 0.5 * ADouble.Pow(vol, 2)) * (mat - time));
            ADouble d2    = d1 - vol * ADouble.Sqrt(mat - time);
            ADouble Out   = MyMath.NormalCdf(d1) * spot - strike * ADouble.Exp(-rate * (mat - time)) * MyMath.NormalCdf(d2);

            Console.WriteLine("");
            Console.WriteLine("BLACK-SCHOLES TEST. Value: " + Out.Value);
            AADTape.InterpretTape();
            AADTape.PrintTape();
            AADTape.ResetTape();
        }
Пример #4
0
        public static ADouble NormalCdf(ADouble x)
        {
            // Courtesy of Antoine Savine (Danske Bank)
            if (x < -10.0)
            {
                return(0.0);
            }
            else if (x > 10.0)
            {
                return(1.0);
            }
            if (x < 0.0)
            {
                return(1.0 - NormalCdf(-x));
            }

            // Constants
            double p  = 0.2316419;
            double b1 = 0.319381530;
            double b2 = -0.356563782;
            double b3 = 1.781477937;
            double b4 = -1.821255978;
            double b5 = 1.330274429;

            // Transform
            ADouble t   = 1.0 / (1.0 + p * x);
            ADouble pol = t * (b1 + t * (b2 + t * (b3 + t * (b4 + t * b5))));
            ADouble pdf = 0.0;

            if (x < -10.0 || 10.0 < x)
            {
                pdf = 0.0;
            }
            else
            {
                pdf = ADouble.Exp(-0.5 * x * x) / MyMathConstants.SqrtTwoPi;
            }

            return(1.0 - pdf * pol);
        }
Пример #5
0
 public ADouble DiscFactor(DateTime asOf, DateTime date, DayCount dayCount, InterpMethod interpolation)
 {
     return(ADouble.Exp(-1.0 * ZeroRate(date, interpolation) * DateHandling.Cvg(asOf, date, dayCount)));
 }