public static RiskyFlySurface GetSurfaceForCode(string nymexSymbol, string nymexOptionFilename, string qwackCode, BasicPriceCurve priceCurve, ICalendarProvider calendarProvider, ICurrencyProvider currency, IFutureSettingsProvider futureSettingsProvider) { var parsed = NYMEXOptionParser.Instance.Parse(nymexOptionFilename).Where(r => r.Symbol == nymexSymbol); var(optionExerciseType, optionMarginingType) = OptionTypeFromCode(nymexSymbol); var origin = DateTime.ParseExact(parsed.First().TradeDate, "MM/dd/yyyy", CultureInfo.InvariantCulture); var q = parsed.Where(x => x.Settle > 0).Select(x => new ListedOptionSettlementRecord { CallPut = x.PutCall == "C"?OptionType.C:OptionType.P, ExerciseType = optionExerciseType, MarginType = optionMarginingType, PV = x.Settle, Strike = x.Strike, UnderlyingFuturesCode = Year2to1(x.Contract.Split(' ')[0].Replace(nymexSymbol, qwackCode)), ExpiryDate = OptionExpiryFromNymexRecord(x, calendarProvider), ValDate = origin }).Where(z => z.ExpiryDate > origin).ToList(); var priceDict = priceCurve.PillarLabels.ToDictionary(x => x, x => priceCurve.GetPriceForDate(priceCurve.PillarDatesForLabel(x))); ListedSurfaceHelper.ImplyVols(q, priceDict, new ConstantRateIrCurve(0.0, origin, "dummy", currency.GetCurrency("USD"))); var smiles = ListedSurfaceHelper.ToDeltaSmiles(q, priceDict); var allOptionExpiries = new List <DateTime>(); var lastDate = q.Max(x => x.ExpiryDate); var dummyFutureCode = $"{qwackCode}Z{DateExtensions.SingleDigitYear(DateTime.Today.Year + 2)}"; var c = new FutureCode(dummyFutureCode, DateTime.Today.Year - 2, futureSettingsProvider); var contract = c.GetFrontMonth(origin, false); var lastContract = c.GetFrontMonth(lastDate, false); while (contract != lastContract) { var cc = new FutureCode(contract, origin.Year, futureSettingsProvider); var exp = ListedUtils.FuturesCodeToDateTime(contract); var record = new NYMEXOptionRecord { ContractMonth = exp.Month, ContractYear = exp.Year, Symbol = nymexSymbol }; var optExpiry = OptionExpiryFromNymexRecord(record, calendarProvider); if (optExpiry > origin) { allOptionExpiries.Add(optExpiry); } contract = cc.GetNextCode(false); } var surface = ListedSurfaceHelper.ToRiskyFlySurfaceStepFlat(smiles, origin, priceCurve, allOptionExpiries, currency); return(surface); }
public static RiskyFlySurface GetFxSurfaceForCode(string cmeSymbol, string cmeFutureFilename, BasicPriceCurve priceCurve, ICurrencyProvider currency) { var parsed = CMEFileParser.Instance.Parse(cmeFutureFilename).Where(r => r.Sym == cmeSymbol && r.SecTyp == "OOF" && r.SettlePrice.HasValue); var(optionExerciseType, optionMarginingType) = OptionTypeFromCode(cmeSymbol); var origin = DateTime.ParseExact(parsed.First().BizDt, "yyyy-MM-dd", CultureInfo.InvariantCulture); var q = parsed.Where(x => x.SettlePrice > 0).Select(x => new ListedOptionSettlementRecord { CallPut = x.PutCall == 1 ? OptionType.C : OptionType.P, ExerciseType = optionExerciseType, MarginType = optionMarginingType, PV = x.SettlePrice.Value, Strike = x.StrkPx.Value, UnderlyingFuturesCode = x.UndlyMMY, ExpiryDate = DateTime.ParseExact(x.MatDt, "yyyy-MM-dd", CultureInfo.InvariantCulture), ValDate = origin }).Where(z => z.ExpiryDate > origin).ToList(); var priceDict = priceCurve.PillarLabels.ToDictionary(x => x, x => priceCurve.GetPriceForDate(priceCurve.PillarDatesForLabel(x))); ListedSurfaceHelper.ImplyVols(q, priceDict, new ConstantRateIrCurve(0.0, origin, "dummy", currency.GetCurrency("USD"))); var smiles = ListedSurfaceHelper.ToDeltaSmiles(q, priceDict); var expiries = smiles.Keys.OrderBy(x => x).ToArray(); var ulByExpiry = expiries.ToDictionary(x => x, x => q.Where(qq => qq.ExpiryDate == x).First().UnderlyingFuturesCode); var fwdByExpiry = ulByExpiry.ToDictionary(x => x.Key, x => priceCurve.GetPriceForDate(priceCurve.PillarDatesForLabel(x.Value))); var fwds = expiries.Select(e => fwdByExpiry[e]).ToArray(); var surface = ListedSurfaceHelper.ToRiskyFlySurface(smiles, origin, fwds, currency); return(surface); }