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); }
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(); }