/// <summary> /// Gets the number of months between the contract month and the expiry date. /// </summary> /// <param name="underlying">The future symbol ticker</param> /// <param name="futureExpiryDate">Expiry date to use to look up contract month delta. Only used for dairy, since we need to lookup its contract month in a pre-defined table.</param> /// <returns>The number of months between the contract month and the contract expiry</returns> public static int GetDeltaBetweenContractMonthAndContractExpiry(string underlying, DateTime?futureExpiryDate = null) { int value; if (futureExpiryDate != null && _dairyUnderlying.Contains(underlying)) { // Dairy can expire in the month following the contract month. var dairyReportDate = futureExpiryDate.Value.Date.AddDays(1); if (_reverseDairyReportDates.ContainsKey(dairyReportDate)) { var contractMonth = _reverseDairyReportDates[dairyReportDate]; // Gets the distance between two months in months return(((contractMonth.Year - dairyReportDate.Year) * 12) + contractMonth.Month - dairyReportDate.Month); } return(0); } return(ExpiriesPriorMonth.TryGetValue(underlying, out value) ? value : 0); }
/// <summary> /// Returns the number of months prior to the contract month that the future expires /// </summary> /// <param name="underlying">The future symbol</param> /// <returns>The number of months prior it expires</returns> public static int ExpiresInPreviousMonth(string underlying) { int value; return(ExpiriesPriorMonth.TryGetValue(underlying, out value) ? value : 0); }