private static void FutureOptionPrice(DataForFutureOptionPrices data, double[] callSigma, double[] putSigma, double spotPrice, double interestRate, out double[] callPrice, out double[] putPrice) { int arrayLength = data.DaysToExpiry.Length; int priceArrysLength = data.DaysToExpiry[arrayLength - 1]; callPrice = new double[priceArrysLength]; putPrice = new double[priceArrysLength]; for (int i = 0; i < arrayLength; i++) { int de = data.DaysToExpiry[i]; callPrice[de - 1] = new BlackScholesModel(de, spotPrice, interestRate, spotPrice, 0, 0, 0, LegType.Call).GetEuroPrice(callSigma[i]); putPrice[de - 1] = new BlackScholesModel(de, spotPrice, interestRate, spotPrice, 0, 0, 0, LegType.Put).GetEuroPrice(putSigma[i]); } int firstExpiry = data.DaysToExpiry[0]; for (int i = 0; i < firstExpiry - 1; i++) { callPrice[i] = (i + 1) * callPrice[firstExpiry - 1] / firstExpiry; putPrice[i] = (i + 1) * putPrice[firstExpiry - 1] / firstExpiry; } for (int i = 0; i < arrayLength - 1; i++) { int currExp = data.DaysToExpiry[i]; int nextExp = data.DaysToExpiry[i + 1]; for (int j = currExp; j < nextExp - 1; j++) { callPrice[j] = DoLinearInterpolation(currExp, nextExp, callPrice[currExp - 1], callPrice[nextExp - 1], j + 1); putPrice[j] = DoLinearInterpolation(currExp, nextExp, putPrice[currExp - 1], putPrice[nextExp - 1], j + 1); } } }
public static Greeks GetGreeks(double daysToExpiry /*T-t, maturity*/, double strike /*K*/, double interestRate /*r*/, double spotPrice /*S*/, double ask, double bid, double lastPrice, LegType callOrPut, double?divYield = null) { if (divYield == null) { divYield = 0; } BlackScholesModel bsm = new BlackScholesModel(daysToExpiry, strike, interestRate, spotPrice, ask, bid, lastPrice, callOrPut, divYield); Greeks greeks = new Greeks(); greeks.Delta = bsm.EuroDelta; greeks.Gamma = bsm.EuroGamma; greeks.Theta = bsm.EuroTheta; greeks.Sigma = bsm.Sigma; greeks.Rho = bsm.EuroRho; greeks.RhoFx = bsm.EuroRhoFx; greeks.Vega = bsm.EuroVega; return(greeks); }