Trade Smarter with Automation

Option Chains

This document will cover working with options, option chains and spreads in Alta5. It assumes the reader has basic programming skills and has reviewed the Strategy Basics guide.

Option Chain Worker

Option chains in Alta5 are created and maintained by an option chain worker. The worker is responsible for loading and filtering the option chain, initializing Option securities and optionally, building spreads for the strategy.

Settings

The following settings are available to configure an option chain worker:

Setup

id

String
The id of the worker. The option chain created by the worker is available in the strategy as data.id. Also used with this.workers.get(id) to get a reference to the option chain worker in your Trader.

openDelay

Number= 3
The number of minutes to wait after the market open for option pricing to stabilize. 3

security

String= '$target'
The symbol of the underlying security for the option chain. By default, bound to the target symbol. $target

Filtering

expiration

String
Filter returned series to a particular month of expiration in the format YYYYMM.

maxDays

Number
The maximum number of days until expiration for option series in the chain.

maxSeries

Number= 4
The maximum number of option series in the chain. Maximum 4 series per request. 4

maxStrike

Number
The maximum strike price for returned options. Also accepts a number between 0 and 1 to represent a decimal percentage above the current ask price for the underlying symbol.

workers: [{
    type: 'optionchain',
    security: '$target',
    optionType: OptionChain.CALLS,
    maxSeries: 1,
    maxStrike: .1,    // return options with a strike price
    minStrike: .1     // within 10% of the current price
}]

maxStrikes

Number= 20
The maximum number strike prices to return per series. Maximum 50 per series. 20

minDays

Number
The minimum number of days until expiration for option series in the chain.

minStrike

Number
The minimum strike price for returned options. Also accepts a number between 0 and 1 to represent a decimal percentage below the current bid price for the underlying symbol.

workers: [{
    id: 'chain',
    type: 'optionchain',
    security: '$target',
    optionType: OptionChain.CALLS,
    maxSeries: 1,
    maxStrike: .1,    // return options with a strike price
    minStrike: .1     // within 10% of the current price
}]

monthlyOnly

Boolean= false
True to only include series that expire on the 3rd friday of each month. false

optionType

String= OptionChain.ALL
The type of options to return. OptionChain.ALL OptionChain.PUTS OptionChain.CALLS OptionChain.ALL

range

String= OptionChain.NTM
A predefined range for the options in the chain. OptionChain.NTM - Near The Money. Returns options with strike prices within 5%, above or below, of the current price of the underlying. OptionChain.ITM - Returns options that are In The Money. OptionChain.OTM - Returns options that are Out of The Money. OptionChain.ALL_STRIKES OptionChain.NTM

Spreads

enableSpreads

Boolean= false
True to enable the spread builder. false

minSpreadInterval

Number= 1
The minimum distance between the strikes in created spreads. Useful with spreadInterval:'auto' and lower priced stocks with .50 gaps. 1

spreadsId

String= 'spreads'
The indentifier used to reference the created spreads array in your strategy. For example, spreadsId:'spreads' would enable the spreads to be accessed in your strategy as data.spreads. spreads

spreadType

String
The type of spreads to create. This list will be expanding in the very near future. Spread.BULLPUT - A put credit spread. Spread.BEARCALL - A call credit spread.

spreadInterval

Number= 'auto'
The distance between the strikes in the created spreads. Use 'auto' to use the smallest available interval. auto

Examples

The following will return an option chain for the target security, with the 2 closest series, with 20 strikes per series. No filtering.


workers: [{
    id: 'chain',
    type: 'optionchain',
    maxSeries: 2,
    maxStrikes: 20
}]

The following returns an option chain for the target security, with the 1 series, at least 14 days til expiration, 20 strikes, only out of the money puts.


workers: [{
    id: 'chain',
    type: 'optionchain',

    minDays: 14,
    maxSeries: 1,                  // 1 series, at least 14 days til expiration

    optionType: OptionChain.PUTS,
    range: OptionChain.OTM,        // out of the money puts

    maxStrikes: 20                 // 20 strikes
}]

