Example #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;
        }
Example #2
0
        private void buttonGo_Click(object sender, EventArgs e)
        {
            string destPath = textBoxOutput.Text;

            int fileCount = 0;

            foreach (object obj in checkedListBoxMonths.CheckedItems)
            {
                MonthCodes code = obj as MonthCodes;

                List <QuoteCollection> monthlyContracts = quoteGroup[code.Month];

                string formatString = "yyyy-MM-dd";

                foreach (QuoteCollection contract in monthlyContracts)
                {
                    string       txtname = destPath + contract.Name + ".txt";
                    FileStream   stream  = new FileStream(txtname, FileMode.Create, FileAccess.Write);
                    StreamWriter sw      = new StreamWriter(stream);
                    sw.AutoFlush = true;

                    sw.WriteLine("Date,Open,High,Low,Close,Volume");
                    for (int i = 0; i < contract.DataCollection.Count; i++)
                    {
                        Quote quote = contract.DataCollection[i];
                        //sw.WriteLine(quote.ToString());
                        sw.WriteLine(String.Format("{0},{1},{2},{3},{4},{5}", quote.Time.ToString(formatString),
                                                   quote.Open, quote.High, quote.Low, quote.Close, quote.Volume));
                    }
                    stream.Close();

                    fileCount++;
                }
            }

            if (panelContinuous.Enabled)
            {
                foreach (GroupingFlag flag in this.methodFlags)
                {
                    bool            isVolumeBased = checkBoxVolumeBased.Checked;
                    QuoteCollection continous     = quoteGroup[flag, isVolumeBased];

                    string formatString = "yyyy-MM-dd";

                    string       txtname = destPath + continous.Name + ".txt";
                    FileStream   stream  = new FileStream(txtname, FileMode.Create, FileAccess.Write);
                    StreamWriter sw      = new StreamWriter(stream);
                    sw.AutoFlush = true;

                    sw.WriteLine("Date,Open,High,Low,Close,Volume");
                    for (int i = 0; i < continous.DataCollection.Count; i++)
                    {
                        Quote quote = continous.DataCollection[i];
                        //sw.WriteLine(quote.ToString());
                        sw.WriteLine(String.Format("{0},{1},{2},{3},{4},{5}", quote.Time.ToString(formatString),
                                                   quote.Open, quote.High, quote.Low, quote.Close, quote.Volume));
                    }
                    stream.Close();

                    fileCount++;
                }
            }

            MessageBox.Show(fileCount.ToString() + " files are geneerated.");
        }
Example #3
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()