Exemple #1
0
        public static CodeInfo GetCodeInfo(CodeIdParser parser, DataLoader_Variety dataLoader_Variety)
        {
            string varietyId = parser.VarietyId;
            string suffix    = parser.Suffix;
            int    year      = parser.Year;
            int    month     = parser.Month;

            VarietyInfo varietyInfo = dataLoader_Variety.GetVariety(varietyId);

            if (varietyInfo == null)
            {
                return(null);
            }
            string   codeId      = parser.CodeId;
            string   codeName    = varietyInfo.Name + suffix;
            int      start       = parser.StartDay;
            int      end         = parser.EndDay;
            string   exchange    = varietyInfo.Exchange;
            string   varietyName = varietyInfo.Name;
            CodeInfo code        = new CodeInfo(parser.CodeId, codeName, varietyId, varietyName, start, end, exchange, "");

            code.ServerCode = GetServerCode(parser.CodeId, exchange);
            code.ShortCode  = parser.ShortCode;
            return(code);
        }
Exemple #2
0
        /// <summary>
        /// 由期货现在的带年份的合约ID换成老的不带年份的合约ID
        /// 如由M1605得到M05
        /// </summary>
        /// <param name="codeInfo"></param>
        /// <returns></returns>
        public static string GetSimpleCodeId(string codeId)
        {
            if (codeId == null)
            {
                return(null);
            }
            string newCodeId = codeId.ToUpper();

            if (newCodeId.EndsWith("0000"))
            {
                return(newCodeId.Substring(0, newCodeId.Length - 4) + "13");
            }
            else if (newCodeId.EndsWith("MI"))
            {
                return(newCodeId);
            }
            else
            {
                CodeIdParser parser = new CodeIdParser(codeId);
                //string[] codeArr = SplitCodeId(codeId);
                string variety = parser.VarietyId;
                string suffix  = parser.Suffix;
                if (IsTwoYearsVariety(variety))
                {
                    int p = int.Parse(suffix.Substring(0, 2));
                    if (p % 2 == 1)
                    {
                        return(variety + "Y" + suffix.Substring(2, 2));
                    }
                    return(variety + "X" + suffix.Substring(2, 2));
                }
                return(variety + suffix.Substring(2, 2));
            }
        }
Exemple #3
0
 private static string GetComplexCodeId(CodeIdParser parser, int contractMonth, int tradingYear, int tradingMonth, int tradingDay)
 {
     if (IsLateThan(contractMonth, 2000 + tradingYear, tradingMonth, tradingDay))
     {
         return(GetComplexCodeIdInternal(parser, tradingYear + 1));
     }
     return(GetComplexCodeIdInternal(parser, tradingYear));
 }
Exemple #4
0
        ///// <summary>
        ///// 分解codeid
        ///// 如ax01,分解成[a,x,01]
        ///// </summary>
        ///// <param name="codeId"></param>
        ///// <returns></returns>
        //public static string[] SplitCodeId(String codeId)
        //{
        //    string[] resultArr = new string[3];

        //    if (codeId == null)
        //        return null;
        //    string ucodeId = codeId.ToUpper();
        //    if (ucodeId.EndsWith("MI"))
        //    {
        //        resultArr[0] = ucodeId.Substring(0, ucodeId.Length - 2);
        //        resultArr[1] = "";
        //        resultArr[2] = "MI";
        //        return resultArr;
        //    }

        //    int index = ucodeId.Length - 1;
        //    int result;
        //    bool isNumber = int.TryParse(ucodeId[index].ToString(), out result);
        //    while (isNumber && index > 0)
        //    {
        //        index--;
        //        isNumber = int.TryParse(ucodeId[index].ToString(), out result);
        //    }
        //    string variety = ucodeId.Substring(0, index + 1);
        //    string suffix = ucodeId.Substring(index + 1, ucodeId.Length - index - 1);

        //    if (variety.EndsWith("X") || variety.EndsWith("Y"))
        //    {
        //        if (variety.Length > 1)
        //        {
        //            resultArr[0] = variety;
        //            resultArr[1] = variety.Substring(variety.Length - 1, 1);
        //            resultArr[2] = suffix;
        //            return resultArr;
        //        }
        //    }

        //    resultArr[0] = variety;
        //    resultArr[1] = "";
        //    resultArr[2] = suffix;
        //    return resultArr;
        //}

        public static string GetComplexCodeId(CodeIdParser parser, int tradingDay)
        {
            string suffix = parser.Suffix;

            if (suffix == "13")
            {
                return(parser.VarietyId + "0000");
            }
            if (suffix == "MI")
            {
                return(parser.VarietyId + "MI");
            }

            int contractMonth = parser.Month;

            if (contractMonth < 0)
            {
                return(null);
            }
            int tradingMonth = (tradingDay % 10000) / 100;
            int tradingYear  = (tradingDay / 10000) % 100;

            //双年合约
            if (parser.TwoYearTag != null && parser.TwoYearTag != "")
            {
                bool isEven = tradingYear % 2 == 0;
                if (isEven && parser.TwoYearTag == CodeIdParser.TWOYEARTAG_ODD)
                {
                    return(GetComplexCodeIdInternal(parser, tradingYear + 1));
                }
                if (!isEven && parser.TwoYearTag == CodeIdParser.TWOYEARTAG_EVEN)
                {
                    return(GetComplexCodeIdInternal(parser, tradingYear + 1));
                }

                if (IsLateThan(contractMonth, 2000 + tradingYear, tradingMonth, tradingDay))
                {
                    return(GetComplexCodeIdInternal(parser, tradingYear + 2));
                }
                return(GetComplexCodeIdInternal(parser, tradingYear));
            }
            else
            {
                return(GetComplexCodeId(parser, contractMonth, tradingYear, tradingMonth, tradingDay));
            }
        }
