public ContractTime GetContractTime(DateTime date, int index = 0)
        {
            ContractTime cContractTime = null;

            date = new DateTime(date.Year, date.Month, date.Day, __iCloseHour, __iCloseMinute, __iCloseSecond);
            int iCount = __cContractTimes.Count;

            for (int i = index; i < iCount; i++)
            {
                ContractTime cContractTemp = __cContractTimes[i];
                double       dTotals       = (cContractTemp.MaturityDate - date).TotalSeconds;
                if (dTotals >= 0 && dTotals <= 604800)
                {
                    cContractTime = cContractTemp;
                    break;
                }
            }

            if (cContractTime == null)
            {
                if (index > 0)
                {
                    date = date.AddSeconds(index * 604800);
                }
                cContractTime = MaturityDateUtil.GetWeekMaturityDate(date);
            }
            return(cContractTime);
        }
        private void CalcContractTime(DateTime today)
        {
            //先計算出現月
            ContractTime cCurrentContractTime = MaturityDateUtil.GetMonthMaturityDate(today, true);

            AddContractTime(0, cCurrentContractTime);

            //由現月計算出其他月份
            int iMonth     = cCurrentContractTime.ContractMonth;
            int iBaseMonth = CalcBaseMonth(iMonth);

            int[] iMonthPeriods = new int[5];
            iMonthPeriods[0] = 1;
            iMonthPeriods[1] = 2;
            for (int i = 0; i < 3; i++)
            {
                iMonthPeriods[i + 2] = (iBaseMonth + (3 * i)) - iMonth;
            }

            //計算其他月份的交易日與到期日
            int iLength = iMonthPeriods.Length;

            for (int i = 0; i < iLength; i++)
            {
                ContractTime cContractTime = AddContractMonths(cCurrentContractTime, iMonthPeriods[i]);
                AddContractTime(i + 1, cContractTime);
            }
        }
        public ContractTime GetContractTime(DateTime date, int index = 0)
        {
            ContractTime cContractTime = null;

            int iYear = date.Year, iMonth = date.Month;
            int iIndex = 0, iKey = iYear * 100 + iMonth;

            if (__cIndexs.TryGetValue(iKey, out iIndex))
            {
                cContractTime = __cContractTimes[(index > 0) ? index : iIndex];
            }
            else
            {
                date          = new DateTime(iYear, iMonth, date.Day, __iCloseHour, __iCloseMinute, __iCloseSecond);
                cContractTime = MaturityDateUtil.GetMonthMaturityDate(date, true);

                if (index > 0)
                {
                    int iCMonth      = cContractTime.ContractMonth;
                    int iBaseMonth   = CalcBaseMonth(iMonth);
                    int iMonthPeriod = (index > 1) ? (iBaseMonth + (3 * (index - 2))) - iCMonth : 1;
                    cContractTime = AddContractMonths(cContractTime, iMonthPeriod);
                }
            }
            return(cContractTime);
        }
        private ContractTime AddContractMonths(ContractTime contract, int month)
        {
            int iYear  = contract.ContractYear;
            int iMonth = contract.ContractMonth + month;

            if (iMonth > 12)
            {
                --iMonth;
                iMonth %= 12;
                ++iMonth;
                ++iYear;
            }
            return(MaturityDateUtil.GetMonthMaturityDate(new DateTime(iYear, iMonth, 1, __iCloseHour, __iCloseMinute, __iCloseSecond), false));
        }
Beispiel #5
0
        private ContractTime AddContractMonths(ContractTime contract, int month)
        {
            int iYear  = contract.ContractYear;
            int iMonth = contract.ContractMonth + month;

            if (iMonth > 12)
            {
                --iMonth;
                iMonth %= 12;
                ++iMonth;
                ++iYear;
            }
            return(MaturityDateUtil.GetMonthMaturityDate((new DateTime(iYear, iMonth, 1)).AddSeconds(__cCloseTime.TotalSeconds), false));
        }
        private void CalcContractTime(DateTime today)
        {
            //先計算出目前此週到期日
            ContractTime cCurrentContractTime = MaturityDateUtil.GetWeekMaturityDate(today);

            AddContractTime(0, cCurrentContractTime);

            DateTime cDate = cCurrentContractTime.MaturityDate.AddSeconds(604800);

            for (int i = 1; i < 3; i++)
            {
                ContractTime cContractTime = MaturityDateUtil.GetWeekMaturityDate(cDate);
                AddContractTime(i, cContractTime);

                cDate = cContractTime.MaturityDate.AddSeconds(604800);
            }
        }