Пример #1
0
        /// <summary>
        /// Creates an identifier for an ETD option instrument.
        /// <para>
        /// This takes into account the expiry of the underlying instrument. If the underlying expiry
        /// is the same as the expiry of the option, the identifier is the same as the normal one.
        /// Otherwise, the underlying expiry is added after the option expiry. For example:
        /// {@code 'OG-ETD~O-ECAG-OGBS-201706-P1.50-U201709'}.
        ///
        /// </para>
        /// </summary>
        /// <param name="exchangeId">  the MIC code of the exchange where the instruments are traded </param>
        /// <param name="contractCode">  the code supplied by the exchange for use in clearing and margining, such as in SPAN </param>
        /// <param name="expiryMonth">  the month of expiry </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">  the Put/Call flag </param>
        /// <param name="strikePrice">  the strike price </param>
        /// <param name="underlyingExpiryMonth">  the expiry of the underlying instrument, such as a future, may be null </param>
        /// <returns> the identifier </returns>
        public static SecurityId optionId(ExchangeId exchangeId, EtdContractCode contractCode, YearMonth expiryMonth, EtdVariant variant, int version, PutCall putCall, double strikePrice, YearMonth underlyingExpiryMonth)
        {
            ArgChecker.notNull(exchangeId, "exchangeId");
            ArgChecker.notNull(contractCode, "contractCode");
            ArgChecker.notNull(expiryMonth, "expiryMonth");
            ArgChecker.notNull(variant, "variant");
            ArgChecker.notNull(putCall, "putCall");

            string putCallStr  = putCall == PutCall.PUT ? "P" : "C";
            string versionCode = version > 0 ? "V" + version + SEPARATOR : "";

            NumberFormat f = NumberFormat.getIntegerInstance(Locale.ENGLISH);

            f.GroupingUsed          = false;
            f.MaximumFractionDigits = 8;
            string strikeStr = f.format(strikePrice).replace('-', 'M');

            string underlying = "";

            if (underlyingExpiryMonth != null && !underlyingExpiryMonth.Equals(expiryMonth))
            {
                underlying = SEPARATOR + "U" + underlyingExpiryMonth.format(YM_FORMAT);
            }

            string id = (new StringBuilder(40)).Append(OPT_PREFIX).Append(exchangeId).Append(SEPARATOR).Append(contractCode).Append(SEPARATOR).Append(expiryMonth.format(YM_FORMAT)).Append(variant.Code).Append(SEPARATOR).Append(versionCode).Append(putCallStr).Append(strikeStr).Append(underlying).ToString();

            return(SecurityId.of(ETD_SCHEME, id));
        }
        //-------------------------------------------------------------------------
        public virtual void test_equalsHashCode()
        {
            EtdContractCode a  = EtdContractCode.of("test");
            EtdContractCode a2 = EtdContractCode.of("test");
            EtdContractCode b  = EtdContractCode.of("test2");

            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);
        }
Пример #3
0
        /// <summary>
        /// Creates an identifier for an ETD future instrument.
        /// <para>
        /// A typical monthly ETD will have the format:
        /// {@code 'OG-ETD~O-ECAG-OGBS-201706'}.
        /// </para>
        /// <para>
        /// A more complex flex ETD (12th of the month, Physical settlement) will have the format:
        /// {@code 'OG-ETD~O-ECAG-OGBS-20170612E'}.
        ///
        /// </para>
        /// </summary>
        /// <param name="exchangeId">  the MIC code of the exchange where the instruments are traded </param>
        /// <param name="contractCode">  the code supplied by the exchange for use in clearing and margining, such as in SPAN </param>
        /// <param name="expiryMonth">  the month of expiry </param>
        /// <param name="variant">  the variant of the ETD, such as 'Monthly', 'Weekly, 'Daily' or 'Flex' </param>
        /// <returns> the identifier </returns>
        public static SecurityId futureId(ExchangeId exchangeId, EtdContractCode contractCode, YearMonth expiryMonth, EtdVariant variant)
        {
            ArgChecker.notNull(exchangeId, "exchangeId");
            ArgChecker.notNull(contractCode, "contractCode");
            ArgChecker.notNull(expiryMonth, "expiryMonth");
            ArgChecker.isTrue(expiryMonth.Year >= 1000 && expiryMonth.Year <= 9999, "Invalid expiry year: ", expiryMonth);
            ArgChecker.notNull(variant, "variant");

            string id = (new StringBuilder(40)).Append(FUT_PREFIX).Append(exchangeId).Append(SEPARATOR).Append(contractCode).Append(SEPARATOR).Append(expiryMonth.format(YM_FORMAT)).Append(variant.Code).ToString();

            return(SecurityId.of(ETD_SCHEME, id));
        }
        public virtual void test_of()
        {
            EtdContractCode test = EtdContractCode.of("test");

            assertEquals(test.ToString(), "test");
        }
