public static double MonteCarloPriceAndGreeks(this AsianOption option, Date valueDate, double spot, double vol, double rate, double div, OptionPriceandGreeks greek, int periods, int numOfSims = 100000) { var T = (double)(option._exerciseDate - valueDate) / 365; var flag = (double)option._putOrCall; double bump = 0.01; var paths = GBMEquitySimulator.StockPathSimulator(spot, vol, div, rate, T, numOfSims, periods, bump); var stockpaths = paths[0]; var stockpaths_up = paths[1]; var stockpaths_down = paths[2]; double value = Double.NaN; // To do : create monte carlo vega, theta, and rho if (greek == OptionPriceandGreeks.Price) { value = MonteCarloPrice(stockpaths, option._strike, flag, rate, T); } else if (greek == OptionPriceandGreeks.Delta) { value = (MonteCarloPrice(stockpaths_up, option._strike, flag, rate, T) - MonteCarloPrice(stockpaths, option._strike, flag, rate, T)) / bump; } else if (greek == OptionPriceandGreeks.Gamma) { value = (MonteCarloPrice(stockpaths_up, option._strike, flag, rate, T) - 2 * MonteCarloPrice(stockpaths, option._strike, flag, rate, T) + MonteCarloPrice(stockpaths_down, option._strike, flag, rate, T)) / (bump * bump); } return(value); }
public static double BlackScholesPriceAndGreeks(this EuropeanOption option, Date valueDate, double spot, double vol, double rate, double div, OptionPriceandGreeks greek) { double value = Double.NaN; if (greek == OptionPriceandGreeks.Price) { value = BlackScholesPrice(option, valueDate, spot, vol, rate, div); } else if (greek == OptionPriceandGreeks.Delta) { value = BlackScholesDelta(option, valueDate, spot, vol, rate, div); } else if (greek == OptionPriceandGreeks.Gamma) { value = BlackScholesGamma(option, valueDate, spot, vol, rate, div); } else if (greek == OptionPriceandGreeks.Vega) { value = BlackScholesVega(option, valueDate, spot, vol, rate, div); } else if (greek == OptionPriceandGreeks.Theta) { value = BlackScholesTheta(option, valueDate, spot, vol, rate, div); } else if (greek == OptionPriceandGreeks.Rho) { value = BlackScholesRho(option, valueDate, spot, vol, rate, div); } return(value); }