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
assetPricedecimalUnderlying asset price.
strikedecimalThe strike price.
riskFreedecimalThe risk free interest rate.
dividenddecimalThe dividend amount on shares.
deviationdecimalStandard deviation.
timeToExpdoubleThe 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
d1doubleThe d1 parameter of the option fulfilment probability estimating.
deviationdecimalStandard deviation.
timeToExpdoubleThe 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
optionTypeOptionTypesOption type.
assetPricedecimalUnderlying asset price.
d1doubleThe 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
riskFreedecimalThe risk free interest rate.
timeToExpdoubleThe 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
optionsIEnumerable<Security>Options to be filtered.
typeOptionTypesOption 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
optionsIEnumerable<Security>Options to be filtered.
strikedecimalThe 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
securitiesIEnumerable<Security>Instruments to be filtered.
expirationDateDateTimeOffset?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
securitiesIEnumerable<Security>Instruments to be filtered.
assetSecurityUnderlying 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
assetPricedecimalUnderlying asset price.
deviationdecimalStandard deviation.
timeToExpdoubleThe option period before the expiration.
d1doubleThe 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
derivativeSecurityThe derivative.
providerISecurityProviderThe provider of information about instruments.
Returns
- Security
Underlying asset.
GetAtTheMoney(Security, ISecurityProvider, decimal)
To get at the money options (ATM).
public static IEnumerable<Security> GetAtTheMoney(this Security underlyingAsset, ISecurityProvider securityProvider, decimal assetPrice)
Parameters
underlyingAssetSecurityUnderlying asset.
securityProviderISecurityProviderThe provider of information about instruments.
assetPricedecimalThe asset price.
Returns
- IEnumerable<Security>
At the money options.
GetAtTheMoney(Security, IEnumerable<Security>, decimal)
To get at the money options (ATM).
public static IEnumerable<Security> GetAtTheMoney(this Security underlyingAsset, IEnumerable<Security> allStrikes, decimal assetPrice)
Parameters
underlyingAssetSecurityUnderlying asset.
allStrikesIEnumerable<Security>All strikes.
assetPricedecimalThe asset price.
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
futureSecurityUnderlying futures.
providerISecurityProviderThe provider of information about instruments.
strikedecimalStrike.
expirationDateDateTimeOffsetThe date of the option expiration.
Returns
- Security
The Call option.
GetCentralStrike(Security, ISecurityProvider, DateTimeOffset, OptionTypes, decimal)
To get the main strike.
public static Security GetCentralStrike(this Security underlyingAsset, ISecurityProvider securityProvider, DateTimeOffset expirationDate, OptionTypes optionType, decimal assetPrice)
Parameters
underlyingAssetSecurityUnderlying asset.
securityProviderISecurityProviderThe provider of information about instruments.
expirationDateDateTimeOffsetThe options expiration date.
optionTypeOptionTypesOption type.
assetPricedecimalThe current market price of the asset. It is used to calculate the main strike.
Returns
- Security
The main strike.
GetCentralStrike(IEnumerable<Security>, decimal)
To get the main strike.
public static Security GetCentralStrike(this IEnumerable<Security> allStrikes, decimal assetPrice)
Parameters
allStrikesIEnumerable<Security>All strikes.
assetPricedecimalThe current market price of the asset. It is used to calculate the main strike.
Returns
- Security
The main strike. If it is impossible to get the current market price of the asset then the null will be returned.
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
assetSecurityUnderlying asset.
providerISecurityProviderThe provider of information about instruments.
expirationDateDateTimeOffset?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
expirationTimeDateTimeOffsetThe option expiration time.
currentTimeDateTimeOffsetThe 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
expirationTimeDateTimeOffsetThe option expiration time.
currentTimeDateTimeOffsetThe current time.
timeLineTimeSpanThe 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
futureNamestringThe futures name.
optionCodestringThe option code.
boardExchangeBoardBoard info.
Returns
- SecurityMessage
Information about futures.
GetInTheMoney(Security, ISecurityProvider, decimal)
To get in the money options (ITM).
public static IEnumerable<Security> GetInTheMoney(this Security underlyingAsset, ISecurityProvider securityProvider, decimal assetPrice)
Parameters
underlyingAssetSecurityUnderlying asset.
securityProviderISecurityProviderThe provider of information about instruments.
assetPricedecimalThe asset price.
Returns
- IEnumerable<Security>
In the money options.
GetInTheMoney(Security, IEnumerable<Security>, decimal)
To get in the money options (ITM).
public static IEnumerable<Security> GetInTheMoney(this Security underlyingAsset, IEnumerable<Security> allStrikes, decimal assetPrice)
Parameters
underlyingAssetSecurityUnderlying asset.
allStrikesIEnumerable<Security>All strikes.
assetPricedecimalThe asset price.
Returns
- IEnumerable<Security>
In the money options.
GetIntrinsicValue(Security, decimal)
To get the internal option value.
public static decimal GetIntrinsicValue(this Security option, decimal assetPrice)
Parameters
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
optionSecurityOptions contract.
providerISecurityProviderThe 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
futureSecurityUnderlying futures.
providerISecurityProviderThe provider of information about instruments.
strikedecimalStrike.
expirationDateDateTimeOffsetThe options expiration date.
optionTypeOptionTypesOption 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
optionNamestringThe option name.
boardExchangeBoardBoard info.
Returns
- Security
Information about the option.
GetOutOfTheMoney(Security, ISecurityProvider, decimal)
To get out of the money options (OTM).
public static IEnumerable<Security> GetOutOfTheMoney(this Security underlyingAsset, ISecurityProvider securityProvider, decimal assetPrice)
Parameters
underlyingAssetSecurityUnderlying asset.
securityProviderISecurityProviderThe provider of information about instruments.
assetPricedecimalThe asset price.
Returns
- IEnumerable<Security>
Out of the money options.
GetOutOfTheMoney(Security, IEnumerable<Security>, decimal)
To get out of the money options (OTM).
public static IEnumerable<Security> GetOutOfTheMoney(this Security underlyingAsset, IEnumerable<Security> allStrikes, decimal assetPrice)
Parameters
underlyingAssetSecurityUnderlying asset.
allStrikesIEnumerable<Security>All strikes.
assetPricedecimalThe asset price.
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
futureSecurityUnderlying futures.
providerISecurityProviderThe provider of information about instruments.
strikedecimalStrike.
expirationDateDateTimeOffsetThe 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
underlyingAssetSecurityUnderlying asset.
providerISecurityProviderThe provider of information about instruments.
expirationDateDateTimeOffset?The options expiration date (to specify a particular series).
Returns
- decimal
The strike step size.
GetTimeValue(Security, decimal, decimal)
To get the timed option value.
public static decimal GetTimeValue(Security option, decimal currentPrice, decimal assetPrice)
Parameters
optionSecurityOptions contract.
currentPricedecimalThe contract price.
assetPricedecimalThe underlying asset price.
Returns
- decimal
The timed value.
GetUnderlyingAsset(Security, ISecurityProvider)
To get the underlying asset by the derivative.
public static Security GetUnderlyingAsset(this Security derivative, ISecurityProvider provider)
Parameters
derivativeSecurityThe derivative.
providerISecurityProviderThe 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
depthIOrderBookMessageThe order book quotes of which will be changed to volatility quotes.
modelIBlackScholesThe model for calculating Greeks values by the Black-Scholes formula.
currentTimeDateTimeOffsetThe 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
depthIOrderBookMessageThe order book quotes of which will be changed to volatility quotes.
securityProviderISecurityProviderThe provider of information about instruments.
dataProviderIMarketDataProviderThe market data provider.
exchangeInfoProviderIExchangeInfoProviderExchanges and trading boards provider.
currentTimeDateTimeOffsetThe current time.
riskFreedecimalThe risk free interest rate.
dividenddecimalThe 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
premiumdecimalThe option premium.
getPremiumFunc<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
typeOptionTypesThe 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
securitySecuritySecurity.
exchangeInfoProviderIExchangeInfoProviderExchanges and trading boards provider.
currentTimeDateTimeOffsetThe current time.
Returns
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
optionTypeOptionTypesOption type.
strikedecimalThe strike price.
assetPricedecimalUnderlying asset price.
riskFreedecimalThe risk free interest rate.
dividenddecimalThe dividend amount on shares.
deviationdecimalStandard deviation.
timeToExpdoubleThe option period before the expiration.
d1doubleThe 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
optionTypeOptionTypesOption type.
strikedecimalThe strike price.
assetPricedecimalUnderlying asset price.
riskFreedecimalThe risk free interest rate.
deviationdecimalStandard deviation.
timeToExpdoubleThe option period before the expiration.
d1doubleThe 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
optionTypeOptionTypesOption type.
strikedecimalThe strike price.
assetPricedecimalUnderlying asset price.
riskFreedecimalThe risk free interest rate.
deviationdecimalStandard deviation.
timeToExpdoubleThe option period before the expiration.
d1doubleThe d1 parameter of the option fulfilment probability estimating.
daysInYeardecimalDays 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
assetPricedecimalUnderlying asset price.
timeToExpdoubleThe option period before the expiration.
d1doubleThe d1 parameter of the option fulfilment probability estimating.
Returns
- decimal
Option vega.