The following returns an option chain for the S&P 500 (SPX), with at least minDays until expiration, with maxSeries series, 16 out of the money (OTM) calls and builds Bear Call spreads at spreadInterval.


workers: [{
    id: 'chain',
    type: 'optionchain',
    security: 'SPX',

    minDays: '$minDays',
    maxSeries: '$maxSeries',

    optionType: OptionChain.CALLS,
    range: OptionChain.OTM,

    maxStrikes: 16,

    enableSpreads: true,
    spreadType: Spread.BEARCALL,
    spreadInterval: '$spreadInterval'
}]

Using the Chain

Accessing

The OptionChain created by the option chain worker is available in the Trader's data object by the id of the worker or by calling the get method of the Trader with the id of the worker. See Get the Chain below for an example.

Structure

The high-level structure of an OptionChain:

OptionChain
• series[]  Array
Series
• strikes[]  Array
Strike
• call/put  Option

OptionChain

Properties

firstSeries
Series
The first Series in this chain.
lastSeries
Series
The last Series in this chain.
length
Number
The number of series in this chain.
series
Array
An array of containing all the Series in this OptionChain. The first series is at index 0.

var thirdSeries = chain.series[2];
underlying
Security
A Security object for the underlying security.

Methods

getSeries
mixed minDateOrDays
Returns the first series that meets the criteria in minDateOrDays. minDateOrDaysmixed The minimum days until expiration or a date the series should expire after. Number - The minimum days until expiration. Date - A date the series should expire after. String - A string date the series should expire after (i.e. '04/15/2016', 'in 2 weeks', 'next month', See valid formats).

var chain = data.chain;
var series = chain.getSeries('in 2 weeks');
Series
rseek
function callback, Object scope
Scans each series, each strike, from highest strike to lowest strike until callback returns a value. callbackfunction Should have the signature function(Strike, index). scopeObject An object that will be used as this for the callback. See seek method below for example. The first value returned by callback.
seek
function callback, Object scope
Scans each series, each strike, from lowest strike to highest strike until callback returns a value. callbackfunction Should have the signature function(Strike, index). scopeObject An object that will be used as this for the callback.

var chain = data.chain;
var put = chain.seek(function(strike){
    if(strike.put.delta > ...){  // whatever your criteria
        return strike.put;
    }
});
if(put){ /// can be undefined if callback doesn't match a put
    this.enter(put);
}
The first value returned by callback or undefined.
spreads
String type, Number interval
Constructs spreads from each series and puts them in 1 array from first series to last series, lowest strike to highest strike. typeString The type of spreads to create. Spread.BULLPUT - A put credit spread. Spread.BEARCALL - A call credit spread. intervalNumber The distance between the strikes in the created spreads. Array An array with the spreads.

Series

Properties

firstStrike
Strike
The first Strike in this Series.
lastStrike
Strike
The last Strike in this Series.
length
Number
The number of strikes in this Series.
nextSeries
Series
The Series after this one in the chain.
previousSeries
Strike
The Series preceding this one in the chain.
strikes
Array
An array of containing all of the Strikes in this Series. The first Strike is at index 0.

var thirdStrike = chain.firstSeries.strikes[2];

Methods

