- ago
Would you please write a sample code to retrieve options for SPX 500?
I tried to use something like this:
CODE:
         TimeSeries iv = HV.Series(bars.Close, 21, 5) / 10d;          string symbol = OptionSynthetic.GetOptionsSymbol(bars, OptionType.Call, bars.Close.LastValue, bars.DateTimes[bars.Count - 1], 3);                 _osyn = OptionSynthetic.GetHistory(bars, symbol, iv);                    PlotBarHistory(_osyn, "OSYN", WLColor.Cyan);


but I get garbage string with NaN values.
0
360
Solved
10 Replies

Reply

Bookmark

Sort
- ago
#1
To clarify, is this the IQFeed symbol? What is the order of enabled historical data providers?
0
Cone8
 ( 25.44% )
- ago
#2
Your snippet works for me (as long as I declare _osyn as a BarHistory). Maybe there's something else in the rest of your code that's messing with the result.

Do you have access to Index data from IQFeed?
If you can get a chart for SPX.XO (or any symbol), there will be no problem to create a synthetic contract.

But if you want the real historical data for non-expired contracts, and have access to that data at IQFeed, see the example in the Help (F1) > IQFeed > Option Chains

0
- ago
#3
I am just looking for the Symbol. I don't care about the actual data from IQFeed. The code is just a copy of your sample on the website.
CODE:
ng WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Data; using WealthLab.Indicators; using System.Collections.Generic; namespace WealthScript1 { public class MyStrategy : UserStrategyBase {          BarHistory _osyn; // the option's BarHistory //create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars) {          //estimate a varying IV using a factor of HV          string symbol = OptionSynthetic.GetOptionsSymbol(bars, OptionType.Call, bars.LastValue, bars.DateTimes[bars.Count - 1], 5);          string c2sym = OptionsHelper.C2Symbol(symbol);          //show the symbols          DrawHeaderText($"Synthetic symbol is {symbol}", WLColor.Gold, 12, "Price");          DrawHeaderText($"C2 symbol is {c2sym}", WLColor.Gold, 12, "Price");           } //execute the strategy rules here, this is executed once for each bar in the backtest history public override void Execute(BarHistory bars, int idx) { if (!HasOpenPosition(bars, PositionType.Long)) { //code your buy conditions here } else { //code your sell conditions here } } //declare private variables below } }





0
Best Answer
Cone8
 ( 25.44% )
- ago
#4
Your snippet indicates you're looking for an synthetic option symbol, and it works.

But SPX.XO is an IQFeed symbol for the S&P 500 index. If you don't have the IQFeed data, then that script won't run for that symbol.

Anyway, be more specific. Which option symbol format you looking for? If you don't know how to respond, just say how you intend to use it.
0
- ago
#5
0
- ago
#6
sorry. You were quicker than me before I edited the last post. I changed the code just to get the symbol as exactly what you have in the sample code and I get the error in red above.
Note: I don't have Access to IQFEED options, but the last code doesn't use any provider to generate the symbol. Right?
0
Cone8
 ( 25.44% )
- ago
#7
I see it. The OptionsHelper doesn't expect a "." in the symbol. You'll need to modify the symbol by removing the "." or probably, you should remove ".XO" since that won't be compatible with C2.

QUOTE:
string symbol = OptionSynthetic.GetOptionsSymbol(bars, OptionType.Call, bars.LastValue, bars.DateTimes[bars.Count - 1], 5);
symbol = symbol.Replace(".XO", "");
string c2sym = OptionsHelper.C2Symbol(symbol);
0
Cone8
 ( 25.44% )
- ago
#8
If you use IQFeed (SPX.XO), it's best to call IQFeed for the option chain instead of the synthetic to return a proper symbol. If you do, no conversion is required for C2 - it's the same format.

CODE:
using WealthLab.IQFeed; // at the top          string symbol = IQFeedHistorical.Instance.GetOptionsSymbol(bars, OptionType.Call, bars.LastValue, bars.DateTimes[bars.Count - 1], 5);          string c2sym = symbol;

For example, for SPX.XO, IQFeed returns a symbol like this: SPX2419A4765

0
- ago
#9
I appreciate you bringing the WealthLab.IQFeed interface to my attention. I was unaware of its existence.
0
Cone8
 ( 25.44% )
- ago
#10
Sure thing.
For some more info and an example, see Help (F1) > Extensions > IQFeed > Option Chains
0

Reply

Bookmark

Sort