Table of Contents

Class DerivativesHelper

Namespace
StockSharp.Algo.Derivatives
Assembly
StockSharp.Algo.dll

Extension class for derivatives.

public static class DerivativesHelper
Inheritance
DerivativesHelper
Inherited Members

Methods

D1(decimal, decimal, decimal, decimal, decimal, double)

To calculate the d1 parameter of the option fulfilment probability estimating.

public static double D1(decimal assetPrice, decimal strike, decimal riskFree, decimal dividend, decimal deviation, double timeToExp)

Parameters

assetPrice decimal

Underlying asset price.

strike decimal

The strike price.

riskFree decimal

The risk free interest rate.

dividend decimal

The dividend amount on shares.

deviation decimal

Standard deviation.

timeToExp double

The option period before the expiration.

Returns

double

The d1 parameter of the option fulfilment probability estimating.

D2(double, decimal, double)

To calculate the d2 parameter of the option fulfilment probability estimating.

public static double D2(double d1, decimal deviation, double timeToExp)

Parameters

d1 double

The d1 parameter of the option fulfilment probability estimating.

deviation decimal

Standard deviation.

timeToExp double

The option period before the expiration.

Returns

double

The d2 parameter of the option fulfilment probability estimating.

Delta(OptionTypes, decimal, double)

To calculate the option delta.

public static decimal Delta(OptionTypes optionType, decimal assetPrice, double d1)

Parameters

optionType OptionTypes

Option type.

assetPrice decimal

Underlying asset price.

d1 double

The d1 parameter of the option fulfilment probability estimating.

Returns

decimal

Option delta.

ExpRate(decimal, double)

To calculate the time exhibitor.

public static double ExpRate(decimal riskFree, double timeToExp)

Parameters

riskFree decimal

The risk free interest rate.

timeToExp double

The option period before the expiration.

Returns

double

The time exhibitor.

Filter(IEnumerable<Security>, OptionTypes)

To filter options by type OptionType.

public static IEnumerable<Security> Filter(this IEnumerable<Security> options, OptionTypes type)

Parameters

options IEnumerable<Security>

Options to be filtered.

type OptionTypes

Option type.

Returns

IEnumerable<Security>

Filtered options.

Filter(IEnumerable<Security>, decimal)

To filter options by the strike Strike.

public static IEnumerable<Security> Filter(this IEnumerable<Security> options, decimal strike)

Parameters

options IEnumerable<Security>

Options to be filtered.

strike decimal

The strike price.

Returns

IEnumerable<Security>

Filtered options.

Filter(IEnumerable<Security>, DateTimeOffset?)

To filter instruments by the expiration date ExpiryDate.

public static IEnumerable<Security> Filter(this IEnumerable<Security> securities, DateTimeOffset? expirationDate)

Parameters

securities IEnumerable<Security>

Instruments to be filtered.

expirationDate DateTimeOffset?

The expiration date.

Returns

IEnumerable<Security>

Instruments filtered.

FilterByUnderlying(IEnumerable<Security>, Security)

To filter instruments by the underlying asset.

public static IEnumerable<Security> FilterByUnderlying(this IEnumerable<Security> securities, Security asset)

Parameters

securities IEnumerable<Security>

Instruments to be filtered.

asset Security

Underlying asset.

Returns

IEnumerable<Security>

Instruments filtered.

Gamma(decimal, decimal, double, double)

To calculate the option gamma.

public static decimal Gamma(decimal assetPrice, decimal deviation, double timeToExp, double d1)

Parameters

assetPrice decimal

Underlying asset price.

deviation decimal

Standard deviation.

timeToExp double

The option period before the expiration.

d1 double

The d1 parameter of the option fulfilment probability estimating.

Returns

decimal

Option gamma.

GetAsset(Security, ISecurityProvider)

To get the underlying asset.

public static Security GetAsset(this Security derivative, ISecurityProvider provider)

Parameters

derivative Security

The derivative.

provider ISecurityProvider

The provider of information about instruments.

Returns

Security

Underlying asset.

GetAtTheMoney(Security, IMarketDataProvider, IEnumerable<Security>)

To get at the money options (ATM).

public static IEnumerable<Security> GetAtTheMoney(this Security underlyingAsset, IMarketDataProvider provider, IEnumerable<Security> allStrikes)

Parameters

underlyingAsset Security

Underlying asset.

provider IMarketDataProvider

The market data provider.

allStrikes IEnumerable<Security>

All strikes.

Returns

IEnumerable<Security>

At the money options.

GetAtTheMoney(Security, ISecurityProvider, IMarketDataProvider)

To get at the money options (ATM).

public static IEnumerable<Security> GetAtTheMoney(this Security underlyingAsset, ISecurityProvider securityProvider, IMarketDataProvider dataProvider)