Пример #5
0
 internal static EtdContractSpec sut2()
 {
     return(EtdContractSpec.builder().type(EtdType.OPTION).exchangeId(ExchangeIds.IFEN).contractCode(EtdContractCode.of("BAR")).description("A test option template").priceInfo(SecurityPriceInfo.of(Currency.EUR, 10)).addAttribute(AttributeType.NAME, "NAME").build());
 }
Пример #6
0
 //-------------------------------------------------------------------------
 internal 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());
 }
 /// <summary>
 /// Sets the code of the contract specification as given by the exchange in clearing and margining.
 /// </summary>
 /// <param name="contractCode">  the new value, not empty </param>
 /// <returns> this, for chaining, not null </returns>
 public EtdContractSpecBuilder contractCode(EtdContractCode contractCode)
 {
     JodaBeanUtils.notNull(contractCode, "contractCode");
     this.contractCode_Renamed = contractCode;
     return(this);
 }
Пример #8
0
        //-------------------------------------------------------------------------
        /// <summary>
        /// Creates an identifier for a contract specification.
        /// <para>
        /// This will have the format:
        /// {@code 'OG-ETD~F-ECAG-FGBS'} or {@code 'OG-ETD~O-ECAG-OGBS'}.
        ///
        /// </para>
        /// </summary>
        /// <param name="type">  type of the contract - future or option </param>
        /// <param name="exchangeId">  the MIC code of the exchange where the instruments are traded </param>
        /// <param name="contractCode">  the code supplied by the exchange for use in clearing and margining, such as in SPAN </param>
        /// <returns> the identifier </returns>
        public static EtdContractSpecId contractSpecId(EtdType type, ExchangeId exchangeId, EtdContractCode contractCode)
        {
            ArgChecker.notNull(type, "type");
            ArgChecker.notNull(exchangeId, "exchangeId");
            ArgChecker.notNull(contractCode, "contractCode");
            switch (type.innerEnumValue)
            {
            case com.opengamma.strata.product.etd.EtdType.InnerEnum.FUTURE:
                return(EtdContractSpecId.of(ETD_SCHEME, FUT_PREFIX + exchangeId + SEPARATOR + contractCode));

            case com.opengamma.strata.product.etd.EtdType.InnerEnum.OPTION:
                return(EtdContractSpecId.of(ETD_SCHEME, OPT_PREFIX + exchangeId + SEPARATOR + contractCode));

            default:
                throw new System.ArgumentException("Unknown ETD type: " + type);
            }
        }
Пример #9
0
 /// <summary>
 /// Creates an identifier for an ETD option instrument.
 /// <para>
 /// A typical monthly ETD with version zero will have the format:
 /// {@code 'OG-ETD~O-ECAG-OGBS-201706-P1.50'}.
 /// </para>
 /// <para>
 /// A more complex flex ETD (12th of the month, Cash settlement, European) with version two will have the format:
 /// {@code 'OG-ETD~O-ECAG-OGBS-20170612CE-V2-P1.50'}.
 ///
 /// </para>
 /// </summary>
 /// <param name="exchangeId">  the MIC code of the exchange where the instruments are traded </param>
 /// <param name="contractCode">  the code supplied by the exchange for use in clearing and margining, such as in SPAN </param>
 /// <param name="expiryMonth">  the month of expiry </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">  the Put/Call flag </param>
 /// <param name="strikePrice">  the strike price </param>
 /// <returns> the identifier </returns>
 public static SecurityId optionId(ExchangeId exchangeId, EtdContractCode contractCode, YearMonth expiryMonth, EtdVariant variant, int version, PutCall putCall, double strikePrice)
 {
     return(optionId(exchangeId, contractCode, expiryMonth, variant, version, putCall, strikePrice, null));
 }