public virtual void test_QUARTERLY_IMM() { DateSequence test = DateSequences.QUARTERLY_IMM; assertEquals(test.Name, "Quarterly-IMM"); assertEquals(test.ToString(), "Quarterly-IMM"); assertEquals(test.dateMatching(YearMonth.of(2013, 3)), LocalDate.of(2013, 3, 20)); }
/// <summary> /// Parses a year-month from the input string. /// <para> /// Parsing is case insensitive. /// It accepts formats 'yyyy-MM', 'yyyyMM', 'MMM-yyyy' or 'MMMyyyy'. /// Some formats also accept two-digits years (use is not recommended): 'MMM-yy' or 'MMMyy'. /// /// </para> /// </summary> /// <param name="str"> the string to parse </param> /// <returns> the parsed value </returns> /// <exception cref="IllegalArgumentException"> if the string cannot be parsed </exception> public static YearMonth parseYearMonth(string str) { try { // yyyy-MM if (str.Length == 7 && str[4] == '-') { return(YearMonth.parse(str, YYYY_MM_DASH)); } // MMM-yy // MMM-yyyy // MMMyy // MMMyyyy if (str.Length >= 5 && !char.IsDigit(str[0])) { return(YearMonth.parse(str, MMM_YEAR)); } // d/M/yyyy - handle Excel converting YearMonth to date if (str.Length >= 8 && (str[1] == '/' || str[2] == '/')) { LocalDate date = LocalDate.parse(str, D_M_YEAR_SLASH); if (date.DayOfMonth == 1) { return(YearMonth.of(date.Year, date.Month)); } throw new System.ArgumentException("Found Excel-style date but day-of-month was not set to 1:" + str); } // yyyyMM return(YearMonth.parse(str, YYYYMM)); } catch (DateTimeParseException) { throw new System.ArgumentException("Unknown date format, must be formatted as 'yyyy-MM', 'yyyyMM', " + "'MMM-yyyy', 'MMMyyyy', 'MMM-yy' or 'MMMyy' but was: " + str); } }
//------------------------------------------------------------------------- public virtual void createFutureAutoId() { EtdFutureSecurity security = FUTURE_CONTRACT.createFuture(YearMonth.of(2015, 6), EtdVariant.MONTHLY); assertThat(security.SecurityId).isEqualTo(SecurityId.of(EtdIdUtils.ETD_SCHEME, "F-ECAG-FOO-201506")); assertThat(security.Expiry).isEqualTo(YearMonth.of(2015, 6)); assertThat(security.ContractSpecId).isEqualTo(FUTURE_CONTRACT.Id); assertThat(security.Variant).isEqualTo(EtdVariant.MONTHLY); assertThat(security.Info.PriceInfo).isEqualTo(FUTURE_CONTRACT.PriceInfo); }
//------------------------------------------------------------------------- public virtual void createOptionWithUnderlyingAutoId() { EtdOptionSecurity security = OPTION_CONTRACT.createOption(YearMonth.of(2015, 6), EtdVariant.MONTHLY, 0, PutCall.CALL, 123.45, YearMonth.of(2015, 9)); assertThat(security.SecurityId).isEqualTo(SecurityId.of(EtdIdUtils.ETD_SCHEME, "O-IFEN-BAR-201506-C123.45-U201509")); assertThat(security.Expiry).isEqualTo(YearMonth.of(2015, 6)); assertThat(security.ContractSpecId).isEqualTo(OPTION_CONTRACT.Id); assertThat(security.Variant).isEqualTo(EtdVariant.MONTHLY); assertThat(security.PutCall).isEqualTo(PutCall.CALL); assertThat(security.StrikePrice).isEqualTo(123.45); assertThat(security.UnderlyingExpiryMonth).hasValue(YearMonth.of(2015, 9)); assertThat(security.Info.PriceInfo).isEqualTo(OPTION_CONTRACT.PriceInfo); }
public virtual void test_parseYearMonth() { assertEquals(LoaderUtils.parseYearMonth("2012-06"), YearMonth.of(2012, 6)); assertEquals(LoaderUtils.parseYearMonth("201206"), YearMonth.of(2012, 6)); assertEquals(LoaderUtils.parseYearMonth("Jun-2012"), YearMonth.of(2012, 6)); assertEquals(LoaderUtils.parseYearMonth("Jun-12"), YearMonth.of(2012, 6)); assertEquals(LoaderUtils.parseYearMonth("Jun2012"), YearMonth.of(2012, 6)); assertEquals(LoaderUtils.parseYearMonth("Jun12"), YearMonth.of(2012, 6)); assertEquals(LoaderUtils.parseYearMonth("1/6/2012"), YearMonth.of(2012, 6)); assertEquals(LoaderUtils.parseYearMonth("01/6/2012"), YearMonth.of(2012, 6)); assertEquals(LoaderUtils.parseYearMonth("1/06/2012"), YearMonth.of(2012, 6)); assertEquals(LoaderUtils.parseYearMonth("01/06/2012"), YearMonth.of(2012, 6)); assertThrowsIllegalArg(() => LoaderUtils.parseYearMonth("2/6/2012")); assertThrowsIllegalArg(() => LoaderUtils.parseYearMonth("1/6/12")); assertThrowsIllegalArg(() => LoaderUtils.parseYearMonth("Jun1")); assertThrowsIllegalArg(() => LoaderUtils.parseYearMonth("12345678")); assertThrowsIllegalArg(() => LoaderUtils.parseYearMonth("Rubbish")); }
public virtual void test_wrongMonthOrder() { assertThrowsIllegalArg(() => InflationInterpolatedRateComputation.of(GB_HICP, END_MONTH_FIRST, START_MONTH_FIRST, WEIGHT)); assertThrowsIllegalArg(() => InflationInterpolatedRateComputation.meta().builder().set(InflationInterpolatedRateComputation.meta().startObservation(), PriceIndexObservation.of(GB_HICP, YearMonth.of(2010, 1))).set(InflationInterpolatedRateComputation.meta().startSecondObservation(), PriceIndexObservation.of(GB_HICP, YearMonth.of(2010, 1))).set(InflationInterpolatedRateComputation.meta().endObservation(), PriceIndexObservation.of(GB_HICP, YearMonth.of(2010, 7))).set(InflationInterpolatedRateComputation.meta().endSecondObservation(), PriceIndexObservation.of(GB_HICP, YearMonth.of(2010, 8))).set(InflationInterpolatedRateComputation.meta().weight(), WEIGHT).build()); assertThrowsIllegalArg(() => InflationInterpolatedRateComputation.meta().builder().set(InflationInterpolatedRateComputation.meta().startObservation(), PriceIndexObservation.of(GB_HICP, YearMonth.of(2010, 1))).set(InflationInterpolatedRateComputation.meta().startSecondObservation(), PriceIndexObservation.of(GB_HICP, YearMonth.of(2010, 2))).set(InflationInterpolatedRateComputation.meta().endObservation(), PriceIndexObservation.of(GB_HICP, YearMonth.of(2010, 7))).set(InflationInterpolatedRateComputation.meta().endSecondObservation(), PriceIndexObservation.of(GB_HICP, YearMonth.of(2010, 7))).set(InflationInterpolatedRateComputation.meta().weight(), WEIGHT).build()); assertThrowsIllegalArg(() => InflationInterpolatedRateComputation.meta().builder().set(InflationInterpolatedRateComputation.meta().startObservation(), PriceIndexObservation.of(GB_HICP, YearMonth.of(2010, 8))).set(InflationInterpolatedRateComputation.meta().startSecondObservation(), PriceIndexObservation.of(GB_HICP, YearMonth.of(2010, 9))).set(InflationInterpolatedRateComputation.meta().endObservation(), PriceIndexObservation.of(GB_HICP, YearMonth.of(2010, 7))).set(InflationInterpolatedRateComputation.meta().endSecondObservation(), PriceIndexObservation.of(GB_HICP, YearMonth.of(2010, 8))).set(InflationInterpolatedRateComputation.meta().weight(), WEIGHT).build()); }
public virtual void createOptionFromFutureContractSpec() { assertThatThrownBy(() => FUTURE_CONTRACT.createOption(YearMonth.of(2015, 6), EtdVariant.MONTHLY, 0, PutCall.CALL, 123.45)).isInstanceOf(typeof(System.InvalidOperationException)).hasMessage("Cannot create an EtdOptionSecurity from a contract specification of type 'Future'"); }
internal static EtdFutureSecurity sut2() { return(EtdFutureSecurity.builder().info(SecurityInfo.of(SecurityId.of("B", "C"), SecurityPriceInfo.of(Currency.EUR, 10))).contractSpecId(EtdContractSpecId.of("test", "234")).expiry(YearMonth.of(2017, 9)).variant(EtdVariant.ofWeekly(2)).build()); }
//------------------------------------------------------------------------- public virtual void test_compareKey() { InflationRateSensitivity a1 = InflationRateSensitivity.of(GB_HICP_OBS, 32d); InflationRateSensitivity a2 = InflationRateSensitivity.of(GB_HICP_OBS, 32d); InflationRateSensitivity b = InflationRateSensitivity.of(CH_CPI_OBS, 32d); InflationRateSensitivity c = InflationRateSensitivity.of(GB_HICP_OBS, USD, 32d); InflationRateSensitivity d = InflationRateSensitivity.of(PriceIndexObservation.of(GB_HICP, YearMonth.of(2015, 10)), 32d); ZeroRateSensitivity other = ZeroRateSensitivity.of(GBP, 2d, 32d); assertEquals(a1.compareKey(a2), 0); assertEquals(a1.compareKey(b) > 0, true); assertEquals(b.compareKey(a1) < 0, true); assertEquals(a1.compareKey(c) < 0, true); assertEquals(c.compareKey(a1) > 0, true); assertEquals(a1.compareKey(d) < 0, true); assertEquals(d.compareKey(a1) > 0, true); assertEquals(a1.compareKey(other) < 0, true); assertEquals(other.compareKey(a1) > 0, true); }
public virtual void createFutureFromOptionContractSpec() { assertThatThrownBy(() => OPTION_CONTRACT.createFuture(YearMonth.of(2015, 6), EtdVariant.MONTHLY)).isInstanceOf(typeof(System.InvalidOperationException)).hasMessage("Cannot create an EtdFutureSecurity from a contract specification of type 'Option'"); }
//------------------------------------------------------------------------- public virtual void test_parse_future() { EtdContractSpecId specId = EtdContractSpecId.of("OG-ETD", "F-ECAG-FGBL"); EtdContractSpec contract = EtdContractSpec.builder().id(specId).type(EtdType.FUTURE).exchangeId(ExchangeIds.ECAG).contractCode(FGBL).description("Dummy").priceInfo(SecurityPriceInfo.of(Currency.GBP, 100)).build(); ReferenceData refData = ImmutableReferenceData.of(specId, contract); PositionCsvLoader test = PositionCsvLoader.of(refData); ValueWithFailures <IList <EtdFuturePosition> > trades = test.parse(ImmutableList.of(FILE.CharSource), typeof(EtdFuturePosition)); IList <EtdFuturePosition> filtered = trades.Value; assertEquals(filtered.Count, 4); EtdFuturePosition expected1 = EtdFuturePosition.builder().info(PositionInfo.builder().id(StandardId.of("OG", "123421")).build()).security(EtdFutureSecurity.of(contract, YearMonth.of(2017, 6), EtdVariant.ofMonthly())).longQuantity(15d).shortQuantity(2d).build(); assertBeanEquals(expected1, filtered[0]); EtdFuturePosition expected2 = EtdFuturePosition.builder().info(PositionInfo.builder().id(StandardId.of("OG", "123422")).build()).security(EtdFutureSecurity.of(contract, YearMonth.of(2017, 6), EtdVariant.ofFlexFuture(13, EtdSettlementType.CASH))).longQuantity(0d).shortQuantity(13d).build(); assertBeanEquals(expected2, filtered[1]); EtdFuturePosition expected3 = EtdFuturePosition.builder().info(PositionInfo.builder().id(StandardId.of("OG", "123423")).build()).security(EtdFutureSecurity.of(contract, YearMonth.of(2017, 6), EtdVariant.ofWeekly(2))).longQuantity(0d).shortQuantity(20d).build(); assertBeanEquals(expected3, filtered[2]); EtdFuturePosition expected4 = EtdFuturePosition.builder().info(PositionInfo.builder().id(StandardId.of("OG", "123424")).build()).security(EtdFutureSecurity.of(contract, YearMonth.of(2017, 6), EtdVariant.ofDaily(3))).longQuantity(30d).shortQuantity(0d).build(); assertBeanEquals(expected4, filtered[3]); }
//------------------------------------------------------------------------- public virtual void test_parseLightweight() { PositionCsvLoader test = PositionCsvLoader.standard(); ValueWithFailures <IList <SecurityPosition> > trades = test.parseLightweight(ImmutableList.of(FILE.CharSource)); IList <SecurityPosition> filtered = trades.Value; assertEquals(filtered.Count, 10); assertBeanEquals(SECURITY1, filtered[0]); assertBeanEquals(SECURITY2, filtered[1]); assertBeanEquals(SECURITY3, filtered[2]); SecurityPosition expected3 = SecurityPosition.builder().info(PositionInfo.builder().id(StandardId.of("OG", "123421")).build()).securityId(EtdIdUtils.futureId(ExchangeIds.ECAG, FGBL, YearMonth.of(2017, 6), EtdVariant.ofMonthly())).longQuantity(15d).shortQuantity(2d).build(); assertBeanEquals(expected3, filtered[3]); SecurityPosition expected4 = SecurityPosition.builder().info(PositionInfo.builder().id(StandardId.of("OG", "123422")).build()).securityId(EtdIdUtils.futureId(ExchangeIds.ECAG, FGBL, YearMonth.of(2017, 6), EtdVariant.ofFlexFuture(13, EtdSettlementType.CASH))).longQuantity(0d).shortQuantity(13d).build(); assertBeanEquals(expected4, filtered[4]); SecurityPosition expected5 = SecurityPosition.builder().info(PositionInfo.builder().id(StandardId.of("OG", "123423")).build()).securityId(EtdIdUtils.futureId(ExchangeIds.ECAG, FGBL, YearMonth.of(2017, 6), EtdVariant.ofWeekly(2))).longQuantity(0d).shortQuantity(20d).build(); assertBeanEquals(expected5, filtered[5]); SecurityPosition expected6 = SecurityPosition.builder().info(PositionInfo.builder().id(StandardId.of("OG", "123424")).build()).securityId(EtdIdUtils.futureId(ExchangeIds.ECAG, FGBL, YearMonth.of(2017, 6), EtdVariant.ofDaily(3))).longQuantity(30d).shortQuantity(0d).build(); assertBeanEquals(expected6, filtered[6]); SecurityPosition expected7 = SecurityPosition.builder().info(PositionInfo.builder().id(StandardId.of("OG", "123431")).build()).securityId(EtdIdUtils.optionId(ExchangeIds.ECAG, OGBL, YearMonth.of(2017, 6), EtdVariant.ofMonthly(), 0, PutCall.PUT, 3d, YearMonth.of(2017, 9))).longQuantity(15d).shortQuantity(2d).build(); assertBeanEquals(expected7, filtered[7]); SecurityPosition expected8 = SecurityPosition.builder().info(PositionInfo.builder().id(StandardId.of("OG", "123432")).build()).securityId(EtdIdUtils.optionId(ExchangeIds.ECAG, OGBL, YearMonth.of(2017, 6), EtdVariant.ofFlexOption(13, EtdSettlementType.CASH, EtdOptionType.AMERICAN), 0, PutCall.CALL, 4d)).longQuantity(0d).shortQuantity(13d).build(); assertBeanEquals(expected8, filtered[8]); SecurityPosition expected9 = SecurityPosition.builder().info(PositionInfo.builder().id(StandardId.of("OG", "123433")).build()).securityId(EtdIdUtils.optionId(ExchangeIds.ECAG, OGBL, YearMonth.of(2017, 6), EtdVariant.ofWeekly(2), 0, PutCall.PUT, 5.1d)).longQuantity(0d).shortQuantity(20d).build(); assertBeanEquals(expected9, filtered[9]); }
public virtual void test_futureId_flex() { SecurityId test = EtdIdUtils.futureId(ExchangeIds.ECAG, FGBS, YearMonth.of(2017, 6), EtdVariant.ofFlexFuture(26, EtdSettlementType.DERIVATIVE)); assertEquals(test.StandardId, StandardId.of("OG-ETD", "F-ECAG-FGBS-20170626D")); }
//------------------------------------------------------------------------- internal static EtdFutureSecurity sut() { return(EtdFutureSecurity.builder().info(SecurityInfo.of(SecurityId.of("A", "B"), SecurityPriceInfo.of(Currency.GBP, 100))).contractSpecId(EtdContractSpecId.of("test", "123")).expiry(YearMonth.of(2017, 6)).build()); }
//------------------------------------------------------------------------- public virtual void test_futureId_monthly() { SecurityId test = EtdIdUtils.futureId(ExchangeIds.ECAG, FGBS, YearMonth.of(2017, 6), MONTHLY); assertEquals(test.StandardId, StandardId.of("OG-ETD", "F-ECAG-FGBS-201706")); }
public virtual void test_futureId_daily() { SecurityId test = EtdIdUtils.futureId(ExchangeIds.ECAG, FGBS, YearMonth.of(2017, 6), EtdVariant.ofDaily(2)); assertEquals(test.StandardId, StandardId.of("OG-ETD", "F-ECAG-FGBS-20170602")); }
public virtual void test_optionIdUnderlying_daily9_version() { SecurityId test = EtdIdUtils.optionId(ExchangeIds.ECAG, FGBS, YearMonth.of(2017, 6), EtdVariant.ofDaily(9), 3, PutCall.PUT, 12.34, YearMonth.of(2017, 9)); assertEquals(test.StandardId, StandardId.of("OG-ETD", "O-ECAG-FGBS-20170609-V3-P12.34-U201709")); }
internal static EtdOptionSecurity sut2() { return(EtdOptionSecurity.builder().info(SecurityInfo.of(SecurityId.of("B", "C"), SecurityPriceInfo.of(Currency.EUR, 10))).contractSpecId(EtdContractSpecId.of("test", "234")).expiry(YearMonth.of(2017, 9)).variant(EtdVariant.ofWeekly(2)).version(4).putCall(PutCall.CALL).strikePrice(3).underlyingExpiryMonth(YearMonth.of(2017, 12)).build()); }
//------------------------------------------------------------------------- internal static EtdOptionSecurity sut() { return(EtdOptionSecurity.builder().info(SecurityInfo.of(SecurityId.of("A", "B"), SecurityPriceInfo.of(Currency.GBP, 100))).contractSpecId(EtdContractSpecId.of("test", "123")).expiry(YearMonth.of(2017, 6)).putCall(PutCall.PUT).strikePrice(2).build()); }
//------------------------------------------------------------------------- public virtual void coverage() { InflationInterpolatedRateComputation test1 = InflationInterpolatedRateComputation.of(GB_HICP, START_MONTH_FIRST, END_MONTH_FIRST, WEIGHT); coverImmutableBean(test1); InflationInterpolatedRateComputation test2 = InflationInterpolatedRateComputation.of(CH_CPI, YearMonth.of(2010, 1), YearMonth.of(2010, 7), WEIGHT + 0.1d); coverBeanEquals(test1, test2); }
public virtual void test_optionId_weekly() { SecurityId test = EtdIdUtils.optionId(ExchangeIds.ECAG, FGBS, YearMonth.of(2017, 6), EtdVariant.ofWeekly(3), 0, PutCall.CALL, -1.45); assertEquals(test.StandardId, StandardId.of("OG-ETD", "O-ECAG-FGBS-201706W3-CM1.45")); }
//------------------------------------------------------------------------- public virtual void coverage() { InflationEndMonthRateComputation test1 = InflationEndMonthRateComputation.of(GB_HICP, START_INDEX, END_MONTH); coverImmutableBean(test1); InflationEndMonthRateComputation test2 = InflationEndMonthRateComputation.of(CH_CPI, 2324d, YearMonth.of(2015, 4)); coverBeanEquals(test1, test2); }
public virtual void test_optionId_daily21_version() { SecurityId test = EtdIdUtils.optionId(ExchangeIds.ECAG, FGBS, YearMonth.of(2017, 6), EtdVariant.ofDaily(21), 11, PutCall.PUT, 12.34); assertEquals(test.StandardId, StandardId.of("OG-ETD", "O-ECAG-FGBS-20170621-V11-P12.34")); }
//------------------------------------------------------------------------- public virtual void test_parse_option() { EtdContractSpecId specId = EtdContractSpecId.of("OG-ETD", "O-ECAG-OGBL"); EtdContractSpec contract = EtdContractSpec.builder().id(specId).type(EtdType.OPTION).exchangeId(ExchangeIds.ECAG).contractCode(OGBL).description("Dummy").priceInfo(SecurityPriceInfo.of(Currency.GBP, 100)).build(); ReferenceData refData = ImmutableReferenceData.of(specId, contract); PositionCsvLoader test = PositionCsvLoader.of(refData); ValueWithFailures <IList <EtdOptionPosition> > trades = test.parse(ImmutableList.of(FILE.CharSource), typeof(EtdOptionPosition)); IList <EtdOptionPosition> filtered = trades.Value; assertEquals(filtered.Count, 3); EtdOptionPosition expected1 = EtdOptionPosition.builder().info(PositionInfo.builder().id(StandardId.of("OG", "123431")).build()).security(EtdOptionSecurity.of(contract, YearMonth.of(2017, 6), EtdVariant.ofMonthly(), 0, PutCall.PUT, 3d, YearMonth.of(2017, 9))).longQuantity(15d).shortQuantity(2d).build(); assertBeanEquals(expected1, filtered[0]); EtdOptionPosition expected2 = EtdOptionPosition.builder().info(PositionInfo.builder().id(StandardId.of("OG", "123432")).build()).security(EtdOptionSecurity.of(contract, YearMonth.of(2017, 6), EtdVariant.ofFlexOption(13, EtdSettlementType.CASH, EtdOptionType.AMERICAN), 0, PutCall.CALL, 4d)).longQuantity(0d).shortQuantity(13d).build(); assertBeanEquals(expected2, filtered[1]); EtdOptionPosition expected3 = EtdOptionPosition.builder().info(PositionInfo.builder().id(StandardId.of("OG", "123433")).build()).security(EtdOptionSecurity.of(contract, YearMonth.of(2017, 6), EtdVariant.ofWeekly(2), 0, PutCall.PUT, 5.1d)).longQuantity(0d).shortQuantity(20d).build(); assertBeanEquals(expected3, filtered[2]); }
public virtual void test_wrongMonthOrder() { assertThrowsIllegalArg(() => InflationEndInterpolatedRateComputation.meta().builder().set(InflationEndInterpolatedRateComputation.meta().startIndexValue(), START_INDEX).set(InflationEndInterpolatedRateComputation.meta().endObservation(), PriceIndexObservation.of(GB_HICP, YearMonth.of(2010, 7))).set(InflationEndInterpolatedRateComputation.meta().endSecondObservation(), PriceIndexObservation.of(GB_HICP, YearMonth.of(2010, 7))).set(InflationEndInterpolatedRateComputation.meta().weight(), WEIGHT).build()); }
//------------------------------------------------------------------------- public virtual void test_optionId_monthly() { SecurityId test = EtdIdUtils.optionId(ExchangeIds.ECAG, FGBS, YearMonth.of(2017, 6), MONTHLY, 0, PutCall.PUT, 12.34); assertEquals(test.StandardId, StandardId.of("OG-ETD", "O-ECAG-FGBS-201706-P12.34")); }
//------------------------------------------------------------------------- public virtual void coverage() { YearMonthDateParameterMetadata test = YearMonthDateParameterMetadata.of(DATE, JAN2015); coverImmutableBean(test); YearMonthDateParameterMetadata test2 = YearMonthDateParameterMetadata.of(date(2014, 1, 1), YearMonth.of(2016, 2)); coverBeanEquals(test, test2); }