/// <summary> /// /// </summary> /// <param name="style"></param> /// <param name="spot"></param> /// <param name="strike"></param> /// <param name="vol"></param> /// <param name="today"></param> /// <param name="expiry"></param> /// <param name="paystyle"></param> /// <param name="zeroDates"></param> /// <param name="zeroRates"></param> /// <param name="divDates"></param> /// <param name="divAms"></param> /// <param name="gridsteps"></param> /// <param name="smoo"></param> /// <param name="flatFlag"></param> /// <returns></returns> public static double[,] BinomialRelativeGetGreeks(string style, double spot, double strike, double vol, DateTime today, DateTime expiry, string paystyle, DateTime[] zeroDates, double[] zeroRates, DateTime[] divDates, double[] divAms, double gridsteps, string smoo, bool flatFlag) { const int arrsize = 4; gridsteps = (gridsteps == 0.0) ? 20 : gridsteps; int nGridsteps = Convert.ToInt32(gridsteps); string smoothing = (smoo.ToLower().Equals("n")) ? "n" : "y"; var retArray = new double[arrsize, arrsize]; double t = expiry.Subtract(today).Days / 365.0; ZeroCurve myZero = (new Wrapper()).UnpackZero(today, zeroDates, zeroRates); DivList myDiv = (new Wrapper()).UnpackDiv(today, expiry, divDates, divAms); //create the tree var myTree = new PropTree(t, vol, spot, nGridsteps, true) { Gridsteps = nGridsteps }; myTree.MakeGrid(myZero, myDiv); //create pricer var myPrice = new Pricer(strike, paystyle, smoothing, style); myPrice.MakeGrid(myTree); myPrice.Price(); var myGreeks = new Greeks(); myGreeks.MakeDeltaGamma(myTree, myPrice, myZero, myDiv); double delta = myGreeks.Delta; double gamma = myGreeks.Gamma; myGreeks.MakeVega(myTree, myPrice, myZero, myDiv); double vega = myGreeks.Vega; myGreeks.MakeTheta(myTree, myPrice, myZero, myDiv); double theta = myGreeks.Theta; retArray[0, 0] = delta; retArray[0, 1] = gamma; retArray[0, 2] = vega; retArray[0, 3] = theta; return(retArray); }
/// <summary> /// /// </summary> /// <param name="style"></param> /// <param name="spot"></param> /// <param name="strike"></param> /// <param name="vol"></param> /// <param name="today"></param> /// <param name="expiry"></param> /// <param name="paystyle"></param> /// <param name="zeroDates"></param> /// <param name="zeroRates"></param> /// <param name="divDates"></param> /// <param name="divAms"></param> /// <param name="gridsteps"></param> /// <param name="smoo"></param> /// <param name="flatFlag"></param> /// <returns></returns> public static double BinomialRelativePricer(string style, double spot, double strike, double vol, DateTime today, DateTime expiry, string paystyle, DateTime[] zeroDates, double[] zeroRates, DateTime[] divDates, double[] divAms, double gridsteps, string smoo, bool flatFlag) { gridsteps = (gridsteps == 0.0) ? 20 : gridsteps; int nGridsteps = Convert.ToInt32(gridsteps); string smoothing = (smoo.ToLower().Equals("n")) ? "n" : "y"; double t = expiry.Subtract(today).Days / 365.0; var wrapper = new Wrapper(); ZeroCurve myZero = wrapper.UnpackZero(today, zeroDates, zeroRates); DivList myDiv = wrapper.UnpackDiv(today, expiry, divDates, divAms); //create the tree var myTree = new PropTree(t, vol, spot, nGridsteps, true); myTree.MakeGrid(myZero, myDiv); //create pricer var myPrice = new Pricer(strike, paystyle, smoothing, style); myPrice.MakeGrid(myTree); double pr = myPrice.Price(); return(pr); }