Example #1
0
        public BlackFuturesCurve(IATMVolSurface volSurface, DateTime startDate, DateTime expiryDate, int nTimeSteps, Func <DateTime, double> forwardCurve, string name, IFutureSettingsProvider futureSettingsProvider, Dictionary <DateTime, double> pastFixings = null)
        {
            _surface                = volSurface;
            _startDate              = startDate;
            _expiryDate             = expiryDate;
            _numberOfSteps          = nTimeSteps;
            _name                   = name;
            _forwardCurve           = forwardCurve;
            _pastFixings            = pastFixings ?? (new Dictionary <DateTime, double>());
            _futureSettingsProvider = futureSettingsProvider;
            if (startDate > expiryDate)
            {
                throw new Exception("Start date must be before expiry date");
            }
            _codes           = new List <string>();
            _futuresExpiries = new List <DateTime>();
            var fCode       = new FutureCode(name, _futureSettingsProvider);
            var currentCode = fCode.GetFrontMonth(startDate);

            _codes.Add(currentCode);
            fCode = new FutureCode(currentCode, DateTime.Today.Year - 2, _futureSettingsProvider);
            _futuresExpiries.Add(fCode.GetRollDate());
            fCode = new FutureCode(currentCode, DateTime.Today.Year - 2, _futureSettingsProvider);
            var targetCode = fCode.GetFrontMonth(expiryDate);

            while (currentCode != targetCode)
            {
                currentCode = fCode.GetNextCode(false);
                _futuresExpiries.Add(fCode.GetRollDate());
                _codes.Add(currentCode);
            }
        }
Example #2
0
        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);
        }
Example #3
0
        public static object FuturesNextCode(
            [ExcelArgument(Description = "Futures code, e.g. CLZ3")] string FuturesCode)
        {
            return(ExcelHelper.Execute(_logger, () =>
            {
                var c = new FutureCode(FuturesCode, DateTime.Today.Year - 2, ContainerStores.SessionContainer.GetService <IFutureSettingsProvider>());

                return c.GetNextCode(false);
            }));
        }
Example #4
0
        public void CheckNextCodeExamples(string futureCode, string nextCode)
        {
            var code = new FutureCode(futureCode, 2016, TestProviderHelper.FutureSettingsProvider);

            Assert.Equal(nextCode, code.GetNextCode(false));
        }