public override double PutPrice() { double tmp = sig * Math.Sqrt(T); double d1 = (Math.Log(U / K) + (b + (sig * sig) * 0.5) * T) / tmp; double d2 = d1 - tmp; return((K * Math.Exp(-r * T) * SpecialFunctions.N(-d2)) - (U * Math.Exp((b - r) * T) * SpecialFunctions.N(-d1))); }
public override double CallPrice() { double pf = Math.Exp(-r * (S - T)); double tmp = sig * Math.Sqrt(T); double d1 = (Math.Log(pf / K) + (b + (sig * sig) * 0.5) * T) / tmp; double d2 = d1 - tmp; double callPrice = Math.Exp(-r * T) * ((pf * SpecialFunctions.N(d1)) - (K * SpecialFunctions.N(d2))); return(callPrice); }
public static void RunExercise1() { double nan = 0.0f / 0.0f; if (double.IsInfinity(nan) || double.IsNaN(nan)) { //It is faster to NOT try to calculate CDN, rather than trying, waiting for an exception to be thrown, and having to handle it. Console.WriteLine("The number supplied to calcualte the CND is not valid."); } else { double d = SpecialFunctions.N(nan); } }