private Object readResolve() { return of(standardId); }
/** * Obtains an instance from a scheme and value. * <p> * The scheme and value are used to produce a {@link StandardId}, where more * information is available on how schemes and values relate to industry identifiers. * <p> * The scheme must be non-empty and match the regular expression '{@code [A-Za-z0-9:/+.=_-]*}'. * This permits letters, numbers, colon, forward-slash, plus, dot, equals, underscore and dash. * If necessary, the scheme can be encoded using {@link StandardId#encodeScheme(String)}. * <p> * The value must be non-empty and match the regular expression '{@code [!-z][ -z]*}'. * * @param scheme the scheme of the identifier, not empty * @param value the value of the identifier, not empty * @return the identifier * @throws IllegalArgumentException if the scheme or value is invalid */ public static EtdContractSpecId of(String scheme, String value) { return of(StandardId.of(scheme, value)); }
/** * Creates an identifier for a contract specification. * <p> * This will have the format: * {@code 'OG-ETD~F-ECAG-FGBS'} or {@code 'OG-ETD~O-ECAG-OGBS'}. * * @param type type of the contract - future or option * @param exchangeId the MIC code of the exchange where the instruments are traded * @param contractCode the code supplied by the exchange for use in clearing and margining, such as in SPAN * @return the identifier */ public static EtdContractSpecId contractSpecId(EtdType type, ExchangeId exchangeId, EtdContractCode contractCode) { ArgChecker.notNull(type, "type"); ArgChecker.notNull(exchangeId, "exchangeId"); ArgChecker.notNull(contractCode, "contractCode"); switch (type) { case FUTURE: return EtdContractSpecId.of(ETD_SCHEME, FUT_PREFIX + exchangeId + SEPARATOR + contractCode); case OPTION: return EtdContractSpecId.of(ETD_SCHEME, OPT_PREFIX + exchangeId + SEPARATOR + contractCode); default: throw new IllegalArgumentException("Unknown ETD type: " + type); } }
public void test_serialization() { EtdContractSpecId test = EtdContractSpecId.of("A", "B"); assertSerialization(test); }
public void test_equalsHashCode() { EtdContractSpecId a = EtdContractSpecId.of(StandardId.of("A", "B")); EtdContractSpecId a2 = EtdContractSpecId.of(StandardId.of("A", "B")); EtdContractSpecId b = EtdContractSpecId.of(StandardId.of("C", "D")); assertEquals(a.hashCode(), a2.hashCode()); assertEquals(a.equals(a), true); assertEquals(a.equals(a2), true); assertEquals(a.equals(b), false); assertEquals(a.equals(null), false); assertEquals(a.equals(ANOTHER_TYPE), false); }
public void test_of() { EtdContractSpecId test = EtdContractSpecId.of(StandardId.of("A", "B")); assertEquals(test.getStandardId(), StandardId.of("A", "B")); assertEquals(test.getReferenceDataType(), EtdContractSpec.class); assertEquals(test.toString(), "A~B"); }
public void test_load_invalidNoQuantity() { 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<List<Position>> trades = test.parse( ImmutableList.of(CharSource.wrap("Strata Position Type,Exchange,Contract Code,Expiry\nFUT,ECAG,FGBL,2017-06"))); assertEquals(trades.getFailures().size(), 1); FailureItem failure = trades.getFailures().get(0); assertEquals(failure.getReason(), FailureReason.PARSING); assertEquals(failure.getMessage(), "CSV file position could not be parsed at line 2: " + "Security must contain a quantity column, either 'Quantity' or 'Long Quantity' and 'Short Quantity'"); }
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(); }
static EtdContractSpec sut() { return EtdContractSpec.builder() .id(EtdContractSpecId.of("test", "123")) .type(EtdType.FUTURE) .exchangeId(ExchangeIds.ECAG) .contractCode(EtdContractCode.of("FOO")) .description("A test future template") .priceInfo(SecurityPriceInfo.of(Currency.GBP, 100)) .build(); }
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(); }
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(); }
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(); }
public void test_parse_option() { EtdContractSpecId specId = EtdContractSpecId.of("OG-ETD", "O-ECAG-OGBL"); EtdContractSpec contract = EtdContractSpec.builder() .id(specId)
public void test_parse_future() { EtdContractSpecId specId = EtdContractSpecId.of("OG-ETD", "F-ECAG-FGBL"); EtdContractSpec contract = EtdContractSpec.builder() .id(specId)