Пример #1
0
        public void CheckExpiryRollForCodeExamples(string futureCode, DateTime expiry, DateTime roll)
        {
            var code = new FutureCode(futureCode, 2016, TestProviderHelper.FutureSettingsProvider);

            Assert.Equal(expiry, code.GetExpiry());
            Assert.Equal(roll, code.GetRollDate());
        }
Пример #2
0
        public static object CreateSTIRFromCode(
            [ExcelArgument(Description = "Object name")] string ObjectName,
            [ExcelArgument(Description = "Value date")] DateTime ValDate,
            [ExcelArgument(Description = "Futures Code, e.g. EDZ9")] string FuturesCode,
            [ExcelArgument(Description = "Rate Index")] string RateIndex,
            [ExcelArgument(Description = "Price")] double Price,
            [ExcelArgument(Description = "Quantity in lots")] double Quantity,
            [ExcelArgument(Description = "Convexity adjustment")] double ConvexityAdjustment,
            [ExcelArgument(Description = "Forecast Curve")] string ForecastCurve,
            [ExcelArgument(Description = "Solve Curve name ")] object SolveCurve,
            [ExcelArgument(Description = "Solve Pillar Date")] object SolvePillarDate)
        {
            return(ExcelHelper.Execute(_logger, () =>
            {
                if (!ContainerStores.GetObjectCache <FloatRateIndex>().TryGetObject(RateIndex, out var rIndex))
                {
                    _logger?.LogInformation("Rate index {index} not found in cache", RateIndex);
                    return $"Rate index {RateIndex} not found in cache";
                }

                var c = new FutureCode(FuturesCode, DateTime.Today.Year - 2, ContainerStores.SessionContainer.GetService <IFutureSettingsProvider>());

                var expiry = c.GetExpiry();
                var accrualStart = expiry.AddPeriod(RollType.F, rIndex.Value.HolidayCalendars, rIndex.Value.FixingOffset);
                var accrualEnd = accrualStart.AddPeriod(rIndex.Value.RollConvention, rIndex.Value.HolidayCalendars, rIndex.Value.ResetTenor);
                //var dcf = accrualStart.CalculateYearFraction(accrualEnd, rIndex.Value.DayCountBasis);
                var product = new STIRFuture
                {
                    Currency = rIndex.Value.Currency,
                    ContractSize = c.Settings.LotSize,
                    //DCF = dcf,
                    ConvexityAdjustment = ConvexityAdjustment,
                    Expiry = expiry,
                    ForecastCurve = ForecastCurve,
                    Index = rIndex.Value,
                    Position = Quantity,
                    Price = Price,
                    SolveCurve = SolveCurve.OptionalExcel(ForecastCurve),
                    PillarDate = SolvePillarDate.OptionalExcel(accrualEnd),
                    TradeId = ObjectName
                };

                return ExcelHelper.PushToCache(product, ObjectName);
            }));
        }
Пример #3
0
        public static object CreateOISFutureFromCode(
            [ExcelArgument(Description = "Object name")] string ObjectName,
            [ExcelArgument(Description = "Value date")] DateTime ValDate,
            [ExcelArgument(Description = "Futures Code, e.g. EDZ9")] string FuturesCode,
            [ExcelArgument(Description = "Rate Index")] string RateIndex,
            [ExcelArgument(Description = "Price")] double Price,
            [ExcelArgument(Description = "Quantity in lots")] double Quantity,
            [ExcelArgument(Description = "Forecast Curve")] string ForecastCurve,
            [ExcelArgument(Description = "Solve Curve name ")] object SolveCurve,
            [ExcelArgument(Description = "Solve Pillar Date")] object SolvePillarDate)
        {
            return(ExcelHelper.Execute(_logger, () =>
            {
                if (!ContainerStores.GetObjectCache <FloatRateIndex>().TryGetObject(RateIndex, out var rIndex))
                {
                    _logger?.LogInformation("Rate index {index} not found in cache", RateIndex);
                    return $"Rate index {RateIndex} not found in cache";
                }

                var c = new FutureCode(FuturesCode, DateTime.Today.Year - 2, ContainerStores.SessionContainer.GetService <IFutureSettingsProvider>());

                var expiry = c.GetExpiry();
                var accrualStart = expiry.FirstDayOfMonth();
                var accrualEnd = expiry.LastDayOfMonth();
                var dcf = accrualStart.CalculateYearFraction(accrualEnd, rIndex.Value.DayCountBasis);
                var product = new OISFuture
                {
                    Currency = rIndex.Value.Currency,
                    ContractSize = c.Settings.LotSize,
                    DCF = dcf,
                    AverageStartDate = accrualStart,
                    AverageEndDate = accrualEnd,
                    ForecastCurve = ForecastCurve,
                    Index = rIndex.Value,
                    Position = Quantity,
                    Price = Price,
                    SolveCurve = SolveCurve.OptionalExcel(rIndex.Name),
                    PillarDate = SolvePillarDate.OptionalExcel(accrualEnd),
                    TradeId = ObjectName
                };

                return ExcelHelper.PushToCache(product, ObjectName);
            }));
        }