public static object LocalVolDenominator(object mktObj, object[] dates, double[] strikes, string assetName) { return(FunctionRunnerUtils.Run("LocalVolSurface", () => { Market market = MarketManager.Instance.GetMarket(mktObj); AssetMarket assetMarket = market.AssetMarketFromName(assetName); VolatilitySurface volSurface = assetMarket.VolSurface(); var localVariance = volSurface.LocalVariance; var moneyness = volSurface.Moneyness; var time = volSurface.Time; var result = new double[dates.Length, strikes.Length]; for (int i = 0; i < dates.Length; i++) { var date = ObjectConverters.ConvertDate(dates[i], assetMarket.RefDate); double t = time[date]; var denomFunc = localVariance.Denominator(t); var denoms = strikes.Map(k => { var y = moneyness.Moneyness(t, k); return denomFunc.Eval(y); }); ArrayUtils.SetRow(ref result, i, denoms); } return result; })); }
public static object EquityImpliedVol(object mktObj, string assetName, object maturity, double strike, double price, string optionType) { return(FunctionRunnerUtils.Run("EquityImpliedVol", () => { Market market = MarketManager.Instance.GetMarket(mktObj); AssetMarket assetMkt = market.AssetMarketFromName(assetName); var pricer = BlackScholesWithDividendOption.Build(assetMkt.Spot, assetMkt.Dividends, assetMkt.RiskFreeDiscount, assetMkt.Time); double q; switch (optionType.Trim().ToLower()) { case "call": q = 1.0; break; case "put": q = -1.0; break; default: throw new Exception(string.Format("Unknow option type : {0}", optionType)); } var matAsDate = ObjectConverters.ConvertDate(maturity, assetMkt.RefDate); return pricer.ImpliedVol(assetMkt.Time[matAsDate], strike, price, q); })); }