public void OISFuture() { var bd = DateTime.Today; var pillars = new[] { bd, bd.AddDays(1000) }; var flatRate = 0.05; var rates = pillars.Select(p => flatRate).ToArray(); CalendarProvider.Collection.TryGetCalendar("LON", out var cal); var usd = TestProviderHelper.CurrencyProvider["USD"]; var discoCurve = new IrCurve(pillars, rates, bd, "USD.BLAH", Interpolator1DType.Linear, usd); var fModel = new FundingModel(bd, new[] { discoCurve }, TestProviderHelper.CurrencyProvider, TestProviderHelper.CalendarProvider); var price = 93.0; var ix = new FloatRateIndex { Currency = usd, DayCountBasis = DayCountBasis.ACT360, FixingOffset = 2.Bd(), HolidayCalendars = cal, ResetTenor = 3.Months(), RollConvention = RollType.MF }; var maturity = bd.AddDays(365); var accrualStart = maturity.AddPeriod(RollType.F, ix.HolidayCalendars, ix.FixingOffset); var accrualEnd = accrualStart.AddPeriod(ix.RollConvention, ix.HolidayCalendars, ix.ResetTenor); var dcf = maturity.CalculateYearFraction(accrualEnd, DayCountBasis.ACT360); var s = new OISFuture { Currency = usd, ContractSize = 1e6, Position = 1, DCF = dcf, AverageStartDate = accrualStart, AverageEndDate = accrualEnd, ForecastCurve = "USD.BLAH", Price = price, Index = ix }; var pv = s.Pv(fModel, false); var rateEst = discoCurve.GetForwardRate(accrualStart, accrualEnd, RateType.Linear, ix.DayCountBasis); var fairPrice = 100.0 - rateEst * 100; var expectedPv = (price - fairPrice) * 1e6 * dcf; Assert.Equal(expectedPv, pv); var ss = s.Sensitivities(fModel); Assert.True(ss.Count == 1 && ss.Keys.Single() == "USD.BLAH"); Assert.True(ss["USD.BLAH"].Count == 2 && ss["USD.BLAH"].Keys.Contains(accrualStart) && ss["USD.BLAH"].Keys.Contains(accrualEnd)); Assert.Equal(accrualEnd, s.LastSensitivityDate); Assert.Empty(s.Dependencies(null)); var s2 = (OISFuture)s.SetParRate(97); Assert.Equal(97, s2.Price); }
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); })); }