//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test(enabled = true) public void log_normal_atm() public virtual void log_normal_atm() { double beta = 0.50; Surface betaSurface = ConstantSurface.of("Beta", beta).withMetadata(DefaultSurfaceMetadata.builder().xValueType(ValueType.YEAR_FRACTION).yValueType(ValueType.YEAR_FRACTION).zValueType(ValueType.SABR_BETA).surfaceName("Beta").build()); double shift = 0.0000; Surface shiftSurface = ConstantSurface.of("Shift", shift).withMetadata(DefaultSurfaceMetadata.builder().xValueType(ValueType.YEAR_FRACTION).yValueType(ValueType.YEAR_FRACTION).surfaceName("Shift").build()); SabrParametersSwaptionVolatilities calibratedSmile = SABR_CALIBRATION.calibrateWithFixedBetaAndShift(DEFINITION, CALIBRATION_TIME, DATA_SPARSE, MULTICURVE, betaSurface, shiftSurface); SabrParametersSwaptionVolatilities calibratedAtm = SABR_CALIBRATION.calibrateAlphaWithAtm(NAME_SABR, calibratedSmile, MULTICURVE, ATM_LOGNORMAL_SIMPLE, TENORS_SIMPLE, EXPIRIES_SIMPLE_2, INTERPOLATOR_2D); int nbExp = EXPIRIES_SIMPLE_2.size(); int nbTenor = TENORS_SIMPLE.size(); for (int loopexpiry = 0; loopexpiry < nbExp; loopexpiry++) { for (int looptenor = 0; looptenor < nbTenor; looptenor++) { double tenor = TENORS_SIMPLE.get(looptenor).get(ChronoUnit.YEARS); LocalDate expiry = EUR_FIXED_1Y_EURIBOR_6M.FloatingLeg.StartDateBusinessDayAdjustment.adjust(CALIBRATION_DATE.plus(EXPIRIES_SIMPLE_2.get(loopexpiry)), REF_DATA); LocalDate effectiveDate = EUR_FIXED_1Y_EURIBOR_6M.calculateSpotDateFromTradeDate(expiry, REF_DATA); LocalDate endDate = effectiveDate.plus(TENORS_SIMPLE.get(looptenor)); SwapTrade swap = EUR_FIXED_1Y_EURIBOR_6M.toTrade(CALIBRATION_DATE, effectiveDate, endDate, BuySell.BUY, 1.0, 0.0); double parRate = SWAP_PRICER.parRate(swap.resolve(REF_DATA).Product, MULTICURVE); ZonedDateTime expiryDateTime = expiry.atTime(11, 0).atZone(ZoneId.of("Europe/Berlin")); double time = calibratedAtm.relativeTime(expiryDateTime); double volBlack = calibratedAtm.volatility(expiryDateTime, tenor, parRate, parRate); double priceComputed = calibratedAtm.price(time, tenor, PutCall.CALL, parRate, parRate, volBlack); double priceBlack = BlackFormulaRepository.price(parRate, parRate, time, DATA_LOGNORMAL_ATM_SIMPLE[looptenor + loopexpiry * nbTenor], true); assertEquals(priceComputed, priceBlack, TOLERANCE_PRICE_CALIBRATION_ROOT); } } }
private const double TOLERANCE_PRICE_CALIBRATION_LS = 5.0E-4; // Calibration Least Square; result not exact //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void normal_cube() public virtual void normal_cube() { double beta = 0.50; Surface betaSurface = ConstantSurface.of("Beta", beta).withMetadata(DefaultSurfaceMetadata.builder().xValueType(ValueType.YEAR_FRACTION).yValueType(ValueType.YEAR_FRACTION).zValueType(ValueType.SABR_BETA).surfaceName("Beta").build()); double shift = 0.0300; Surface shiftSurface = ConstantSurface.of("Shift", shift).withMetadata(DefaultSurfaceMetadata.builder().xValueType(ValueType.YEAR_FRACTION).yValueType(ValueType.YEAR_FRACTION).surfaceName("Shift").build()); SabrParametersSwaptionVolatilities calibrated = SABR_CALIBRATION.calibrateWithFixedBetaAndShift(DEFINITION, CALIBRATION_TIME, DATA_SPARSE, MULTICURVE, betaSurface, shiftSurface); for (int looptenor = 0; looptenor < TENORS.size(); looptenor++) { double tenor = TENORS.get(looptenor).get(ChronoUnit.YEARS); for (int loopexpiry = 0; loopexpiry < EXPIRIES.size(); loopexpiry++) { LocalDate expiry = EUR_FIXED_1Y_EURIBOR_6M.FloatingLeg.StartDateBusinessDayAdjustment.adjust(CALIBRATION_DATE.plus(EXPIRIES.get(loopexpiry)), REF_DATA); LocalDate effectiveDate = EUR_FIXED_1Y_EURIBOR_6M.calculateSpotDateFromTradeDate(expiry, REF_DATA); LocalDate endDate = effectiveDate.plus(TENORS.get(looptenor)); SwapTrade swap = EUR_FIXED_1Y_EURIBOR_6M.toTrade(CALIBRATION_DATE, effectiveDate, endDate, BuySell.BUY, 1.0, 0.0); double parRate = SWAP_PRICER.parRate(swap.resolve(REF_DATA).Product, MULTICURVE); ZonedDateTime expiryDateTime = expiry.atTime(11, 0).atZone(ZoneId.of("Europe/Berlin")); double time = calibrated.relativeTime(expiryDateTime); for (int loopmoney = 0; loopmoney < MONEYNESS.size(); loopmoney++) { if (!double.IsNaN(DATA_ARRAY_SPARSE[looptenor][loopexpiry][loopmoney])) { double strike = parRate + MONEYNESS.get(loopmoney); double volBlack = calibrated.volatility(expiryDateTime, tenor, strike, parRate); double priceComputed = BlackFormulaRepository.price(parRate + shift, parRate + MONEYNESS.get(loopmoney) + shift, time, volBlack, true); double priceNormal = NormalFormulaRepository.price(parRate, parRate + MONEYNESS.get(loopmoney), time, DATA_ARRAY_SPARSE[looptenor][loopexpiry][loopmoney], PutCall.CALL); assertEquals(priceComputed, priceNormal, TOLERANCE_PRICE_CALIBRATION_LS); } } } } }
private static IborIndex parseIborIndex(CsvRow row) { string name = row.getValue(NAME_FIELD); Currency currency = Currency.parse(row.getValue(CURRENCY_FIELD)); bool active = bool.Parse(row.getValue(ACTIVE_FIELD)); DayCount dayCount = DayCount.of(row.getValue(DAY_COUNT_FIELD)); HolidayCalendarId fixingCal = HolidayCalendarId.of(row.getValue(FIXING_CALENDAR_FIELD)); int offsetDays = int.Parse(row.getValue(OFFSET_DAYS_FIELD)); HolidayCalendarId offsetCal = HolidayCalendarId.of(row.getValue(OFFSET_CALENDAR_FIELD)); HolidayCalendarId effectiveCal = HolidayCalendarId.of(row.getValue(EFFECTIVE_DATE_CALENDAR_FIELD)); Tenor tenor = Tenor.parse(row.getValue(TENOR_FIELD)); LocalTime time = LocalTime.parse(row.getValue(FIXING_TIME_FIELD), TIME_FORMAT); ZoneId zoneId = ZoneId.of(row.getValue(FIXING_ZONE_FIELD)); DayCount fixedLegDayCount = DayCount.of(row.getValue(FIXED_LEG_DAY_COUNT)); // interpret CSV DaysAdjustment fixingOffset = DaysAdjustment.ofBusinessDays(-offsetDays, offsetCal, BusinessDayAdjustment.of(PRECEDING, fixingCal)).normalized(); DaysAdjustment effectiveOffset = DaysAdjustment.ofBusinessDays(offsetDays, offsetCal, BusinessDayAdjustment.of(FOLLOWING, effectiveCal)).normalized(); // convention can be two different things PeriodAdditionConvention periodAdditionConvention = PeriodAdditionConvention.extendedEnum().find(row.getField(TENOR_CONVENTION_FIELD)).orElse(PeriodAdditionConventions.NONE); BusinessDayConvention tenorBusinessConvention = BusinessDayConvention.extendedEnum().find(row.getField(TENOR_CONVENTION_FIELD)).orElse(isEndOfMonth(periodAdditionConvention) ? MODIFIED_FOLLOWING : FOLLOWING); BusinessDayAdjustment adj = BusinessDayAdjustment.of(tenorBusinessConvention, effectiveCal); TenorAdjustment tenorAdjustment = TenorAdjustment.of(tenor, periodAdditionConvention, adj); // build result return(ImmutableIborIndex.builder().name(name).currency(currency).active(active).dayCount(dayCount).fixingCalendar(fixingCal).fixingDateOffset(fixingOffset).effectiveDateOffset(effectiveOffset).maturityDateOffset(tenorAdjustment).fixingTime(time).fixingZone(zoneId).defaultFixedLegDayCount(fixedLegDayCount).build()); }
public virtual void test_volatilities() { BlackFxOptionInterpolatedNodalSurfaceVolatilitiesSpecification @base = BlackFxOptionInterpolatedNodalSurfaceVolatilitiesSpecification.builder().name(VOL_NAME).currencyPair(GBP_USD).dayCount(ACT_365F).nodes(NODES).timeInterpolator(PCHIP).strikeInterpolator(DOUBLE_QUADRATIC).build(); LocalDate date = LocalDate.of(2017, 9, 25); ZonedDateTime dateTime = date.atStartOfDay().atZone(ZoneId.of("Europe/London")); DoubleArray parameters = DoubleArray.of(0.19, 0.15, 0.13, 0.14, 0.14, 0.11, 0.09, 0.09, 0.11, 0.09, 0.07, 0.07); BlackFxOptionSurfaceVolatilities computed = @base.volatilities(dateTime, parameters, REF_DATA); DaysAdjustment expOffset = DaysAdjustment.ofBusinessDays(-2, NY_LO); double[] expiries = new double[STRIKES.Count * TENORS.Count]; double[] strikes = new double[STRIKES.Count * TENORS.Count]; ImmutableList.Builder <ParameterMetadata> paramMetadata = ImmutableList.builder(); for (int i = 0; i < TENORS.Count; ++i) { double expiry = ACT_365F.relativeYearFraction(date, expOffset.adjust(BDA.adjust(SPOT_OFFSET.adjust(date, REF_DATA).plus(TENORS[i]), REF_DATA), REF_DATA)); for (int j = 0; j < STRIKES.Count; ++j) { paramMetadata.add(FxVolatilitySurfaceYearFractionParameterMetadata.of(expiry, SimpleStrike.of(STRIKES[j]), GBP_USD)); expiries[STRIKES.Count * i + j] = expiry; strikes[STRIKES.Count * i + j] = STRIKES[j]; } } InterpolatedNodalSurface surface = InterpolatedNodalSurface.ofUnsorted(Surfaces.blackVolatilityByExpiryStrike(VOL_NAME.Name, ACT_365F).withParameterMetadata(paramMetadata.build()), DoubleArray.ofUnsafe(expiries), DoubleArray.ofUnsafe(strikes), parameters, GridSurfaceInterpolator.of(PCHIP, DOUBLE_QUADRATIC)); BlackFxOptionSurfaceVolatilities expected = BlackFxOptionSurfaceVolatilities.of(VOL_NAME, GBP_USD, dateTime, surface); assertEquals(computed, expected); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private org.neo4j.values.storable.DateTimeValue unpackDateTimeWithZoneName() throws java.io.IOException internal virtual DateTimeValue UnpackDateTimeWithZoneName() { long epochSecondLocal = UnpackLong(); long nano = UnpackLong(); string zoneId = UnpackString(); return(datetime(NewZonedDateTime(epochSecondLocal, nano, ZoneId.of(zoneId)))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void shouldBeAbleToParseTimeWithoutTimeZoneWithHeaderInformation() internal virtual void ShouldBeAbleToParseTimeWithoutTimeZoneWithHeaderInformation() { string headerInformation = "{timezone:-01:00}"; string data = "14:05:17"; TimeValue expected = TimeValue.Parse(data, () => ZoneId.of("-01:00")); TimeValue unexpected = TimeValue.Parse(data, InUTC); TimeValue actual = TimeValue.Parse(data, OrFail, TemporalValue.ParseHeaderInformation(headerInformation)); assertEqual(expected, actual); assertNotEquals(unexpected, actual); }
private static SwapIndex parseSwapIndex(CsvRow row) { string name = row.getField(NAME_FIELD); bool active = bool.Parse(row.getField(ACTIVE_FIELD)); FixedIborSwapConvention convention = FixedIborSwapConvention.of(row.getField(CONVENTION_FIELD)); Tenor tenor = Tenor.parse(row.getField(TENOR_FIELD)); LocalTime time = LocalTime.parse(row.getField(FIXING_TIME_FIELD), TIME_FORMAT); ZoneId zoneId = ZoneId.of(row.getField(FIXING_ZONE_FIELD)); // build result return(ImmutableSwapIndex.builder().name(name).active(active).fixingTime(time).fixingZone(zoneId).template(FixedIborSwapTemplate.of(tenor, convention)).build()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldHandleDateTimeWithZoneId() public virtual void ShouldHandleDateTimeWithZoneId() { // Given DateTimeValue dvalue = DateTimeValue.datetime(1, 2, 3, 4, 5, 6, 7, ZoneId.of("Europe/Stockholm")); // When dvalue.WriteTo(_converter); // Then object value = _converter.value(); assertThat(value, instanceOf(typeof(ZonedDateTime))); assertThat(value, equalTo(dvalue.AsObjectCopy())); }
// parse the trade info private TradeInfo parseTradeInfo(CsvRow row) { TradeInfoBuilder infoBuilder = TradeInfo.builder(); string scheme = row.findField(ID_SCHEME_FIELD).orElse(DEFAULT_TRADE_SCHEME); row.findValue(ID_FIELD).ifPresent(id => infoBuilder.id(StandardId.of(scheme, id))); string schemeCpty = row.findValue(CPTY_SCHEME_FIELD).orElse(DEFAULT_CPTY_SCHEME); row.findValue(CPTY_FIELD).ifPresent(cpty => infoBuilder.counterparty(StandardId.of(schemeCpty, cpty))); row.findValue(TRADE_DATE_FIELD).ifPresent(dateStr => infoBuilder.tradeDate(LoaderUtils.parseDate(dateStr))); row.findValue(TRADE_TIME_FIELD).ifPresent(timeStr => infoBuilder.tradeTime(LoaderUtils.parseTime(timeStr))); row.findValue(TRADE_ZONE_FIELD).ifPresent(zoneStr => infoBuilder.zone(ZoneId.of(zoneStr))); row.findValue(SETTLEMENT_DATE_FIELD).ifPresent(dateStr => infoBuilder.settlementDate(LoaderUtils.parseDate(dateStr))); resolver.parseTradeInfo(row, infoBuilder); return(infoBuilder.build()); }
private DateTimeValue(ZonedDateTime value) { ZoneId zone = value.Zone; if (zone is ZoneOffset) { this._value = value; } else { // Do a 2-way lookup of the zone to make sure we only use the new name of renamed zones ZoneId mappedZone = ZoneId.of(TimeZones.Map(TimeZones.Map(zone.Id))); this._value = value.withZoneSameInstant(mappedZone); } this._epochSeconds = this._value.toEpochSecond(); }
private ZoneId[] zonesOf(Description description) { TimeZone zone = description.getAnnotation(typeof(TimeZone)); string[] ids = zone == null ? null : zone.value(); if (ids == null || ids.Length == 0) { return(new ZoneId[] { UTC }); } else { ZoneId[] zones = new ZoneId[ids.Length]; for (int i = 0; i < zones.Length; i++) { zones[i] = ZoneId.of(ids[i]); } return(zones); } }
public virtual void test_volatilities() { BlackFxOptionSmileVolatilitiesSpecification @base = BlackFxOptionSmileVolatilitiesSpecification.builder().name(VOL_NAME).currencyPair(EUR_GBP).dayCount(ACT_360).nodes(NODES).timeInterpolator(PCHIP).strikeInterpolator(PCHIP).build(); LocalDate date = LocalDate.of(2017, 9, 25); ZonedDateTime dateTime = date.atStartOfDay().atZone(ZoneId.of("Europe/London")); DoubleArray parameters = DoubleArray.of(0.05, -0.05, 0.15, 0.25, 0.1, -0.1); BlackFxOptionSmileVolatilities computed = @base.volatilities(dateTime, parameters, REF_DATA); LocalDate spotDate = SPOT_OFFSET.adjust(dateTime.toLocalDate(), REF_DATA); DaysAdjustment expOffset = DaysAdjustment.ofBusinessDays(-2, TA_LO); DoubleArray expiries = DoubleArray.of(ACT_360.relativeYearFraction(date, expOffset.adjust(BUS_ADJ.adjust(spotDate.plus(Tenor.TENOR_3M), REF_DATA), REF_DATA)), ACT_360.relativeYearFraction(date, expOffset.adjust(BUS_ADJ.adjust(spotDate.plus(Tenor.TENOR_1Y), REF_DATA), REF_DATA))); SmileDeltaTermStructure smiles = InterpolatedStrikeSmileDeltaTermStructure.of(expiries, DoubleArray.of(0.1), DoubleArray.of(0.25, 0.15), DoubleMatrix.ofUnsafe(new double[][] { new double[] { -0.1 }, new double[] { -0.05 } }), DoubleMatrix.ofUnsafe(new double[][] { new double[] { 0.1 }, new double[] { 0.05 } }), ACT_360, PCHIP, FLAT, FLAT, PCHIP, FLAT, FLAT); BlackFxOptionSmileVolatilities expected = BlackFxOptionSmileVolatilities.of(VOL_NAME, EUR_GBP, dateTime, smiles); assertEquals(computed, expected); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldHandleTemporalUsingGraphResultDataContent() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldHandleTemporalUsingGraphResultDataContent() { //Given GraphDatabaseFacade db = Server().Database.Graph; ZonedDateTime date = ZonedDateTime.of(1980, 3, 11, 0, 0, 0, 0, ZoneId.of("Europe/Stockholm")); using (Transaction tx = Db.beginTx()) { Node node = Db.createNode(label("N")); node.SetProperty("date", date); tx.Success(); } //When HTTP.Response response = RunQuery("MATCH (n:N) RETURN n", "graph"); //Then assertEquals(200, response.Status()); AssertNoErrors(response); JsonNode row = response.Get("results").get(0).get("data").get(0).get("graph").get("nodes").get(0).get("properties").get("date"); assertEquals("\"1980-03-11T00:00+01:00[Europe/Stockholm]\"", row.ToString()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void compareToSameAsValue() public virtual void CompareToSameAsValue() { Value[] values = new Value[] { DateTimeValue.datetime(9999, 100, ZoneId.of("+18:00")), DateTimeValue.datetime(10000, 100, ZoneId.of("-18:00")), DateTimeValue.datetime(10000, 100, ZoneOffset.of("-17:59:59")), DateTimeValue.datetime(10000, 100, ZoneId.of("UTC")), DateTimeValue.datetime(10000, 100, ZoneId.of("+01:00")), DateTimeValue.datetime(10000, 100, ZoneId.of("Europe/Stockholm")), DateTimeValue.datetime(10000, 100, ZoneId.of("+03:00")), DateTimeValue.datetime(10000, 101, ZoneId.of("-18:00")) }; ZonedDateTimeIndexKey keyI = new ZonedDateTimeIndexKey(); ZonedDateTimeIndexKey keyJ = new ZonedDateTimeIndexKey(); int len = values.Length; for (int i = 0; i < len; i++) { for (int j = 0; j < len; j++) { Value vi = values[i]; Value vj = values[j]; vi.WriteTo(keyI); vj.WriteTo(keyJ); int expected = Integer.signum(Values.COMPARATOR.Compare(vi, vj)); assertEquals(format("comparing %s and %s", vi, vj), expected, Integer.signum(i - j)); assertEquals(format("comparing %s and %s", vi, vj), expected, Integer.signum(keyI.CompareValueTo(keyJ))); } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldReadAndWriteConsistentValues() public virtual void ShouldReadAndWriteConsistentValues() { Value[] values = new Value[] { DateTimeValue.datetime(9999, 100, ZoneId.of("+18:00")), DateTimeValue.datetime(10000, 100, ZoneId.of("-18:00")), DateTimeValue.datetime(10000, 100, ZoneOffset.of("-17:59:59")), DateTimeValue.datetime(10000, 100, ZoneId.of("UTC")), DateTimeValue.datetime(10000, 100, ZoneId.of("+01:00")), DateTimeValue.datetime(10000, 100, ZoneId.of("Europe/Stockholm")), DateTimeValue.datetime(10000, 100, ZoneId.of("+03:00")), DateTimeValue.datetime(10000, 101, ZoneId.of("-18:00")) }; ZonedDateTimeLayout layout = new ZonedDateTimeLayout(); PageCursor cursor = new StubPageCursor(0, 8 * 1024); ZonedDateTimeIndexKey writeKey = layout.NewKey(); ZonedDateTimeIndexKey readKey = layout.NewKey(); // Write all foreach (Value value in values) { value.WriteTo(writeKey); layout.WriteKey(cursor, writeKey); } // Read all cursor.Offset = 0; foreach (Value value in values) { layout.ReadKey(cursor, readKey, ZonedDateTimeIndexKey.Size); assertEquals(value, readKey.AsValue()); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testDateTimeArrayWithZoneOffsetAndZoneID() public virtual void TestDateTimeArrayWithZoneOffsetAndZoneID() { ZonedDateTime[] array = new ZonedDateTime[] { DateTimeValue.datetime(1991, 1, 1, 0, 0, 13, 37, "-01:00").asObjectCopy(), DateTimeValue.datetime(1992, 2, 28, 1, 15, 0, 4000, "+11:00").asObjectCopy(), DateTimeValue.datetime(1992, 2, 28, 1, 15, 0, 4000, ZoneId.of("Europe/Stockholm")).asObjectCopy() }; string key = "testarray"; _node1.setProperty(key, array); NewTransaction(); ZonedDateTime[] propertyValue = ( ZonedDateTime[] )_node1.getProperty(key); assertEquals(array.Length, propertyValue.Length); for (int i = 0; i < array.Length; i++) { assertEquals(array[i], propertyValue[i]); } _node1.removeProperty(key); NewTransaction(); assertTrue(!_node1.hasProperty(key)); }
internal static FxVanillaOption sut2() { FxSingle fxProduct = FxSingle.of(CurrencyAmount.of(EUR, -NOTIONAL), CurrencyAmount.of(GBP, NOTIONAL * 0.9), PAYMENT_DATE); return(FxVanillaOption.builder().longShort(LongShort.SHORT).expiryDate(LocalDate.of(2015, 2, 15)).expiryTime(LocalTime.of(12, 45)).expiryZone(ZoneId.of("GMT")).underlying(fxProduct).build()); }
public virtual void test_serialization() { IborIndex index = ImmutableIborIndex.builder().name("Test-3M").currency(Currency.GBP).fixingCalendar(GBLO).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, GBLO)).effectiveDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)).maturityDateOffset(TenorAdjustment.ofLastBusinessDay(TENOR_3M, BusinessDayAdjustment.NONE)).dayCount(ACT_360).fixingTime(LocalTime.NOON).fixingZone(ZoneId.of("Europe/London")).build(); assertSerialization(index); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testDateTimeTypeWithZoneId() public virtual void TestDateTimeTypeWithZoneId() { DateTimeValue dateTime = DateTimeValue.datetime(1991, 1, 1, 0, 0, 13, 37, ZoneId.of("Europe/Stockholm")); string key = "dt"; _node1.setProperty(key, dateTime); NewTransaction(); object property = _node1.getProperty(key); assertEquals(dateTime.AsObjectCopy(), property); }
//------------------------------------------------------------------------- public virtual void test_equals() { ImmutableIborIndex a = ImmutableIborIndex.builder().name("Test-3M").currency(Currency.GBP).fixingCalendar(GBLO).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, GBLO)).effectiveDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)).maturityDateOffset(TenorAdjustment.ofLastBusinessDay(TENOR_3M, BusinessDayAdjustment.NONE)).dayCount(ACT_360).fixingTime(LocalTime.NOON).fixingZone(ZoneId.of("Europe/London")).build(); IborIndex b = a.toBuilder().name("Rubbish-3M").build(); assertEquals(a.Equals(b), false); }
//------------------------------------------------------------------------- public virtual void coverage() { ImmutableIborIndex index = ImmutableIborIndex.builder().name("Test-3M").currency(Currency.GBP).fixingCalendar(GBLO).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, GBLO)).effectiveDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)).maturityDateOffset(TenorAdjustment.ofLastBusinessDay(TENOR_3M, BusinessDayAdjustment.NONE)).dayCount(ACT_360).fixingTime(LocalTime.NOON).fixingZone(ZoneId.of("Europe/London")).build(); coverImmutableBean(index); coverPrivateConstructor(typeof(IborIndices)); }
public virtual void test_euribor3m_dates() { IborIndex test = IborIndex.of("EUR-EURIBOR-3M"); assertEquals(test.calculateEffectiveFromFixing(date(2014, 10, 27), REF_DATA), date(2014, 10, 29)); assertEquals(test.calculateMaturityFromFixing(date(2014, 10, 27), REF_DATA), date(2015, 1, 29)); assertEquals(test.calculateFixingFromEffective(date(2014, 10, 29), REF_DATA), date(2014, 10, 27)); assertEquals(test.calculateMaturityFromEffective(date(2014, 10, 29), REF_DATA), date(2015, 1, 29)); // weekend assertEquals(test.calculateEffectiveFromFixing(date(2014, 10, 10), REF_DATA), date(2014, 10, 14)); assertEquals(test.calculateMaturityFromFixing(date(2014, 10, 10), REF_DATA), date(2015, 1, 14)); assertEquals(test.calculateFixingFromEffective(date(2014, 10, 14), REF_DATA), date(2014, 10, 10)); assertEquals(test.calculateMaturityFromEffective(date(2014, 10, 14), REF_DATA), date(2015, 1, 14)); // input date is Sunday assertEquals(test.calculateEffectiveFromFixing(date(2014, 10, 12), REF_DATA), date(2014, 10, 15)); assertEquals(test.calculateMaturityFromFixing(date(2014, 10, 12), REF_DATA), date(2015, 1, 15)); assertEquals(test.calculateFixingFromEffective(date(2014, 10, 12), REF_DATA), date(2014, 10, 9)); assertEquals(test.calculateMaturityFromEffective(date(2014, 10, 12), REF_DATA), date(2015, 1, 13)); // fixing time and zone assertEquals(test.calculateFixingDateTime(date(2014, 10, 13)), date(2014, 10, 13).atTime(LocalTime.of(11, 0)).atZone(ZoneId.of("Europe/Brussels"))); }
public virtual void test_tibor_euroyen3m_dates() { IborIndex test = IborIndex.of("JPY-TIBOR-EUROYEN-3M"); assertEquals(test.calculateEffectiveFromFixing(date(2014, 10, 27), REF_DATA), date(2014, 10, 29)); assertEquals(test.calculateMaturityFromFixing(date(2014, 10, 27), REF_DATA), date(2015, 1, 29)); assertEquals(test.calculateFixingFromEffective(date(2014, 10, 29), REF_DATA), date(2014, 10, 27)); assertEquals(test.calculateMaturityFromEffective(date(2014, 10, 29), REF_DATA), date(2015, 1, 29)); // weekend assertEquals(test.calculateEffectiveFromFixing(date(2014, 10, 10), REF_DATA), date(2014, 10, 15)); assertEquals(test.calculateMaturityFromFixing(date(2014, 10, 10), REF_DATA), date(2015, 1, 15)); assertEquals(test.calculateFixingFromEffective(date(2014, 10, 15), REF_DATA), date(2014, 10, 10)); assertEquals(test.calculateMaturityFromEffective(date(2014, 10, 15), REF_DATA), date(2015, 1, 15)); // input date is Sunday assertEquals(test.calculateEffectiveFromFixing(date(2014, 10, 12), REF_DATA), date(2014, 10, 16)); assertEquals(test.calculateMaturityFromFixing(date(2014, 10, 12), REF_DATA), date(2015, 1, 16)); assertEquals(test.calculateFixingFromEffective(date(2014, 10, 12), REF_DATA), date(2014, 10, 9)); assertEquals(test.calculateMaturityFromEffective(date(2014, 10, 12), REF_DATA), date(2015, 1, 14)); // fixing time and zone assertEquals(test.calculateFixingDateTime(date(2014, 10, 13)), date(2014, 10, 13).atTime(LocalTime.of(11, 50)).atZone(ZoneId.of("Asia/Tokyo"))); }
public virtual void test_gbpLibor3m_dates() { IborIndex test = IborIndex.of("GBP-LIBOR-3M"); assertEquals(test.calculateEffectiveFromFixing(date(2014, 10, 13), REF_DATA), date(2014, 10, 13)); assertEquals(test.calculateMaturityFromFixing(date(2014, 10, 13), REF_DATA), date(2015, 1, 13)); assertEquals(test.calculateFixingFromEffective(date(2014, 10, 13), REF_DATA), date(2014, 10, 13)); assertEquals(test.calculateMaturityFromEffective(date(2014, 10, 13), REF_DATA), date(2015, 1, 13)); // weekend assertEquals(test.calculateEffectiveFromFixing(date(2014, 10, 10), REF_DATA), date(2014, 10, 10)); assertEquals(test.calculateMaturityFromFixing(date(2014, 10, 10), REF_DATA), date(2015, 1, 12)); assertEquals(test.calculateFixingFromEffective(date(2014, 10, 10), REF_DATA), date(2014, 10, 10)); assertEquals(test.calculateMaturityFromEffective(date(2014, 10, 10), REF_DATA), date(2015, 1, 12)); // input date is Sunday assertEquals(test.calculateEffectiveFromFixing(date(2014, 10, 12), REF_DATA), date(2014, 10, 13)); assertEquals(test.calculateMaturityFromFixing(date(2014, 10, 12), REF_DATA), date(2015, 1, 13)); assertEquals(test.calculateFixingFromEffective(date(2014, 10, 12), REF_DATA), date(2014, 10, 13)); assertEquals(test.calculateMaturityFromEffective(date(2014, 10, 12), REF_DATA), date(2015, 1, 13)); // fixing time and zone assertEquals(test.calculateFixingDateTime(date(2014, 10, 13)), date(2014, 10, 13).atTime(LocalTime.of(11, 0)).atZone(ZoneId.of("Europe/London"))); // resolve assertEquals(test.resolve(REF_DATA).apply(date(2014, 10, 13)), IborIndexObservation.of(test, date(2014, 10, 13), REF_DATA)); }
public virtual void test_usdLibor3m_dates() { IborIndex test = IborIndex.of("USD-LIBOR-3M"); assertEquals(test.calculateEffectiveFromFixing(date(2014, 10, 27), REF_DATA), date(2014, 10, 29)); assertEquals(test.calculateMaturityFromFixing(date(2014, 10, 27), REF_DATA), date(2015, 1, 29)); assertEquals(test.calculateFixingFromEffective(date(2014, 10, 29), REF_DATA), date(2014, 10, 27)); assertEquals(test.calculateMaturityFromEffective(date(2014, 10, 29), REF_DATA), date(2015, 1, 29)); // weekend assertEquals(test.calculateEffectiveFromFixing(date(2014, 10, 10), REF_DATA), date(2014, 10, 14)); assertEquals(test.calculateMaturityFromFixing(date(2014, 10, 10), REF_DATA), date(2015, 1, 14)); assertEquals(test.calculateFixingFromEffective(date(2014, 10, 14), REF_DATA), date(2014, 10, 10)); assertEquals(test.calculateMaturityFromEffective(date(2014, 10, 14), REF_DATA), date(2015, 1, 14)); // effective date is US holiday assertEquals(test.calculateEffectiveFromFixing(date(2015, 1, 16), REF_DATA), date(2015, 1, 20)); assertEquals(test.calculateMaturityFromFixing(date(2015, 1, 16), REF_DATA), date(2015, 4, 20)); assertEquals(test.calculateFixingFromEffective(date(2015, 1, 20), REF_DATA), date(2015, 1, 16)); assertEquals(test.calculateMaturityFromEffective(date(2015, 1, 20), REF_DATA), date(2015, 4, 20)); // input date is Sunday, 13th is US holiday, but not UK holiday (can fix, but not be effective) assertEquals(test.calculateEffectiveFromFixing(date(2014, 10, 12), REF_DATA), date(2014, 10, 15)); assertEquals(test.calculateMaturityFromFixing(date(2014, 10, 12), REF_DATA), date(2015, 1, 15)); assertEquals(test.calculateFixingFromEffective(date(2014, 10, 12), REF_DATA), date(2014, 10, 10)); assertEquals(test.calculateMaturityFromEffective(date(2014, 10, 12), REF_DATA), date(2015, 1, 14)); // fixing time and zone assertEquals(test.calculateFixingDateTime(date(2014, 10, 13)), date(2014, 10, 13).atTime(LocalTime.of(11, 0)).atZone(ZoneId.of("Europe/London"))); // resolve assertEquals(test.resolve(REF_DATA).apply(date(2014, 10, 27)), IborIndexObservation.of(test, date(2014, 10, 27), REF_DATA)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Ignore public void shouldEqualRenamedTimeZone() public virtual void ShouldEqualRenamedTimeZone() { assertEqual(datetime(10000, 100, ZoneId.of("Canada/Saskatchewan")), datetime(10000, 100, ZoneId.of("Canada/East-Saskatchewan"))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Before public void setup() public virtual void Setup() { _values = new List <Value>(); // ZONED_DATE_TIME_ARRAY _values.Add(Values.dateTimeArray(new ZonedDateTime[] { ZonedDateTime.of(2018, 10, 9, 8, 7, 6, 5, ZoneId.of("UTC")), ZonedDateTime.of(2017, 9, 8, 7, 6, 5, 4, ZoneId.of("UTC")) })); // LOCAL_DATE_TIME_ARRAY _values.Add(Values.localDateTimeArray(new DateTime[] { new DateTime(2018, 10, 9, 8, 7, 6, 5), new DateTime(2018, 10, 9, 8, 7, 6, 5) })); // DATE_ARRAY _values.Add(Values.dateArray(new LocalDate[] { LocalDate.of(1, 12, 28), LocalDate.of(1, 12, 28) })); // ZONED_TIME_ARRAY _values.Add(Values.timeArray(new OffsetTime[] { OffsetTime.of(19, 8, 7, 6, ZoneOffset.UTC), OffsetTime.of(19, 8, 7, 6, ZoneOffset.UTC) })); // LOCAL_TIME_ARRAY _values.Add(Values.localTimeArray(new LocalTime[] { LocalTime.of(19, 28), LocalTime.of(19, 28) })); // DURATION_ARRAY _values.Add(Values.durationArray(new DurationValue[] { DurationValue.duration(99, 10, 10, 10), DurationValue.duration(99, 10, 10, 10) })); // TEXT_ARRAY _values.Add(Values.of(new string[] { "someString1", "someString2" })); // BOOLEAN_ARRAY _values.Add(Values.of(new bool[] { true, true })); // NUMBER_ARRAY (byte, short, int, long, float, double) _values.Add(Values.of(new sbyte[] { ( sbyte )1, ( sbyte )12 })); _values.Add(Values.of(new short[] { 314, 1337 })); _values.Add(Values.of(new int[] { 3140, 13370 })); _values.Add(Values.of(new long[] { 31400, 133700 })); _values.Add(Values.of(new float[] { 0.5654f, 13432.14f })); _values.Add(Values.of(new double[] { 432453254.43243, 4354.7888 })); _values.Add(Values.of(new char[] { 'a', 'z' })); // ZONED_DATE_TIME _values.Add(DateTimeValue.datetime(2014, 3, 25, 12, 45, 13, 7474, "UTC")); // LOCAL_DATE_TIME _values.Add(LocalDateTimeValue.localDateTime(2018, 3, 1, 13, 50, 42, 1337)); // DATE _values.Add(DateValue.epochDate(2)); // ZONED_TIME _values.Add(TimeValue.time(43_200_000_000_000L, ZoneOffset.UTC)); // LOCAL_TIME _values.Add(LocalTimeValue.localTime(100000)); // DURATION _values.Add(DurationValue.duration(10, 20, 30, 40)); // TEXT _values.Add(Values.of("string1")); // BOOLEAN _values.Add(Values.of(true)); // NUMBER (byte, short, int, long, float, double) _values.Add(Values.of(sbyte.MaxValue)); _values.Add(Values.of(short.MaxValue)); _values.Add(Values.of(int.MaxValue)); _values.Add(Values.of(long.MaxValue)); _values.Add(Values.of(float.MaxValue)); _values.Add(Values.of(double.MaxValue)); _values.Add(Values.of(char.MaxValue)); // GEOMETRY _values.Add(Values.pointValue(CoordinateReferenceSystem.WGS84, 12.78, 56.7)); _values.Add(Values.pointArray(new PointValue[] { Values.pointValue(CoordinateReferenceSystem.WGS84, 12.7566548, 56.7163465), Values.pointValue(CoordinateReferenceSystem.WGS84, 12.13413478, 56.1343457) })); _values.Add(Values.pointValue(CoordinateReferenceSystem.WGS84_3D, 12.78, 56.7, 666)); _values.Add(Values.pointArray(new PointValue[] { Values.pointValue(CoordinateReferenceSystem.WGS84_3D, 12.7566548, 56.7163465, 666), Values.pointValue(CoordinateReferenceSystem.WGS84_3D, 12.13413478, 56.1343457, 555) })); _values.Add(Values.pointValue(CoordinateReferenceSystem.Cartesian, 0.0000043, -0.0000000012341025786543)); _values.Add(Values.pointArray(new PointValue[] { Values.pointValue(CoordinateReferenceSystem.Cartesian, 0.0000043, -0.0000000012341025786543), Values.pointValue(CoordinateReferenceSystem.Cartesian, 0.2000043, -0.0300000012341025786543) })); _values.Add(Values.pointValue(CoordinateReferenceSystem.Cartesian_3D, 0.0000043, -0.0000000012341025786543, 666)); _values.Add(Values.pointArray(new PointValue[] { Values.pointValue(CoordinateReferenceSystem.Cartesian_3D, 0.0000043, -0.0000000012341025786543, 666), Values.pointValue(CoordinateReferenceSystem.Cartesian_3D, 0.2000043, -0.0300000012341025786543, 555) })); }
//------------------------------------------------------------------------- /// <summary> /// Runs the calibration of swaptions and print the calibrated smile results on the console. /// </summary> /// <param name="args"> -s to use the sparse data, i.e. a cube with missing data points </param> public static void Main(string[] args) { // select data TenorRawOptionData data = DATA_FULL; if (args.Length > 0) { if (args[0].Equals("-s")) { data = DATA_SPARSE; } } Console.WriteLine("Start calibration"); double beta = 0.50; SurfaceMetadata betaMetadata = DefaultSurfaceMetadata.builder().xValueType(ValueType.YEAR_FRACTION).yValueType(ValueType.YEAR_FRACTION).zValueType(ValueType.SABR_BETA).surfaceName("Beta").build(); Surface betaSurface = ConstantSurface.of(betaMetadata, beta); double shift = 0.0300; Surface shiftSurface = ConstantSurface.of("Shift", shift); SabrParametersSwaptionVolatilities calibrated = SABR_CALIBRATION.calibrateWithFixedBetaAndShift(DEFINITION, CALIBRATION_TIME, data, MULTICURVE, betaSurface, shiftSurface); Console.WriteLine("End calibration"); /* Graph calibration */ int nbStrikesGraph = 50; double moneyMin = -0.0250; double moneyMax = +0.0300; double[] moneyGraph = new double[nbStrikesGraph + 1]; for (int i = 0; i < nbStrikesGraph + 1; i++) { moneyGraph[i] = moneyMin + i * (moneyMax - moneyMin) / nbStrikesGraph; } //JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java: //ORIGINAL LINE: double[][][] strikesGraph = new double[NB_TENORS][NB_EXPIRIES][nbStrikesGraph + 1]; double[][][] strikesGraph = RectangularArrays.ReturnRectangularDoubleArray(NB_TENORS, NB_EXPIRIES, nbStrikesGraph + 1); //JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java: //ORIGINAL LINE: double[][][] volLNGraph = new double[NB_TENORS][NB_EXPIRIES][nbStrikesGraph + 1]; double[][][] volLNGraph = RectangularArrays.ReturnRectangularDoubleArray(NB_TENORS, NB_EXPIRIES, nbStrikesGraph + 1); //JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java: //ORIGINAL LINE: double[][][] volNGraph = new double[NB_TENORS][NB_EXPIRIES][nbStrikesGraph + 1]; double[][][] volNGraph = RectangularArrays.ReturnRectangularDoubleArray(NB_TENORS, NB_EXPIRIES, nbStrikesGraph + 1); //JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java: //ORIGINAL LINE: double[][] parRate = new double[NB_TENORS][NB_EXPIRIES]; double[][] parRate = RectangularArrays.ReturnRectangularDoubleArray(NB_TENORS, NB_EXPIRIES); for (int looptenor = 0; looptenor < TENORS.size(); looptenor++) { double tenor = TENORS.get(looptenor).get(ChronoUnit.YEARS); for (int loopexpiry = 0; loopexpiry < EXPIRIES.size(); loopexpiry++) { LocalDate expiry = EUR_FIXED_1Y_EURIBOR_6M.FloatingLeg.StartDateBusinessDayAdjustment.adjust(CALIBRATION_DATE.plus(EXPIRIES.get(loopexpiry)), REF_DATA); LocalDate effectiveDate = EUR_FIXED_1Y_EURIBOR_6M.calculateSpotDateFromTradeDate(expiry, REF_DATA); LocalDate endDate = effectiveDate.plus(TENORS.get(looptenor)); SwapTrade swap = EUR_FIXED_1Y_EURIBOR_6M.toTrade(CALIBRATION_DATE, effectiveDate, endDate, BuySell.BUY, 1.0, 0.0); parRate[looptenor][loopexpiry] = SWAP_PRICER.parRate(swap.resolve(REF_DATA).Product, MULTICURVE); ZonedDateTime expiryDateTime = expiry.atTime(11, 0).atZone(ZoneId.of("Europe/Berlin")); double time = calibrated.relativeTime(expiryDateTime); for (int i = 0; i < nbStrikesGraph + 1; i++) { strikesGraph[looptenor][loopexpiry][i] = parRate[looptenor][loopexpiry] + moneyGraph[i]; volLNGraph[looptenor][loopexpiry][i] = calibrated.volatility(expiryDateTime, tenor, strikesGraph[looptenor][loopexpiry][i], parRate[looptenor][loopexpiry]); volNGraph[looptenor][loopexpiry][i] = NormalFormulaRepository.impliedVolatilityFromBlackApproximated(parRate[looptenor][loopexpiry] + shift, strikesGraph[looptenor][loopexpiry][i] + shift, time, volLNGraph[looptenor][loopexpiry][i]); } } } /* Graph export */ string svn = "Moneyness"; for (int looptenor = 0; looptenor < TENORS.size(); looptenor++) { for (int loopexpiry = 0; loopexpiry < EXPIRIES.size(); loopexpiry++) { svn = svn + ", Strike_" + EXPIRIES.get(loopexpiry).ToString() + "x" + TENORS.get(looptenor).ToString() + ", NormalVol_" + EXPIRIES.get(loopexpiry).ToString() + "x" + TENORS.get(looptenor).ToString(); } } svn = svn + "\n"; for (int i = 0; i < nbStrikesGraph + 1; i++) { svn = svn + moneyGraph[i]; for (int looptenor = 0; looptenor < TENORS.size(); looptenor++) { for (int loopexpiry = 0; loopexpiry < EXPIRIES.size(); loopexpiry++) { svn = svn + ", " + strikesGraph[looptenor][loopexpiry][i]; svn = svn + ", " + volNGraph[looptenor][loopexpiry][i]; } } svn = svn + "\n"; } Console.WriteLine(svn); }
public virtual void test_of() { FxOptionVolatilitiesDefinition test = FxOptionVolatilitiesDefinition.of(SPEC); assertEquals(test.Specification, SPEC); assertEquals(test.ParameterCount, SPEC.ParameterCount); assertEquals(test.volatilitiesInputs(), SPEC.volatilitiesInputs()); ZonedDateTime dateTime = LocalDate.of(2017, 9, 25).atStartOfDay().atZone(ZoneId.of("Europe/London")); DoubleArray parameters = DoubleArray.of(0.05, -0.05, 0.15, 0.25, 0.1, -0.1); assertEquals(test.volatilities(dateTime, parameters, REF_DATA), SPEC.volatilities(dateTime, parameters, REF_DATA)); }
//------------------------------------------------------------------------- public virtual void coverage() { BlackFxOptionSurfaceVolatilities test1 = BlackFxOptionSurfaceVolatilities.of(CURRENCY_PAIR, VAL_DATE_TIME, SURFACE); coverImmutableBean(test1); BlackFxOptionSurfaceVolatilities test2 = BlackFxOptionSurfaceVolatilities.of(CURRENCY_PAIR.inverse(), ZonedDateTime.of(2015, 12, 21, 11, 15, 0, 0, ZoneId.of("Z")), SURFACE); coverBeanEquals(test1, test2); }