I am trying my hand at recreating some python code in C# but am having some trouble with typing, specifically I want to get the furtherest expiration for a chain.

The documentation is rather limited (and has a typo I believe):

// In Initialize OptionSymol = option.Symbol; // (sp)? // In OnData OptionChain chain; if (slice.OptionChains.TryGetValue(OptionSymbol, out chain)) { // we find at the money (ATM) put contract with farthest expiration var atmContract = chain .OrderByDescending(x => x.Expiry) .ThenBy(x => Math.Abs(chain.Underlying.Price - x.Strike)) .ThenByDescending(x => x.Right) .FirstOrDefault(); }

I have:

private Symbol options_symbol; // should be OptionsSymbol? public override void Initialize() { SetStartDate(2018, 9, 1); //Set Start Date SetEndDate(2018, 9, 30); //Set End Date SetCash(100000); //Set Strategy Cash AddEquity("SPY", Resolution.Minute); var option = AddOption("SPY", Resolution.Minute); options_symbol = option.Symbol; // returns "OptionsSymbol"? SetWarmUp(TimeSpan.FromDays(3)); //Warm up 7 days of data. }

And than in `onData()`

public override void OnData(Slice data) { if(IsWarmingUp) return; OptionChain chain; // TryGetValue (doesn't work with option_symbol as type Symbol) if(slice.OptionChains.TryGetValue(option_symbol, out chain)){ var spot_price = chain.Underlying.Price; DateTime expiry = chain .OrderByDescending(x => x.Expiry) .FirstOrDefault().Expiry.Date; Log("Expiry: " + expiry); } else { Debug("Didn't get options chain"); } }

Author