//------------------------------------------------------------------------- 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]); }
// parse the position info private PositionInfo parsePositionInfo(CsvRow row) { PositionInfoBuilder infoBuilder = PositionInfo.builder(); string scheme = row.findField(ID_SCHEME_FIELD).orElse(DEFAULT_POSITION_SCHEME); row.findValue(ID_FIELD).ifPresent(id => infoBuilder.id(StandardId.of(scheme, id))); resolver.parsePositionInfo(row, infoBuilder); return(infoBuilder.build()); }
//------------------------------------------------------------------------- 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_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]); }