Parameters

underlyingAsset Security

Underlying asset.

securityProvider ISecurityProvider

The provider of information about instruments.

dataProvider IMarketDataProvider

The market data provider.

Returns

IEnumerable<Security>

At the money options.

GetCall(Security, ISecurityProvider, decimal, DateTimeOffset)

To get Call for the underlying futures.

public static Security GetCall(this Security future, ISecurityProvider provider, decimal strike, DateTimeOffset expirationDate)

Parameters

future Security

Underlying futures.

provider ISecurityProvider

The provider of information about instruments.

strike decimal

Strike.

expirationDate DateTimeOffset

The date of the option expiration.

Returns

Security

The Call option.

GetCentralStrike(Security, IMarketDataProvider, IEnumerable<Security>)

To get the main strike.

public static Security GetCentralStrike(this Security underlyingAsset, IMarketDataProvider provider, IEnumerable<Security> allStrikes)

Parameters

underlyingAsset Security

Underlying asset.

provider IMarketDataProvider

The market data provider.

allStrikes IEnumerable<Security>

All strikes.

Returns

Security

The main strike. If it is impossible to get the current market price of the asset then the null will be returned.

GetCentralStrike(Security, ISecurityProvider, IMarketDataProvider, DateTimeOffset, OptionTypes)

To get the main strike.

public static Security GetCentralStrike(this Security underlyingAsset, ISecurityProvider securityProvider, IMarketDataProvider dataProvider, DateTimeOffset expirationDate, OptionTypes optionType)

Parameters

underlyingAsset Security

Underlying asset.

securityProvider ISecurityProvider

The provider of information about instruments.

dataProvider IMarketDataProvider

The market data provider.

expirationDate DateTimeOffset

The options expiration date.

optionType OptionTypes

Option type.

Returns

Security

The main strike.

GetDerivatives(Security, ISecurityProvider, DateTimeOffset?)

To get derivatives by the underlying asset.

public static IEnumerable<Security> GetDerivatives(this Security asset, ISecurityProvider provider, DateTimeOffset? expirationDate = null)

Parameters

asset Security

Underlying asset.

provider ISecurityProvider

The provider of information about instruments.

expirationDate DateTimeOffset?

The expiration date.

Returns

IEnumerable<Security>

The list of derivatives.

Remarks

It returns an empty list if derivatives are not found.

GetExpirationTimeLine(DateTimeOffset, DateTimeOffset)

To get the option period before expiration.

public static double? GetExpirationTimeLine(DateTimeOffset expirationTime, DateTimeOffset currentTime)

Parameters

expirationTime DateTimeOffset

The option expiration time.

currentTime DateTimeOffset

The current time.

Returns

double?

The option period before expiration. If the value is equal to null, then the value calculation currently is impossible.

GetExpirationTimeLine(DateTimeOffset, DateTimeOffset, TimeSpan)

To get the option period before expiration.

public static double? GetExpirationTimeLine(DateTimeOffset expirationTime, DateTimeOffset currentTime, TimeSpan timeLine)

Parameters

expirationTime DateTimeOffset

The option expiration time.

currentTime DateTimeOffset

The current time.

timeLine TimeSpan

The length of the total period.

Returns

double?

The option period before expiration. If the value is equal to null, then the value calculation currently is impossible.

GetFutureInfo(string, string, ExchangeBoard)

To get the information about the futures from its name (underlying asset, expiration date, etc.).

public static SecurityMessage GetFutureInfo(this string futureName, string optionCode, ExchangeBoard board)

Parameters

futureName string

The futures name.

optionCode string

The option code.

board ExchangeBoard

Board info.

Returns

SecurityMessage

Information about futures.

GetInTheMoney(Security, IMarketDataProvider, IEnumerable<Security>)

To get in the money options (ITM).

public static IEnumerable<Security> GetInTheMoney(this Security underlyingAsset, IMarketDataProvider provider, IEnumerable<Security> allStrikes)

Parameters

underlyingAsset Security

Underlying asset.

provider IMarketDataProvider

The market data provider.

allStrikes IEnumerable<Security>

All strikes.

Returns

IEnumerable<Security>

In the money options.

GetInTheMoney(Security, ISecurityProvider, IMarketDataProvider)

To get in the money options (ITM).

public static IEnumerable<Security> GetInTheMoney(this Security underlyingAsset, ISecurityProvider securityProvider, IMarketDataProvider dataProvider)

Parameters

underlyingAsset Security

Underlying asset.

securityProvider ISecurityProvider

The provider of information about instruments.

dataProvider IMarketDataProvider

The market data provider.

Returns

IEnumerable<Security>

