/// <summary> /// Restricted copy constructor. </summary> /// <param name="beanToCopy"> the bean to copy from, not null </param> internal Builder(EtdFutureTrade beanToCopy) { this.info_Renamed = beanToCopy.Info; this.security_Renamed = beanToCopy.Security; this.quantity_Renamed = beanToCopy.Quantity; this.price_Renamed = beanToCopy.Price; }
public override Builder set(string propertyName, object newValue) { switch (propertyName.GetHashCode()) { case 3237038: // info this.info_Renamed = (TradeInfo)newValue; break; case 949122880: // security this.security_Renamed = (EtdFutureSecurity)newValue; break; case -1285004149: // quantity this.quantity_Renamed = (double?)newValue.Value; break; case 106934601: // price this.price_Renamed = (double?)newValue.Value; break; default: throw new NoSuchElementException("Unknown property: " + propertyName); } return(this); }
/// <summary> /// Restricted copy constructor. </summary> /// <param name="beanToCopy"> the bean to copy from, not null </param> internal Builder(EtdFuturePosition beanToCopy) { this.info_Renamed = beanToCopy.Info; this.security_Renamed = beanToCopy.Security; this.longQuantity_Renamed = beanToCopy.LongQuantity; this.shortQuantity_Renamed = beanToCopy.ShortQuantity; }
public override Builder set(string propertyName, object newValue) { switch (propertyName.GetHashCode()) { case 3237038: // info this.info_Renamed = (PositionInfo)newValue; break; case 949122880: // security this.security_Renamed = (EtdFutureSecurity)newValue; break; case 611668775: // longQuantity this.longQuantity_Renamed = (double?)newValue.Value; break; case -2094395097: // shortQuantity this.shortQuantity_Renamed = (double?)newValue.Value; break; default: throw new NoSuchElementException("Unknown property: " + propertyName); } return(this); }
/// <summary> /// Obtains an instance from position information, security and net quantity. /// <para> /// The net quantity is the long quantity minus the short quantity, which may be negative. /// If the quantity is positive it is treated as a long quantity. /// Otherwise it is treated as a short quantity. /// /// </para> /// </summary> /// <param name="positionInfo"> the position information </param> /// <param name="security"> the underlying security </param> /// <param name="netQuantity"> the net quantity of the underlying security </param> /// <returns> the position </returns> public static EtdFuturePosition ofNet(PositionInfo positionInfo, EtdFutureSecurity security, double netQuantity) { double longQuantity = netQuantity >= 0 ? netQuantity : 0; double shortQuantity = netQuantity >= 0 ? 0 : -netQuantity; return(new EtdFuturePosition(positionInfo, security, longQuantity, shortQuantity)); }
private EtdFutureTrade(TradeInfo info, EtdFutureSecurity security, double quantity, double price) { JodaBeanUtils.notNull(info, "info"); JodaBeanUtils.notNull(security, "security"); this.info = info; this.security = security; this.quantity = quantity; this.price = price; }
//------------------------------------------------------------------------- /// <summary> /// Obtains an instance from a contract specification, expiry year-month and variant. /// <para> /// The security identifier will be automatically created using <seealso cref="EtdIdUtils"/>. /// The specification must be for a future. /// /// </para> /// </summary> /// <param name="spec"> the future contract specification </param> /// <param name="expiry"> the expiry year-month of the future </param> /// <param name="variant"> the variant of the ETD, such as 'Monthly', 'Weekly, 'Daily' or 'Flex' </param> /// <returns> a future security based on this contract specification </returns> /// <exception cref="IllegalStateException"> if the product type of the contract specification is not {@code FUTURE} </exception> public static EtdFutureSecurity of(EtdContractSpec spec, YearMonth expiry, EtdVariant variant) { if (spec.Type != EtdType.FUTURE) { throw new System.InvalidOperationException(Messages.format("Cannot create an EtdFutureSecurity from a contract specification of type '{}'", spec.Type)); } SecurityId securityId = EtdIdUtils.futureId(spec.ExchangeId, spec.ContractCode, expiry, variant); return(EtdFutureSecurity.builder().info(SecurityInfo.of(securityId, spec.PriceInfo)).contractSpecId(spec.Id).expiry(expiry).variant(variant).build()); }
//------------------------------------------------------------------------- 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); }
private EtdFuturePosition(PositionInfo info, EtdFutureSecurity security, double longQuantity, double shortQuantity) { JodaBeanUtils.notNull(info, "info"); JodaBeanUtils.notNull(security, "security"); ArgChecker.notNegative(longQuantity, "longQuantity"); ArgChecker.notNegative(shortQuantity, "shortQuantity"); this.info = info; this.security = security; this.longQuantity = longQuantity; this.shortQuantity = shortQuantity; }
public virtual void test() { EtdFutureSecurity test = sut(); assertEquals(test.Variant, EtdVariant.MONTHLY); assertEquals(test.Type, EtdType.FUTURE); assertEquals(test.Currency, Currency.GBP); assertEquals(test.UnderlyingIds, ImmutableSet.of()); assertEquals(test.createProduct(REF_DATA), test); assertEquals(test.createTrade(TradeInfo.empty(), 1, 2, ReferenceData.empty()), EtdFutureTrade.of(TradeInfo.empty(), test, 1, 2)); assertEquals(test.createPosition(PositionInfo.empty(), 1, ReferenceData.empty()), EtdFuturePosition.ofNet(PositionInfo.empty(), test, 1)); assertEquals(test.createPosition(PositionInfo.empty(), 1, 2, ReferenceData.empty()), EtdFuturePosition.ofLongShort(PositionInfo.empty(), test, 1, 2)); }
public override bool Equals(object obj) { if (obj == this) { return(true); } if (obj != null && obj.GetType() == this.GetType()) { EtdFutureSecurity other = (EtdFutureSecurity)obj; return(JodaBeanUtils.equal(info, other.info) && JodaBeanUtils.equal(contractSpecId, other.contractSpecId) && JodaBeanUtils.equal(expiry, other.expiry) && JodaBeanUtils.equal(variant, other.variant)); } return(false); }
//------------------------------------------------------------------------- /// <summary> /// Creates a future security based on this contract specification. /// <para> /// The security identifier will be automatically created using <seealso cref="EtdIdUtils"/>. /// The <seealso cref="#getType() type"/> must be <seealso cref="EtdType#FUTURE"/> otherwise an exception will be thrown. /// /// </para> /// </summary> /// <param name="expiryMonth"> the expiry month of the future </param> /// <param name="variant"> the variant of the ETD, such as 'Monthly', 'Weekly, 'Daily' or 'Flex' </param> /// <returns> a future security based on this contract specification </returns> /// <exception cref="IllegalStateException"> if the product type of the contract specification is not {@code FUTURE} </exception> public EtdFutureSecurity createFuture(YearMonth expiryMonth, EtdVariant variant) { return(EtdFutureSecurity.of(this, expiryMonth, variant)); }
//------------------------------------------------------------------------- /// <summary> /// Obtains an instance from the security and net quantity. /// <para> /// The net quantity is the long quantity minus the short quantity, which may be negative. /// If the quantity is positive it is treated as a long quantity. /// Otherwise it is treated as a short quantity. /// /// </para> /// </summary> /// <param name="security"> the underlying security </param> /// <param name="netQuantity"> the net quantity of the underlying security </param> /// <returns> the position </returns> public static EtdFuturePosition ofNet(EtdFutureSecurity security, double netQuantity) { return(ofNet(PositionInfo.empty(), security, netQuantity)); }
/// <summary> /// Sets the underlying security. </summary> /// <param name="security"> the new value, not null </param> /// <returns> this, for chaining, not null </returns> public Builder security(EtdFutureSecurity security) { JodaBeanUtils.notNull(security, "security"); this.security_Renamed = security; return(this); }
//------------------------------------------------------------------------- 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()); }
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()); }
/// <summary> /// Obtains an instance from position information, security, long quantity and short quantity. /// <para> /// The long quantity and short quantity must be zero or positive, not negative. /// In many cases, only a long quantity or short quantity will be present with the other set to zero. /// However it is also possible for both to be non-zero, allowing long and short positions to be treated separately. /// /// </para> /// </summary> /// <param name="positionInfo"> the position information </param> /// <param name="security"> the underlying security </param> /// <param name="longQuantity"> the long quantity of the underlying security </param> /// <param name="shortQuantity"> the short quantity of the underlying security </param> /// <returns> the position </returns> public static EtdFuturePosition ofLongShort(PositionInfo positionInfo, EtdFutureSecurity security, double longQuantity, double shortQuantity) { return(new EtdFuturePosition(positionInfo, security, longQuantity, shortQuantity)); }
/// <summary> /// Obtains an instance from the security, long quantity and short quantity. /// <para> /// The long quantity and short quantity must be zero or positive, not negative. /// In many cases, only a long quantity or short quantity will be present with the other set to zero. /// However it is also possible for both to be non-zero, allowing long and short positions to be treated separately. /// /// </para> /// </summary> /// <param name="security"> the underlying security </param> /// <param name="longQuantity"> the long quantity of the underlying security </param> /// <param name="shortQuantity"> the short quantity of the underlying security </param> /// <returns> the position </returns> public static EtdFuturePosition ofLongShort(EtdFutureSecurity security, double longQuantity, double shortQuantity) { return(ofLongShort(PositionInfo.empty(), security, longQuantity, shortQuantity)); }
//------------------------------------------------------------------------- /// <summary> /// Obtains an instance from trade information, security, quantity and price. /// </summary> /// <param name="tradeInfo"> the trade information </param> /// <param name="security"> the security that was traded </param> /// <param name="quantity"> the quantity that was traded </param> /// <param name="price"> the price that was traded </param> /// <returns> the trade </returns> public static EtdFutureTrade of(TradeInfo tradeInfo, EtdFutureSecurity security, double quantity, double price) { return(new EtdFutureTrade(tradeInfo, security, quantity, price)); }