getStrike
Number price
Get a Strike with an exact strike price. priceNumber The desired strike price. Strike The Strike with price.
getCallAbove
Number price
Get the first call Option with a strike price higher than price. priceNumber The reference price. Option The first call Option above price.
getCallBelow
Number price
Get the first call Option with a strike price lower than price. priceNumber The reference price. Option The first call Option below price.
getPutAbove
Number price
Get the first put Option with a strike price higher than price. priceNumber The reference price. Option The first put Option above price.
getPutBelow
Number price
Get the first put Option with a strike price lower than price. priceNumber The reference price. Option The first put Option below price.
getStrikeAbove
Number price
Get the first Strike with a strike price higher than price. priceNumber The reference price. Strike The first Strike above price.
getStrikeBelow
Number price
Get the first Strike with a strike price lower than price. priceNumber The reference price. Strike The first Strike below price.
rseek
function callback, Object scope
Scans each strike, from highest strike to lowest strike until callback returns a value. callbackfunction Should have the signature function(Strike, index). scopeObject An object that will be used as this for the callback. See seek method below for example. The first value returned by callback or undefined.
seek
function callback, Object scope
Scans each strike, from lowest strike to highest strike until callback returns a value. callbackfunction Should have the signature function(Strike, index). scopeObject An object that will be used as this for the callback.

var series = data.chain.firstSeries;
var put = series.seek(function(strike){
    if(strike.put.delta > ...){  // whatever your criteria
        return strike.put;
    }
});
if(put){ /// can be undefined if callback doesn't match a put
    this.enter(put);
}
The first value returned by callback or undefined.
spreads
String type, Number interval
Constructs spreads from the strikes in this series and puts them in an array from lowest strike to highest strike. typeString The type of spreads to create. Spread.BULLPUT - A put credit spread. Spread.BEARCALL - A call credit spread. intervalNumber The distance between the strikes in the created spreads. Array An array with the spreads.

Strike

Properties

call
Option
The call Option for this Strike or null if the chain is filtered to only contain puts.
nextStrike
Series
The Strike after this one in the Series.
previousStrike
Strike
The Strike preceding this one in the Series.
price
Number
The strike price.
put
Option
The put Option for this Strike or null if the chain is filtered to only contain calls.

Option

See the Securities Guide.

Spread

The Spreads created by an option chain are lightweight and intended to help a strategy find a desirable position. All calculations are based on the current market ask or bid prices. For example, the credit property for a Spread is calculated using the short leg bid - the long leg ask. In a live trade, prices will generally fill at a better price somewhere in between those prices (mark price).

Properties labeled real-time are bound to the real-time properties of the Option securities and are always up-to-date with the latest market value.

All Spreads

breakeven
Number
The breakeven price for this Spread.
closePrice
Number
The asking price to close a position of this Spread. (per share)
days
Number
The number of days until expiration for the short leg of this Spread.
delta
Number
The combined delta greek for this Spread.
expiration
Date
The expiration date for the short leg of this Spread.
gamma
Number
The combined gamma greek for this Spread.
interval
Number
The distance between the strike prices of the options in this Spread.
itm
Boolean
True if this Spread is in the money.
maintenance
Number
The amount of maintenance (capital or margin) required to secure each spread.
markPrice
Number
The short leg mark - the long leg mark. This value is not bounds checked and can result in a negative value with far out of the money options.
maxLoss
Number
The maximum potential loss for each Spread, not including commissions.
maxProfit
Number
The maximum potential profit for each Spread, not including commissions.
mdays
Number
The number of days until expiration for the short leg of this Spread, adjusted to only including trading days in the final week. If an option with 10 days until expiration expires on Saturday and the preceding Friday is a holiday, the days value would be adjusted 2 days and mdays would be 8.
openPrice
Number
The asking price to open a position of this Spread. (per share)
rewardToRiskRatio
Number
The reward to risk ratio for this spread. (maxProfit / maxLoss)
riskToRewardRatio
Number
The risk to reward ratio for this spread. (maxLoss / maxProfit)
rho
Number
The combined rho greek for this Spread.
strike
Number
The price at which this Spread goes in the money.
theta
Number
The combined theta greek for this Spread.
underlying
Security
A Security object for the underlying security.
vega
Number
The combined vega greek for this Spread.

Credit Spreads

credit
Number
The premium credit per share collected for selling this Spread.
returnRate
Number
The return on capital for this Spread as a decimal percent. (credit * 100) / (maintenance - (credit * 100))