In the money options.

GetIntrinsicValue(Security, ISecurityProvider, IMarketDataProvider)

To get the internal option value.

public static decimal? GetIntrinsicValue(this Security option, ISecurityProvider securityProvider, IMarketDataProvider dataProvider)

Parameters

option Security

Options contract.

securityProvider ISecurityProvider

The provider of information about instruments.

dataProvider IMarketDataProvider

The market data provider.

Returns

decimal?

The internal value. If it is impossible to get the current market price of the asset then the null will be returned.

GetOppositeOption(Security, ISecurityProvider)

To get opposite option (for Call to get Put, for Put to get Call).

public static Security GetOppositeOption(this Security option, ISecurityProvider provider)

Parameters

option Security

Options contract.

provider ISecurityProvider

The provider of information about instruments.

Returns

Security

The opposite option.

GetOption(Security, ISecurityProvider, decimal, DateTimeOffset, OptionTypes)

To get an option for the underlying futures.

public static Security GetOption(this Security future, ISecurityProvider provider, decimal strike, DateTimeOffset expirationDate, OptionTypes optionType)

Parameters

future Security

Underlying futures.

provider ISecurityProvider

The provider of information about instruments.

strike decimal

Strike.

expirationDate DateTimeOffset

The options expiration date.

optionType OptionTypes

Option type.

Returns

Security

Options contract.

GetOptionInfo(string, ExchangeBoard)

To get the information about the option from its name (underlying asset, strike, expiration date, etc.).

public static Security GetOptionInfo(this string optionName, ExchangeBoard board)

Parameters

optionName string

The option name.

board ExchangeBoard

Board info.

Returns

Security

Information about the option.

GetOutOfTheMoney(Security, IMarketDataProvider, IEnumerable<Security>)

To get out of the money options (OTM).

public static IEnumerable<Security> GetOutOfTheMoney(this Security underlyingAsset, IMarketDataProvider provider, IEnumerable<Security> allStrikes)

Parameters

underlyingAsset Security

Underlying asset.

provider IMarketDataProvider

The market data provider.

allStrikes IEnumerable<Security>

All strikes.

Returns

IEnumerable<Security>

Out of the money options.

GetOutOfTheMoney(Security, ISecurityProvider, IMarketDataProvider)

To get out of the money options (OTM).

public static IEnumerable<Security> GetOutOfTheMoney(this Security underlyingAsset, ISecurityProvider securityProvider, IMarketDataProvider dataProvider)

Parameters

underlyingAsset Security

Underlying asset.

securityProvider ISecurityProvider

The provider of information about instruments.

dataProvider IMarketDataProvider

The market data provider.

Returns

IEnumerable<Security>

Out of the money options.

GetPut(Security, ISecurityProvider, decimal, DateTimeOffset)

To get Put for the underlying futures.

public static Security GetPut(this Security future, ISecurityProvider provider, decimal strike, DateTimeOffset expirationDate)

Parameters

future Security

Underlying futures.

provider ISecurityProvider

The provider of information about instruments.

strike decimal

Strike.

expirationDate DateTimeOffset

The date of the option expiration.

Returns

Security

The Put option.

GetStrikeStep(Security, ISecurityProvider, DateTimeOffset?)

To get the strike step size.

public static decimal GetStrikeStep(this Security underlyingAsset, ISecurityProvider provider, DateTimeOffset? expirationDate = null)

Parameters

underlyingAsset Security

Underlying asset.

provider ISecurityProvider

The provider of information about instruments.

expirationDate DateTimeOffset?

The options expiration date (to specify a particular series).

Returns

decimal

The strike step size.

GetTimeValue(Security, ISecurityProvider, IMarketDataProvider)

To get the timed option value.

public static decimal? GetTimeValue(this Security option, ISecurityProvider securityProvider, IMarketDataProvider dataProvider)

Parameters

option Security

Options contract.

securityProvider ISecurityProvider

The provider of information about instruments.

dataProvider IMarketDataProvider

The market data provider.

Returns

decimal?

The timed value. If it is impossible to get the current market price of the asset then the null will be returned.

GetUnderlyingAsset(Security, ISecurityProvider)

To get the underlying asset by the derivative.

public static Security GetUnderlyingAsset(this Security derivative, ISecurityProvider provider)

Parameters

derivative Security

The derivative.

provider ISecurityProvider

The provider of information about instruments.

Returns

Security

Underlying asset.

ImpliedVolatility(IOrderBookMessage, IBlackScholes, DateTimeOffset)

To create the volatility order book from usual order book.

public static QuoteChangeMessage ImpliedVolatility(this IOrderBookMessage depth, IBlackScholes model, DateTimeOffset currentTime)

Parameters

