//private DateTime[] RollDatesEnrichment(IContract identifier, DateTime[] dates) //{ // switch (AsFuture().BbgBase) // { // case "RX": // // can add speical case for particular market // default: // // -2 weekday from the first notice day // return dates.Select(d => RollBackWeekdays(d, 2)).ToArray(); // } //} /// <summary> /// The current implementation of future roll logic does not involve the intraday rolling. So the start date input needs to be of same /// time as the intraday data. Otherwise the roll logic would not be correct. /// Let say your data time series is at 9am. If your roll time set below is 00:00 (this is normal because we don't normally put time information for date), /// then ValueOnDate(xx-xx-xx) method called to retrieve the data for check data roll would not find any data at 00:00. /// </summary> /// <param name="startDate"></param> /// <returns></returns> public override IEnumerable<IContractSeries> ComputeContractsSeries(DateTime startDate) { var contractSeries = new List<ContractSeries>(); var rolldates = ComputeRollDates(startDate).OrderBy(d => d).ToArray(); int i = 0; MonthCodeYear curMonthCode = null; MonthCodeYear prevMonthCode = null; DateTime nextRollDate = DateTime.MinValue; int rollIndex = 0; while (startDate < DateTime.Today) { // 1. set the contract month code on first day if (i == 0) { var firstRoll = SetFirstDayMonthCodeAndRollDates(rolldates, startDate); curMonthCode = firstRoll.Item1; prevMonthCode = curMonthCode.GetMonthOffset(-3); rollIndex = firstRoll.Item2; nextRollDate = rolldates[rollIndex]; } else { // 2. roll to the next quarter contract if passed roll dates if(startDate >= nextRollDate) { prevMonthCode = curMonthCode; var newMonthCodeYear = MyCalendar.GetNextFutureMonthCode(curMonthCode.Month.ToString(), curMonthCode.Year, 3); curMonthCode = new MonthCodeYear((MonthCode) Enum.Parse(typeof(MonthCode), newMonthCodeYear.Item1), newMonthCodeYear.Item2); // after roll, we itererate to the next roll date rollIndex++; if (rollIndex >= rolldates.Length) break; nextRollDate = rolldates[rollIndex]; } } var curContractTicker = FutureBondLookup.getBbgTicker(AsFuture().BbgBase, curMonthCode); var prevContractTicker = FutureBondLookup.getBbgTicker(AsFuture().BbgBase, prevMonthCode); contractSeries.Add(new ContractSeries() { CurrentContract = curContractTicker, Date = startDate, PrevContract = prevContractTicker }); startDate = MyCalendar.NextWeekDay(startDate); i++; } return contractSeries; }
public static Bond GetBondForFuture(string tickerStart_, MonthCodeYear contract_) { var v = GetBondAndConversionFactorForFuture(tickerStart_, contract_); return v == null ? null : v.Bond; }
public static BondFutureConversion GetBondAndConversionFactorForFuture(string tickerSTart_, MonthCodeYear contract_) { string ticker = getBbgTicker(tickerSTart_, contract_); return GetBondAndConversionFactorForFuture(ticker); }
public static string getBbgTicker(string tickerStart_, MonthCodeYear contract_) { if (contract_.Year >= DateTime.Today.Year) return string.Format("{0}{1}{2} COMDTY", tickerStart_, ((MonthCode) (int) contract_.Month).ToString(), (contract_.Year%10).ToString()); else return string.Format("{0}{1}{2} COMDTY", tickerStart_, ((MonthCode) (int) contract_.Month).ToString(), (contract_.Year%100).ToString("00")); }