コード例 #1
0
        public List <QuoteCollection> this[int month]
        {
            get
            {
                List <QuoteCollection> result = new  List <QuoteCollection>();

                List <QuoteCollection> quotes = Group.Values.ToList();
                bool isMergeable = true;

                for (int i = 1; i < quotes.Count; i++)
                {
                    if (quotes[i - 1].Until >= quotes[i].Since)
                    {
                        isMergeable = false;
                        break;
                    }
                }

                if (isMergeable)
                {
                    List <QuoteCollection> allYearQuotes = QuotesOfMonth(month, GroupingFlag.Default);

                    List <Quote> records = quotesFromCollections(allYearQuotes);

                    string name = string.Format("{0}{1}", Commodity.Description, MonthCodes.MonthCodeOf(month).Name);
                    result.Add(new QuoteCollection(name, "", RecordType.DayRecord, records));
                }
                else
                {
                    result.Add(this[month, GroupingFlag.EvenYearOnly]);
                    result.Add(this[month, GroupingFlag.OddYearOnly]);
                }
                return(result);
            }
        }
コード例 #2
0
        public QuoteCollection this[int month, GroupingFlag flag]
        {
            get
            {
                GroupingFlag yearFlag = flag & GroupingFlag.Default;

                if (yearFlag == GroupingFlag.EvenYearOnly)
                {
                    List <QuoteCollection> evenYearQuotes = QuotesOfMonth(month, GroupingFlag.EvenYearOnly);

                    List <Quote> records = quotesFromCollections(evenYearQuotes);

                    string name = string.Format("{0}{1}Even", Commodity.Description, MonthCodes.MonthCodeOf(month).Name);
                    return(new QuoteCollection(name, "", RecordType.DayRecord, records));
                }
                else if (yearFlag == GroupingFlag.OddYearOnly)
                {
                    List <QuoteCollection> oddYearQuotes = QuotesOfMonth(month, GroupingFlag.OddYearOnly);

                    List <Quote> records = quotesFromCollections(oddYearQuotes);

                    string name = string.Format("{0}{1}Odd", Commodity.Description, MonthCodes.MonthCodeOf(month).Name);
                    return(new QuoteCollection(name, "", RecordType.DayRecord, records));
                }
                else
                {
                    return(null);
                }
            }
        }
コード例 #3
0
        public ContractInfomation ContractOf(string fileName)
        {
            int index = fileName.LastIndexOf('\\');

            fileName = fileName.Substring(index + 1);

            if (!fileName.StartsWith(Symbol))
            {
                throw new Exception("Unexpected filename: " + fileName);
            }

            if (fileName.EndsWith("da1"))
            {
                if (fileName.Contains('.'))
                {
                    fileName = fileName.Substring(0, fileName.IndexOf('.'));
                }

                char code = fileName[fileName.Length - 1];

                int month, year = DateTimeOffset.Now.Year;

                month = MonthCodes.MonthOf(code);

                return(new ContractInfomation(this, year, month));
            }
            else
            {
                if (fileName.Contains('.'))
                {
                    fileName = fileName.Substring(0, fileName.IndexOf('.'));
                }

                char code = fileName[fileName.Length - 1];
                if (!MonthCodeString.Contains(code))
                {
                    //throw new Exception(string.Format("The commodity contains no contract for month of {0}({1})", code, MonthCodes.MonthCodeOf(code).Name));
                    MonthCodeString = string.Format("{0}{1}", code, MonthCodeString);
                    Months.Add(MonthCodes.MonthCodeOf(code));
                    Months.Sort();
                }

                int month, year;

                month = MonthCodes.MonthOf(code);

                string yearString = fileName.Substring(Symbol.Length, fileName.Length - Symbol.Length - 1);

                if (int.TryParse(yearString, out year))
                {
                    return(new ContractInfomation(this, year > 30 ? 1900 + year : 2000 + year, month));
                }
                else
                {
                    throw new Exception("Failed to parse year from " + yearString);
                }
            }
        }
コード例 #4
0
        public bool HasContractOn(int month)
        {
            if (month < 1 || month > 12)
            {
                return(false);
            }

            char symbol = MonthCodes.MonthCodeOf(month).Symbol;

            return(MonthCodeString.Contains(symbol));
        }
コード例 #5
0
        public ContractInfomation Next()
        {
            MonthCodes nextCode = Commodity.NextOf(Code);

            if (Code.Month < nextCode.Month)
            {
                return(new ContractInfomation(Commodity, Year, MonthCodes.MonthOf(nextCode.Symbol)));
            }
            else
            {
                return(new ContractInfomation(Commodity, Year + 1, MonthCodes.MonthOf(nextCode.Symbol)));
            }
        }
コード例 #6
0
        public MonthCodes NextOf(MonthCodes theCode)
        {
            int index = Months.IndexOf(theCode);

            if (index == -1)
            {
                return(null);
            }

            index = (index++) % Months.Count;

            return(Months[index]);
        }
コード例 #7
0
        private CommodityInfomation(string symbol, string contract, string exchange, string monthCodes, double minTick, double unitMove)
        {
            Symbol          = symbol;
            Description     = contract;
            Exchange        = ExchangeInfo.ExchangeOf(exchange);
            MonthCodeString = monthCodes.Replace(",", "");

            char ch = MonthCodes.January.Symbol;

            Months = new List <MonthCodes>();
            foreach (char code in MonthCodeString)
            {
                Months.Add(MonthCodes.MonthCodeOf(code));
            }


            MinTick  = minTick;
            UnitMove = unitMove;
        }