Option Sample

This sample will cover configuring an option chain worker, accessing that option chain and buying a put in the target security when an RSI technical indicator is above the rsiSignal parameter value. For more information about Parameters, see Parameters Guide.

We will be using the Strategy code below as a base:


Strategy.define({
    name: 'Option Sample',
    description: 'Demonstrates loading options and buying a put.',
    positionType: 'Option',

    params: [{
        id: 'rsiSignal',       // custom parameter for rsi signal
        type: 'number',
        label: 'RSI Signal',
        min: 1,
        max: 100,
        defaultValue: 80
    }],

    workers: [],

    onSeek: function(target, data){

    }
});

Add Workers

The code below adds 2 workers, a chart worker (see Charts) and an option chain worker. The option chain is for the target security, with 1 series, at least 14 days til expiration, only 3 strikes and only out of the money (OTM) puts.


workers: [{
    id: 'chart',
    type: 'ichart',                // intraday chart
    minBars: 14,
    indicators: [{
        type: 'rsi',
        timePeriod: 14
    }]
},{
    id: 'options',                   // access the chain as data.options
    type: 'optionchain',

    minDays: 14,
    maxSeries: 1,                  // 1 series, at least 14 days til expiration

    maxStrikes: 3,                 // 3 nearest strikes

    optionType: OptionChain.PUTS,  // only puts
    range: OptionChain.OTM         // out of the money
}]

Get the Chain

The OptionChain created by a option chain worker is made available in our strategy with the id provided in the id setting on the worker. We set id:'options' on our worker, so we can get the OptionChain with data.options in our onSeek method.


onSeek: function(target, data){
    // get the first option series
    var series = data.options.firstSeries;

    // ...
}

Buying an Option

In this simple example, we are going to buy the nearest out of the money (OTM) put in the chain when the RSI for the target security is higher than the rsiSignal parameter.

For more information about the enter method, see Strategy Basics.


onSeek: function(target, data){
    var bar = data.chart.lastBar,
        rsi = bar.indicator('rsi');         // get the RSI value

    var signal = data.rsiSignal;            // get our signal parameter

    if(rsi >= signal){
        var series = data.options.firstSeries,       // get the first option series
            put = series.getPutBelow(target.last);   // get put nearest to current price

        // trigger a buy with a memo message
        this.enter(put, 'RSI Signal: {0}, RSI Value: {1}'.format(signal, rsi));
    }
}

Spreads Sample

Below is a sample strategy created for a tutorial video we will be publishing in the near future. In a nutshell, you pick a stock you like and it waits for a volatility spike and sells a put spread when it happens. There are 2 versions of the strategy below:

The 1st is very simple and short with hard coded numbers.

The 2nd is the same strategy, but with parameters that allow you to customize the numbers used internally by the strategy - for each trader that uses it.

Without Parameters


Strategy.define({
    name: 'Bull Reversal',
    description: 'Sells a put spread on the target stock when market volatility causes an intraday downward swing.',
    positionType: Position.SPREAD_BULLPUT,

    params: [{
        id: 'vix',
        type: 'security',
        label: 'Volatility Index',
        description: 'The volatility index to watch (generally VIX)',
        required: true,
        defaultValue: 'VIX'
    }],

    workers: [{
        id: 'chain',
        type: 'optionchain',
        security: '$target',
        optionType: OptionChain.PUTS,
        range: OptionChain.OTM,
        minDays: 10,
        maxSeries: 2,
        maxStrikes: 20,
        enableSpreads: true,
        spreadType: Spread.BULLPUT,
        spreadsId: 'spreads',
        spreadInterval: 'auto'
    }],

    onSeek: function(target, data){
        var vix = data.vix,  // the vix Security (see docs)
            maxStrike = target.last - (target.last * .02);   // 2% lower

        // The VIX is up 3% and the stock is down
        if(vix.changePct >= .03 && target.changePct <= -0.015){
            // The "seek" function of an array calls the callback function with
            // with each item in the array until the call returns a value.
            var spread = data.spreads.seek(function(s){
                 if(s.strike <= maxStrike && s.returnRate >= .2){
                     return s;
                 }
            });
            // if seek() found a valid spread, open a new position.
            if(spread){
                this.enter(spread);
            }
        }
    },

    onManage: function(target, pos, data){
        // if it touches the strike and the cost to get out is greater than a max loss
        if(target.last < pos.strike && pos.marketValue > -pos.maintenance){
            this.exit(pos);
        }
    }
});

