/** * Obtains an instance from a contract specification, expiry year-month and variant. * <p> * The security identifier will be automatically created using {@link EtdIdUtils}. * The specification must be for a future. * * @param spec the future contract specification * @param expiry the expiry year-month of the future * @param variant the variant of the ETD, such as 'Monthly', 'Weekly, 'Daily' or 'Flex' * @return a future security based on this contract specification * @throws IllegalStateException if the product type of the contract specification is not {@code FUTURE} */ public static EtdFutureSecurity of(EtdContractSpec spec, YearMonth expiry, EtdVariant variant) { if (spec.getType() != EtdType.FUTURE) { throw new IllegalStateException( Messages.format("Cannot create an EtdFutureSecurity from a contract specification of type '{}'", spec.getType())); } SecurityId securityId = EtdIdUtils.futureId(spec.getExchangeId(), spec.getContractCode(), expiry, variant); return EtdFutureSecurity.builder() .info(SecurityInfo.of(securityId, spec.getPriceInfo())) .contractSpecId(spec.getId()) .expiry(expiry) .variant(variant) .build(); }
/** * Returns a builder that allows this bean to be mutated. * @return the mutable builder, not null */ public Builder toBuilder() { return new Builder(this); }
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(); }
@Override public EtdFutureSecurity.Builder builder() { return new EtdFutureSecurity.Builder(); }
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(); }
/** * Returns a builder used to create an instance of the bean. * @return the builder, not null */ public static EtdFutureSecurity.Builder builder() { return new EtdFutureSecurity.Builder(); }