Syntax
public enum OptionType {Call, Put}
public class OptionsData { string Symbol, DateTime LastTradeDate, double Strike, double LastPrice, int Volume, double OpenInterest, double IV }
public static List<OptionsData> GetDataForSymbol(string symbol, OptionType type, DateTime dt)
Parameter Description
symbol | Symbol to get the options data |
type | OptionType.Call or OptionType.Put |
dt | An expiration date in the future |
Description
For a given U.S. stock symbol, retrieves the option specific data (such as last trade date, strike, last price, volume, open interest and implied volatility) for a specified expiry date in the future and option type (call or put).
Example
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using Community.Components;
namespace WealthLab.Strategies
{
public class MyStrategy : WealthScript
{
protected override void Execute()
{
ClearDebug();
var dateTime = NextOptionExpiryDate(Bars.Count - 1);
var key = Bars.Symbol + ";" + OptionType.Put + ";" + dateTime;
PrintDebug(key);
List<OptionsData> lst = new List<OptionsData>();
if (GetGlobal(key) == null)
{
lst = OpenInterestForOptions.GetDataForSymbol(Bars.Symbol, OptionType.Put, dateTime);
SetGlobal(key, (object)lst);
}
else
lst = (List<OptionsData>)GetGlobal(key);
PrintDebug("Symbol" + "\t" + "Last Trade" + "\t" + "Strike" + "\t" + "Last Price" + "\t" + "Volume" + "\t" + "Open Interest" + "\t" + "IV");
foreach (var t in lst)
PrintDebug(t.Symbol + "\t" + t.LastTradeDate + "\t" + t.Strike + "\t" + t.LastPrice + "\t" + t.Volume + "\t" + t.OpenInterest + "\t" +
string.Format("Value: {0:P2}.", t.IV / 100d));
}
}
}