/// <summary> /// Restricted copy constructor. </summary> /// <param name="beanToCopy"> the bean to copy from, not null </param> internal Builder(EtdOptionPosition beanToCopy) { this.info_Renamed = beanToCopy.Info; this.security_Renamed = beanToCopy.Security; this.longQuantity_Renamed = beanToCopy.LongQuantity; this.shortQuantity_Renamed = beanToCopy.ShortQuantity; }
/// <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 EtdOptionPosition ofNet(PositionInfo positionInfo, EtdOptionSecurity security, double netQuantity) { double longQuantity = netQuantity >= 0 ? netQuantity : 0; double shortQuantity = netQuantity >= 0 ? 0 : -netQuantity; return(new EtdOptionPosition(positionInfo, security, longQuantity, shortQuantity)); }
/// <summary> /// Restricted copy constructor. </summary> /// <param name="beanToCopy"> the bean to copy from, not null </param> internal Builder(EtdOptionTrade 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 = (PositionInfo)newValue; break; case 949122880: // security this.security_Renamed = (EtdOptionSecurity)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); }
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 = (EtdOptionSecurity)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); }
private EtdOptionTrade(TradeInfo info, EtdOptionSecurity 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, variant, /// version, put/call, strike price and underlying expiry. /// <para> /// The security identifier will be automatically created using <seealso cref="EtdIdUtils"/>. /// The specification must be for an option. /// /// </para> /// </summary> /// <param name="spec"> the option contract specification </param> /// <param name="expiry"> the expiry year-month of the option </param> /// <param name="variant"> the variant of the ETD, such as 'Monthly', 'Weekly, 'Daily' or 'Flex' </param> /// <param name="version"> the non-negative version, zero if versioning does not apply </param> /// <param name="putCall"> whether the option is a put or call </param> /// <param name="strikePrice"> the strike price of the option </param> /// <param name="underlyingExpiryMonth"> the expiry of the underlying instrument, such as a future, may be null </param> /// <returns> an option security based on this contract specification </returns> /// <exception cref="IllegalStateException"> if the product type of the contract specification is not {@code OPTION} </exception> public static EtdOptionSecurity of(EtdContractSpec spec, YearMonth expiry, EtdVariant variant, int version, PutCall putCall, double strikePrice, YearMonth underlyingExpiryMonth) { if (spec.Type != EtdType.OPTION) { throw new System.InvalidOperationException(Messages.format("Cannot create an EtdOptionSecurity from a contract specification of type '{}'", spec.Type)); } SecurityId securityId = EtdIdUtils.optionId(spec.ExchangeId, spec.ContractCode, expiry, variant, version, putCall, strikePrice, underlyingExpiryMonth); return(EtdOptionSecurity.builder().info(SecurityInfo.of(securityId, spec.PriceInfo)).contractSpecId(spec.Id).expiry(expiry).variant(variant).version(version).putCall(putCall).strikePrice(strikePrice).underlyingExpiryMonth(underlyingExpiryMonth).build()); }
private EtdOptionPosition(PositionInfo info, EtdOptionSecurity 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 override bool Equals(object obj) { if (obj == this) { return(true); } if (obj != null && obj.GetType() == this.GetType()) { EtdOptionSecurity other = (EtdOptionSecurity)obj; return(JodaBeanUtils.equal(info, other.info) && JodaBeanUtils.equal(contractSpecId, other.contractSpecId) && JodaBeanUtils.equal(expiry, other.expiry) && JodaBeanUtils.equal(variant, other.variant) && (version == other.version) && JodaBeanUtils.equal(putCall, other.putCall) && JodaBeanUtils.equal(strikePrice, other.strikePrice) && JodaBeanUtils.equal(underlyingExpiryMonth, other.underlyingExpiryMonth)); } return(false); }
//------------------------------------------------------------------------- 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() { EtdOptionSecurity test = sut(); assertEquals(test.Variant, EtdVariant.MONTHLY); assertEquals(test.Type, EtdType.OPTION); 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()), EtdOptionTrade.of(TradeInfo.empty(), test, 1, 2)); assertEquals(test.createPosition(PositionInfo.empty(), 1, ReferenceData.empty()), EtdOptionPosition.ofNet(PositionInfo.empty(), test, 1)); assertEquals(test.createPosition(PositionInfo.empty(), 1, 2, ReferenceData.empty()), EtdOptionPosition.ofLongShort(PositionInfo.empty(), test, 1, 2)); }
/// <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 EtdOptionPosition ofLongShort(EtdOptionSecurity security, double longQuantity, double shortQuantity) { return(ofLongShort(PositionInfo.empty(), security, longQuantity, shortQuantity)); }
/// <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 EtdOptionPosition ofLongShort(PositionInfo positionInfo, EtdOptionSecurity security, double longQuantity, double shortQuantity) { return(new EtdOptionPosition(positionInfo, security, longQuantity, shortQuantity)); }
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()); }
/// <summary> /// Sets the security that was traded. </summary> /// <param name="security"> the new value, not null </param> /// <returns> this, for chaining, not null </returns> public Builder security(EtdOptionSecurity security) { JodaBeanUtils.notNull(security, "security"); this.security_Renamed = security; return(this); }
//------------------------------------------------------------------------- /// <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 EtdOptionPosition ofNet(EtdOptionSecurity security, double netQuantity) { return(ofNet(PositionInfo.empty(), security, netQuantity)); }
//------------------------------------------------------------------------- /// <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 EtdOptionTrade of(TradeInfo tradeInfo, EtdOptionSecurity security, double quantity, double price) { return(new EtdOptionTrade(tradeInfo, security, quantity, price)); }
/// <summary> /// Creates an option 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#OPTION"/> otherwise an exception will be thrown. /// /// </para> /// </summary> /// <param name="expiryMonth"> the expiry month of the option </param> /// <param name="variant"> the variant of the ETD, such as 'Monthly', 'Weekly, 'Daily' or 'Flex' </param> /// <param name="version"> the non-negative version, zero by default </param> /// <param name="putCall"> whether the option is a put or call </param> /// <param name="strikePrice"> the strike price of the option </param> /// <param name="underlyingExpiryMonth"> the expiry of the underlying instrument, such as a future </param> /// <returns> an option security based on this contract specification </returns> /// <exception cref="IllegalStateException"> if the product type of the contract specification is not {@code OPTION} </exception> public EtdOptionSecurity createOption(YearMonth expiryMonth, EtdVariant variant, int version, PutCall putCall, double strikePrice, YearMonth underlyingExpiryMonth) { return(EtdOptionSecurity.of(this, expiryMonth, variant, version, putCall, strikePrice, underlyingExpiryMonth)); }