With Parameters


Strategy.define({
    name: 'Bull Reversal',
    description: 'Sells a put spread on the target stock when market volatility causes an intraday downward swing.',
    positionType: Position.SPREAD_BULLPUT,

    params: [{
        id: 'vix',
        type: 'security',
        label: 'Volatility Index',
        description: 'The volatility index to watch (generally VIX)',
        required: true,
        defaultValue: 'VIX'
    },{
        id: 'vixSpike',
        type: 'percent',
        label: 'VIX Spike',
        group: 'Entry Signals',
        required: true,
        description: 'The minimum % the VIX must be up intraday to signal entry.',
        min: -100,
        allowDecimals: true,
        decimalPrecision: 2,
        defaultValue: 5
    },{
        id: 'targetFall',
        type: 'percent',
        label: 'Target Fall',
        required: true,
        description: 'The minimum % the target security must be down intraday to signal entry.',
        allowDecimals: true,
        decimalPrecision: 2,
        defaultValue: 1
    },{
        id: 'returnRate',
        type: 'percent',
        label: 'Return Rate',
        description: 'The minimum potential return % for spread positions.',
        required: true,
        group: 'Spread Settings',
        allowDecimals: true,
        min: 1,
        decimalPrecision: 2,
        defaultValue: 20
    },{
        id: 'strikeDistance',
        type: 'percent',
        label: 'Strike Distance',
        description: 'The minimum % below the current price the strike price of a spread must be on entry.',
        required: true,
        allowDecimals: true,
        decimalPrecision: 2,
        defaultValue: 2
    },{
        id: 'spreadInterval',
        type: 'spreadinterval',
        label: 'Spread Interval',
        required: false,
        defaultValue: 'auto',
        description: 'The distance between the strike prices in a spread.'
    },{
        id: 'minDays',
        type: 'number',
        label: 'Days',
        description: 'The minimum number of calendar days from expiration a spread must be on entry.',
        required: true,
        min: 0,
        max: 365,
        defaultValue: 10
    }],

    workers: [{
        id: 'chain',
        type: 'optionchain',
        security: '$target',
        optionType: OptionChain.PUTS,
        range: OptionChain.OTM,
        minDays: '$minDays',
        maxSeries: 2,
        maxStrikes: 20,
        enableSpreads: true,
        spreadType: Spread.BULLPUT,
        spreadsId: 'spreads',
        spreadInterval: '$spreadInterval'
    }],

    onSeek: function(target, data){
        var vix = data.vix,
            vspike = data.vixSpike * .01,
            tfall = data.targetFall * -.01,
            rrate = data.returnRate * .01,
            maxStrike = target.last - (target.last * data.strikeDistance * .01);

        if(vix.changePct >= vspike && target.changePct <= tfall){
            var spread = data.spreads.seek(function(s){
                 if(s.strike <= maxStrike && s.returnRate >= rrate){
                     return s;
                 }
            });
            if(spread){
                var memo = 'Target: {0}, Vix: {1}'.format(vix.changePct, target.changePct);
                this.enter(spread, memo);
            }
        }
    },

    onManage: function(target, pos, data){
        if(target.last < pos.strike && pos.marketValue > -pos.maintenance){
            var memo = 'Underlying price {0} below spread strike price {1}.'.format(target.last, pos.strike);
            this.exit(pos, memo);
        }
    }
});