Пример #1
0
        public static RiskyFlySurface GetSurfaceForCode(string nymexSymbol, string nymexOptionFilename, string qwackCode, PriceCurve priceCurve, ICalendarProvider calendarProvider, ICurrencyProvider currency)
        {
            var parsed = NYMEXOptionParser.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.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
            }).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 surface = ListedSurfaceHelper.ToRiskyFlySurface(smiles, origin, smiles.Keys.Select(x => priceCurve.GetPriceForDate(x)).ToArray());

            return(surface);
        }
Пример #2
0
        public static RiskyFlySurface GetMetalSurfaceForCode(string cmxSymbol, string cmxSettleFilename, ICurrencyProvider currency)
        {
            var blob   = CMEFileParser.Instance.GetBlob(cmxSettleFilename);
            var origin = blob.Batch.First().BizDt;

            var(optionExerciseType, optionMarginingType) = OptionTypeFromCode(cmxSymbol);
            var opts = blob.Batch.Where(b => b.Instrmt.Sym == cmxSymbol).Select(x => new ListedOptionSettlementRecord
            {
                Strike                = Convert.ToDouble(x.Instrmt.StrkPx),
                PV                    = Convert.ToDouble(x.Full.Where(x => x.Typ == "6").First().Px),
                CallPut               = x.Instrmt.PutCall ? OptionType.C : OptionType.P, //x.Instrmt.PutCall == 1 ? OptionType.C : OptionType.P,
                ExerciseType          = optionExerciseType,
                MarginType            = optionMarginingType,
                UnderlyingFuturesCode = $"{x.Undly.ID}~{x.Undly.MMY}",
                ExpiryDate            = x.Instrmt.MatDt,
                ValDate               = origin
            }).Where(z => z.ExpiryDate > origin).ToList();

            var underlyings = opts.Select(x => x.UnderlyingFuturesCode).Distinct().ToArray();
            var ulCodes     = underlyings.Select(x => x.Split('~')[0]).Distinct().ToArray();

            var futRecords = blob.Batch.Where(b => b.Instrmt.SecTyp == "FUT" && ulCodes.Contains(b.Instrmt.ID));
            var priceDict  = futRecords.ToDictionary(x => $"{x.Instrmt.ID}~{x.Instrmt.MMY}", x => Convert.ToDouble(x.Full.Where(x => x.Typ == "6").First().Px));

            ListedSurfaceHelper.ImplyVols(opts, priceDict, new ConstantRateIrCurve(0.0, origin, "dummy", currency.GetCurrency("USD")));
            var smiles = ListedSurfaceHelper.ToDeltaSmiles(opts, priceDict);

            var expiries    = smiles.Keys.OrderBy(x => x).ToArray();
            var ulByExpiry  = expiries.ToDictionary(x => x, x => opts.Where(qq => qq.ExpiryDate == x).First().UnderlyingFuturesCode);
            var fwdByExpiry = ulByExpiry.ToDictionary(x => x.Key, x => priceDict[x.Value]);
            var fwds        = expiries.Select(e => fwdByExpiry[e]).ToArray();
            var surface     = ListedSurfaceHelper.ToRiskyFlySurface(smiles, origin, fwds, currency);

            return(surface);
        }
Пример #3
0
        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);
        }