Beispiel #1
0
        /// <summary>
        /// Selects the correct contract month given the input time.
        /// </summary>
        /// <param name="month">The month to be accessed.  Note that the front month contract has an index of zero.</param>
        /// <param name="currentTime"></param>
        /// <returns></returns>
        private int GetMonth(int month, DateTime currentTime)
        {
            int contractMonthCount             = RolloverMap.Count;
            KeyValuePair <int, DateTime>?match = null;
            int frontMonthIndex = 0;

            for (int i = 0; i < contractMonthCount; i++)
            {
                if (RolloverMap[i].Value > currentTime)
                {
                    match           = RolloverMap[i];
                    frontMonthIndex = i;
                    break;
                }
            }

            if (match == null)
            {
                if (month == 0)
                {
                    throw new SystemException("EXCEPTION:  \"Month\" parameter cannot be zero.  To acces the front month, use a \"month\" value of 'one'.");
                }
                else
                {
                    throw new SystemException("EXCEPTION:  No valid contracts included in RolloverKey for instrument \"" + this.Name + "\"at " + currentTime.ToString() + ".");
                }
            }
            else
            {
                int addend = month - 1;
                int specifiedMonthIndex = frontMonthIndex + addend;

                return(RolloverMap.ElementAt(specifiedMonthIndex).Key);
            }
        }
Beispiel #2
0
        private void InsertMonthsIntoRolloverKey(List <ContractMonth> months)
        {
            RolloverMap = new RolloverMap();

            foreach (ContractMonth month in months)
            {
                KeyValuePair <int, DateTime> monthKey = new KeyValuePair <int, DateTime>(month.Name.GetId(), month.RolloverDate);
                RolloverMap.Add(monthKey);
            }
        }