GetExpirationDate ( string strDate ) { // Method members string monthCode; int monthIndex; int yearCode; DateTime date; // Set the asset symbol to not valid Valid = false; try { // Are there only numbers in the date string? if (!Regex.IsMatch(strDate, @"^[A-Za-z]")) { // YES: Parse of date time value good? if (DateTime.TryParse($"{strDate.Substring(0, 4)}-{strDate.Substring(4, 2)}-{strDate.Substring(6, 2)}", out date)) { // YES: Save the date if (AssetType == "OPT") { option.ExpirationDate = date; } else { futures.ExpirationDate = date; } // Set validity of option based on exp. date? Valid = date > DateTime.UtcNow; // Nothing more to process return; } } else { // NO: An alphanumeric expiration date string should be in form // of SSSSXN, where SSS is the symbol of the asset, X is the // month character and N is the last digit of the year. // // Does expiration date string have the asset symbol in it? if (strDate.StartsWith(Symbol)) { // YES: Eliminate the asset symbol strDate = strDate.Replace(Symbol, ""); // The date string should now be only two characters if (strDate.Length == 2) { // YES: Correct length. Get the month code and the year monthCode = strDate[0].ToString(); yearCode = Convert.ToInt32(strDate.Substring(1, 1)); // Is this a FUT or an FUTX? if (AssetType.StartsWith("FUT")) { // YES: Expiration date for FUTURES. Third Fri. // of every third month. // // Get the month index for the FUTURE expiration monthIndex = FutureCodes.IndexOf(monthCode) + 1; // Get the FUTURES expiration date futures.ExpirationDate = GetDateFromCode(yearCode, monthIndex); } else { // NO: For OPTIONS. For CALL? if (CallCodes.Contains(monthCode)) { // YES: For a CALL option.PutCallType = "C"; // Get the month index for the CALL expiration monthIndex = CallCodes.IndexOf(monthCode) + 1; } else { // NO: For a PUT option.PutCallType = "P"; // Get the month index for the PUT expiration monthIndex = PutCodes.IndexOf(monthCode) + 1; } // Get and save the option expiration date option.ExpirationDate = GetDateFromCode(yearCode, monthIndex); } } } } } catch (Exception e) { } // Return the asset symbol return; }