Exemple #5
0
        public void TestSplitCodeId()
        {
            CodeIdParser parser = new CodeIdParser("ax01");

            Assert.AreEqual("A", parser.VarietyId);
            Assert.AreEqual("X", parser.TwoYearTag);
            Assert.AreEqual("01", parser.Suffix);
            Assert.AreEqual(0, parser.Year);
            Assert.AreEqual(1, parser.Month);
            Assert.AreEqual(0, parser.EndDay);
            Assert.AreEqual("AX01", parser.ShortCode);

            parser = new CodeIdParser("a0910");
            Assert.AreEqual("A", parser.VarietyId);
            Assert.AreEqual("Y", parser.TwoYearTag);
            Assert.AreEqual("0910", parser.Suffix);
            Assert.AreEqual(2009, parser.Year);
            Assert.AreEqual(10, parser.Month);
            Assert.AreEqual(20091016, parser.EndDay);
            Assert.AreEqual(20071021, parser.StartDay);
            Assert.AreEqual("AY10", parser.ShortCode);

            parser = new CodeIdParser("AMI");
            Assert.AreEqual("A", parser.VarietyId);
            Assert.AreEqual("", parser.TwoYearTag);
            Assert.AreEqual("MI", parser.Suffix);
            Assert.AreEqual(0, parser.Year);
            Assert.AreEqual(0, parser.Month);
            Assert.AreEqual(0, parser.EndDay);
            Assert.AreEqual("AMI", parser.ShortCode);

            parser = new CodeIdParser("PIMI");
            Assert.AreEqual("PI", parser.VarietyId);
            Assert.AreEqual("", parser.TwoYearTag);
            Assert.AreEqual("MI", parser.Suffix);
            Assert.AreEqual("PIMI", parser.ShortCode);

            parser = new CodeIdParser("y01");
            Assert.AreEqual("Y", parser.VarietyId);
            Assert.AreEqual("", parser.TwoYearTag);
            Assert.AreEqual("01", parser.Suffix);
            Assert.AreEqual(0, parser.Year);
            Assert.AreEqual(1, parser.Month);
            Assert.AreEqual(0, parser.EndDay);
            Assert.AreEqual("Y01", parser.ShortCode);

            parser = new CodeIdParser("y1001");
            Assert.AreEqual("Y", parser.VarietyId);
            Assert.AreEqual("", parser.TwoYearTag);
            Assert.AreEqual("1001", parser.Suffix);
            Assert.AreEqual(2010, parser.Year);
            Assert.AreEqual(1, parser.Month);
            Assert.AreEqual(20100115, parser.EndDay);
            Assert.AreEqual("Y01", parser.ShortCode);

            parser = new CodeIdParser("sr1005");
            Assert.AreEqual("SR", parser.VarietyId);
            Assert.AreEqual("X", parser.TwoYearTag);
            Assert.AreEqual("1005", parser.Suffix);
            Assert.AreEqual(2010, parser.Year);
            Assert.AreEqual(5, parser.Month);
            Assert.AreEqual(20100521, parser.EndDay);
            Assert.AreEqual(20090317, parser.StartDay);
            Assert.AreEqual("SRX05", parser.ShortCode);

            parser = new CodeIdParser("sr0905");
            Assert.AreEqual("SR", parser.VarietyId);
            Assert.AreEqual("Y", parser.TwoYearTag);
            Assert.AreEqual("0905", parser.Suffix);
            Assert.AreEqual(2009, parser.Year);
            Assert.AreEqual(5, parser.Month);
            Assert.AreEqual(20090515, parser.EndDay);
            Assert.AreEqual(20070520, parser.StartDay);
            Assert.AreEqual("SRY05", parser.ShortCode);
        }
Exemple #6
0
 private static String GetComplexCodeIdInternal(CodeIdParser parser, int tradingYear)
 {
     return(parser.VarietyId + ((tradingYear < 10) ? "0" + tradingYear.ToString() : tradingYear.ToString()) + parser.Suffix);
 }