Search Framework:
OptionChain
Namespace: WealthLab.Backtest
Parent: Object

An OptionChain organizes an option chain's strikes and expirations for a single underlier symbol and provides methods to find specific strikes and expirations.

public List OptionSymExpirations { get; }

**OptionSymExpirations** returns a complete list of `OptionSymExp` objects, each of which stores the strikes for each expiration. 
public double PreviousStrike(double price, DateTime expiration, bool useWeekly)

PreviousStrike returns the next lower strike above the price for the expiration. Pass true for useWeekly for non-regular option expirations.

Remarks:

  • For backtests on expired contracts option chains are not available. In this case, PreviousStrike returns "ficticious" strikes in $1 steps for prices below 20, and in $5 steps otherwise. public OptionSymExp GetOptionSymExp(DateTime expiration, bool useWeekly)
Returns the `OptionSymExp` object for the *expiration*. Pass *true* for *useWeekly* for non-regular option expirations.
Constructors
OptionChain
public OptionChain(string underlier, bool isIndex = false)

Instantiante an OptionChain with the underlying symbol. Because Index options typically expire on Thursday before the Friday option expiration, specify if the chain class is for Index options by passing true to isIndex. Complete an option chain by creating OptionSymExp objects for each expiration and use the Add method to add them to the chain.



Members
Add
public void Add(OptionSymExp optionSymExp)

Adds a unique OptionSymExp (symbol/expiration with strikes) to the chain.


ClosestStrike
public double ClosestStrike(double price, DateTime expiration, bool useWeekly)
Example Code
**Remarks:**
- For backtests on expired contracts option chains are not available. In this case, `ClosestStrike` returns "ficticious" strikes in $1 steps for prices below 20, and in $5 steps otherwise. 

### GetOptionSymExp

Expirations
public List<DateTime> Expirations(bool weeklies = false)

Returns a list of expirations for this OptionChain and null if none. If weeklies is false, only regular expirations are returned. Otherwise this returns all non-regular expirations in the chain.


IsIndex
public bool IsIndex { get; set; }

Identifies if the OptionChain belongs to Index options.


NextExpiry
public DateTime NextExpiry(DateTime dte, int calendarDaysAhead = 0, bool allowExpired = false, bool weeklies = false)

Starting from dte, NextExpiry returns the next expiration at least the number of calendarDaysAhead. Since otion chains do not include expired contracts, set allowExpired true to return option historical dates in backtests.


NextStrike
public double NextStrike(double price, DateTime expiration, bool useWeekly)
Example Code
**Remarks:**
- For backtests on expired contracts option chains are not available. In this case, `NextStrike` returns "ficticious" strikes in $1 steps for prices below 20, and in $5 steps otherwise. 

### PreviousStrike

RegularExpirationOnThursday
public bool RegularExpirationOnThursday { get; set; }

Use to generate expired [index] option expiration dates (if required).


Underlier

public string Underlier { get; }

Example Code
The underlier symbol for the option chain. 

### OptionSymExpirations