- ago
It returns Friday as the expiration day instead of Wednesday.
If you trace into the code until optionChain.NextExpiry you will notice the option chain has the correct date, but NextExpiry returns Friday.
CODE:
   public override string GetOptionsSymbol(BarHistory underlierBars, OptionType optionType, double price, DateTime expiryDate, int minDaysAhead = 0, bool useWeeklies = false, bool allowExpired = false, bool closestStrike = true, double multiplier = 100.0)    {       InitializeIfRequired();       if (underlierBars == null)       {          return null;       }       string symbol = underlierBars.Symbol;       OptionChain optionChain = GetOptionChain(symbol);       if (optionChain == null)       {          return null;       }       expiryDate = optionChain.NextExpiry(expiryDate, minDaysAhead, allowExpired, useWeeklies);


Note: The date return correct for not expiring options.


0
114
3 Replies

Reply

Bookmark

Sort
Cone8
 ( 4.98% )
- ago
#1
What are the parameters you used in the call?

QUOTE:
Note: The date return correct for not expiring options.
Confusing note. What does a correct date mean for "not expiring options"?
0
- ago
#2
User VIX.XO 5-minute bars.
Here are three examples:

string optionSymbol = IQFeedHistorical.Instance.GetOptionsSymbol(VIXBars, OptionType.Call, 18, 8/13/2024, 4, true, true, true);

Return: "VIX.XO2423H18" which is 8/23/2024 (Friday).

string optionSymbol = IQFeedHistorical.Instance.GetOptionsSymbol(VIXBars, OptionType.Call, 16, 9/03/2024, 11, true, true, true);

Return: "VIX.XO2420I16" Which is 09/20/2024 (Friday).

string optionSymbol = IQFeedHistorical.Instance.GetOptionsSymbol(VIXBars, OptionType.Call, 20, 10/01/2024, 11, true, true, true);

Return: "VIX2416J20" which is 10/16/2024 (Wednesday) ( see here also ".XO" is cleaned up.

"Not expiring means" the expiration date is above DateTime.Now.

To correct the problem I do the following:
CODE:
BarHistory optionBars = null; if (optionSymbol != null) { optionSymbol = optionSymbol.Replace(".XO", ""); // Fix WL expiration error. if (endFutureDate < DateTime.Now) { string dayString = optionSymbol.Substring(5, 2); int day = int.Parse(dayString); day = day - 2; dayString = "" + day; optionSymbol = optionSymbol.Substring(0, 5) + dayString + optionSymbol.Substring(7); }

0
Cone8
 ( 4.98% )
- ago
#3
Since the dates come from IQFeed, I'd have to call it their problem. But let's check to make sure what's coming back. I don't have access to index symbol data, so run this script on VIX.XO and post the debug log.

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using System.Collections.Generic; using WealthLab.IQFeed; using System.Linq; namespace WealthScript72 { public class IQFeedOptionChainDemo : UserStrategyBase { public override void Initialize(BarHistory bars) {          OptionChain chain = IQFeedHistorical.Instance.GetOptionChain(bars.Symbol);          if (chain == null)          {             WriteToDebugLog("null chain");             return;          }          List<DateTime> regExpirations = chain.Expirations(weeklies: false);          WriteToDebugLog("All regular Expirations in chain");          WriteToDebugLog(string.Join('\n', regExpirations));          List<DateTime> weeklyExpirations = chain.Expirations(weeklies: true);          WriteToDebugLog("\nAll non-regular Expirations in chain");          WriteToDebugLog(string.Join('\n', weeklyExpirations));       } public override void Execute(BarHistory bars, int idx) { } } }
0

Reply

Bookmark

Sort