Пример #1
0
        public static double BachelierCallPrice(double spot, double lambda, double mat, double strike)
        {
            double d         = (spot - strike) / (lambda * Math.Sqrt(mat));
            double NormalPdf = 1.0; // calculate this

            return(MyMath.NormalCdf(d) * (spot - strike) + lambda * Math.Sqrt(mat) * NormalPdf);
        }
Пример #2
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);
 }
Пример #3
0
        public static double BsCallPrice(double spot, double vol, double mat, double strike, double rate)
        {
            double std     = Math.Sqrt(mat) * vol;
            double halfVar = (rate + vol * vol * 0.5) * mat;
            double d1      = (Math.Log(spot / strike) + halfVar) / std;
            double d2      = d1 - std;

            return(spot * MyMath.NormalCdf(d1) - strike * MyMath.NormalCdf(d2) * Math.Exp(-rate * mat));
        }
Пример #4
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();
        }