depth IOrderBookMessage

The order book quotes of which will be changed to volatility quotes.

model IBlackScholes

The model for calculating Greeks values by the Black-Scholes formula.

currentTime DateTimeOffset

The current time.

Returns

QuoteChangeMessage

The order book volatility.

ImpliedVolatility(IOrderBookMessage, ISecurityProvider, IMarketDataProvider, IExchangeInfoProvider, DateTimeOffset, decimal, decimal)

To create the volatility order book from usual order book.

public static QuoteChangeMessage ImpliedVolatility(this IOrderBookMessage depth, ISecurityProvider securityProvider, IMarketDataProvider dataProvider, IExchangeInfoProvider exchangeInfoProvider, DateTimeOffset currentTime, decimal riskFree = 0, decimal dividend = 0)

Parameters

depth IOrderBookMessage

The order book quotes of which will be changed to volatility quotes.

securityProvider ISecurityProvider

The provider of information about instruments.

dataProvider IMarketDataProvider

The market data provider.

exchangeInfoProvider IExchangeInfoProvider

Exchanges and trading boards provider.

currentTime DateTimeOffset

The current time.

riskFree decimal

The risk free interest rate.

dividend decimal

The dividend amount on shares.

Returns

QuoteChangeMessage

The order book volatility.

ImpliedVolatility(decimal, Func<decimal, decimal?>)

To calculate the implied volatility.

public static decimal? ImpliedVolatility(decimal premium, Func<decimal, decimal?> getPremium)

Parameters

premium decimal

The option premium.

getPremium Func<decimal, decimal?>

To calculate the premium by volatility.

Returns

decimal?

The implied volatility. If the value is equal to null, then the value calculation currently is impossible.

Invert(OptionTypes)

To change the option type for opposite.

public static OptionTypes Invert(this OptionTypes type)

Parameters

type OptionTypes

The initial value.

Returns

OptionTypes

The opposite value.

IsExpired(Security, IExchangeInfoProvider, DateTimeOffset)

To check whether the instrument has finished the action.

public static bool IsExpired(this Security security, IExchangeInfoProvider exchangeInfoProvider, DateTimeOffset currentTime)

Parameters

security Security

Security.

exchangeInfoProvider IExchangeInfoProvider

Exchanges and trading boards provider.

currentTime DateTimeOffset

The current time.

Returns

bool

true if the instrument has finished its action.

Premium(OptionTypes, decimal, decimal, decimal, decimal, decimal, double, double)

To calculate the option premium.

public static decimal Premium(OptionTypes optionType, decimal strike, decimal assetPrice, decimal riskFree, decimal dividend, decimal deviation, double timeToExp, double d1)

Parameters

optionType OptionTypes

Option type.

strike decimal

The strike price.

assetPrice decimal

Underlying asset price.

riskFree decimal

The risk free interest rate.

dividend decimal

The dividend amount on shares.

deviation decimal

Standard deviation.

timeToExp double

The option period before the expiration.

d1 double

The d1 parameter of the option fulfilment probability estimating.

Returns

decimal

The option premium.

Rho(OptionTypes, decimal, decimal, decimal, decimal, double, double)

To calculate the option rho.

public static decimal Rho(OptionTypes optionType, decimal strike, decimal assetPrice, decimal riskFree, decimal deviation, double timeToExp, double d1)

Parameters

optionType OptionTypes

Option type.

strike decimal

The strike price.

assetPrice decimal

Underlying asset price.

riskFree decimal

The risk free interest rate.

deviation decimal

Standard deviation.

timeToExp double

The option period before the expiration.

d1 double

The d1 parameter of the option fulfilment probability estimating.

Returns

decimal

Option rho.

Theta(OptionTypes, decimal, decimal, decimal, decimal, double, double, decimal)

To calculate the option theta.

public static decimal Theta(OptionTypes optionType, decimal strike, decimal assetPrice, decimal riskFree, decimal deviation, double timeToExp, double d1, decimal daysInYear = 365)

Parameters

optionType OptionTypes

Option type.

strike decimal

The strike price.

assetPrice decimal

Underlying asset price.

riskFree decimal

The risk free interest rate.

deviation decimal

Standard deviation.

timeToExp double

The option period before the expiration.

d1 double

The d1 parameter of the option fulfilment probability estimating.

daysInYear decimal

Days per year.

Returns

decimal

Option theta.

Vega(decimal, double, double)

To calculate the option vega.

public static decimal Vega(decimal assetPrice, double timeToExp, double d1)

Parameters

assetPrice decimal

Underlying asset price.

timeToExp double

The option period before the expiration.

d1 double

The d1 parameter of the option fulfilment probability estimating.

Returns

decimal

Option vega.