Beispiel #1
0
        }//FullName
        //
        //
        //
        #endregion//Properties



        #region Constructors and Creators
        // *****************************************************************
        // ****                     Constructors                        ****
        // *****************************************************************
        protected Instrument(Instrument instrumentToCopy) : base((Product)instrumentToCopy)
        {
            this.MonthCode = instrumentToCopy.MonthCode;
            this.Year      = instrumentToCopy.Year;
        }
Beispiel #2
0
        }//Create

        //
        //
        // ****				TryInitialize()			****
        //
        /// <summary>
        /// Allowed format examples:
        /// 1) CME.GEU2		- simplest, full exchange and specific name
        /// 2) CME.GE#12	- term notation, 12th along term structure curve of GE family.
        /// 3) CME.GE		- single product reference only, like an equity where product = instrument.
        /// Using this weird out-function approach allows us to validate the format and then finally create
        /// a read-only object.
        /// </summary>
        protected static bool TryInitialize(string exchInstrName, string serverName, out Instrument instrument)
        {
            bool         isSuccess = true;
            string       exchange;
            string       productName;
            ProductTypes productType = ProductTypes.Future;

            instrument = null;

            int        year      = -1;
            MonthCodes monthCode = MonthCodes.None;

            //
            // Extract exchange from front of string.
            string fullInstrName;                             // place to store the instrument name.
            int    delimitIndex = exchInstrName.IndexOf('.'); // locate exchange/instr delimiter

            if (delimitIndex < 1)                             // there is no exchange tag
            {
                //this.Exchange = GuessTheExchange(exchInstrName);
                exchange      = GuessTheExchange(exchInstrName);
                fullInstrName = exchInstrName;
            }
            else
            {
                //this.Exchange = exchInstrName.Substring(0, delimitIndex);
                exchange      = exchInstrName.Substring(0, delimitIndex);
                fullInstrName = exchInstrName.Substring(delimitIndex + 1);
            }
            // Analyze full instrument name.
            delimitIndex = fullInstrName.IndexOf('#');          // locate term-structure delimiter.
            if (delimitIndex < 0)
            {
                delimitIndex = fullInstrName.IndexOf('_');              // alternate term-structure delimiter.
            }
            if (delimitIndex < 0)
            {   // Instrument name is in one of the basic format.
                // Extract year index.  Can accept 0,1, or 2 digit-formats. 0 means no year included (eg., equity).
                int yr;
                int n = fullInstrName.Length;
                if (int.TryParse(fullInstrName.Substring(n - 2), out yr))
                {       // 2-digit year provided.
                    //this.Year = DateTime.Now.Year - (DateTime.Now.Year % 100) + yr;
                    year = DateTime.Now.Year - (DateTime.Now.Year % 100) + yr;
                    string monthStr = fullInstrName.Substring(n - 3, 1);        // Month code must immediately proceed year.
                    //this.MonthCode = (MonthCodes)Enum.Parse(typeof(MonthCodes), monthStr, true);
                    monthCode = (MonthCodes)Enum.Parse(typeof(MonthCodes), monthStr, true);
                    //this.ProductName = fullInstrName.Substring(0, n - 3);
                    productName = fullInstrName.Substring(0, n - 3);
                }
                else if (int.TryParse(fullInstrName.Substring(n - 1), out yr))
                {       // 1-digit year provided.
                    //this.Year = DateTime.Now.Year - (DateTime.Now.Year % 10) + yr;
                    year = DateTime.Now.Year - (DateTime.Now.Year % 10) + yr;
                    string monthStr = fullInstrName.Substring(n - 2, 1);        // Month code must immediately proceed year.
                    //this.MonthCode = (MonthCodes)Enum.Parse(typeof(MonthCodes), monthStr, true);
                    monthCode = (MonthCodes)Enum.Parse(typeof(MonthCodes), monthStr, true);
                    //this.ProductName = fullInstrName.Substring(0, n - 2);
                    productName = fullInstrName.Substring(0, n - 2);
                }
                else
                {       // No year provided.  For example, equities "NYSE.GE"
                    //this.ProductName = fullInstrName;
                    productName = fullInstrName;
                    productType = ProductTypes.Equity;
                }
            }
            else if (delimitIndex < 1)
            {
                return(false);
            }
            else
            {   // instrument name formated as "term-structure" format: [prodName]#[location along term]
                //this.IsTermIdentified = true;
                //this.ProductName = fullInstrName.Substring(0, delimitIndex);
                productName = fullInstrName.Substring(0, delimitIndex);
                //this.MonthCode = MonthCodes.TermIdentified;
                monthCode = MonthCodes.TermIdentified;
                string sTermIndex = fullInstrName.Substring(delimitIndex + 1);
                int    n;
                if (!int.TryParse(sTermIndex, out n))
                {
                    return(false);                                                       // failed to parse integer!
                }
                //this.TermIndex = n;
                //this.Year = n;
                year = n;
            }
            // Exit
            instrument = new Instrument(new Product(exchange, productName, productType, serverName));
            return(isSuccess);
        }//initialize()