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
decimalUnderlying asset price.
strike
decimalThe strike price.
riskFree
decimalThe risk free interest rate.
dividend
decimalThe dividend amount on shares.
deviation
decimalStandard deviation.
timeToExp
doubleThe 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
doubleThe d1 parameter of the option fulfilment probability estimating.
deviation
decimalStandard deviation.
timeToExp
doubleThe 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
OptionTypesOption type.
assetPrice
decimalUnderlying asset price.
d1
doubleThe 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
decimalThe risk free interest rate.
timeToExp
doubleThe 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
OptionTypesOption 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
decimalThe 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
SecurityUnderlying 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
decimalUnderlying asset price.
deviation
decimalStandard deviation.
timeToExp
doubleThe option period before the expiration.
d1
doubleThe 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
SecurityThe derivative.
provider
ISecurityProviderThe 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
SecurityUnderlying asset.
provider
IMarketDataProviderThe 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
SecurityUnderlying asset.
securityProvider
ISecurityProviderThe provider of information about instruments.
dataProvider
IMarketDataProviderThe 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
SecurityUnderlying futures.
provider
ISecurityProviderThe provider of information about instruments.
strike
decimalStrike.
expirationDate
DateTimeOffsetThe 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
SecurityUnderlying asset.
provider
IMarketDataProviderThe 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
SecurityUnderlying asset.
securityProvider
ISecurityProviderThe provider of information about instruments.
dataProvider
IMarketDataProviderThe market data provider.
expirationDate
DateTimeOffsetThe options expiration date.
optionType
OptionTypesOption 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
SecurityUnderlying asset.
provider
ISecurityProviderThe 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
DateTimeOffsetThe option expiration time.
currentTime
DateTimeOffsetThe 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
DateTimeOffsetThe option expiration time.
currentTime
DateTimeOffsetThe current time.
timeLine
TimeSpanThe 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
stringThe futures name.
optionCode
stringThe option code.
board
ExchangeBoardBoard 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
SecurityUnderlying asset.
provider
IMarketDataProviderThe 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
SecurityUnderlying asset.
securityProvider
ISecurityProviderThe provider of information about instruments.
dataProvider
IMarketDataProviderThe 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
SecurityOptions contract.
securityProvider
ISecurityProviderThe provider of information about instruments.
dataProvider
IMarketDataProviderThe 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
SecurityOptions contract.
provider
ISecurityProviderThe 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
SecurityUnderlying futures.
provider
ISecurityProviderThe provider of information about instruments.
strike
decimalStrike.
expirationDate
DateTimeOffsetThe options expiration date.
optionType
OptionTypesOption 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
stringThe option name.
board
ExchangeBoardBoard 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
SecurityUnderlying asset.
provider
IMarketDataProviderThe 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
SecurityUnderlying asset.
securityProvider
ISecurityProviderThe provider of information about instruments.
dataProvider
IMarketDataProviderThe 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
SecurityUnderlying futures.
provider
ISecurityProviderThe provider of information about instruments.
strike
decimalStrike.
expirationDate
DateTimeOffsetThe 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
SecurityUnderlying asset.
provider
ISecurityProviderThe 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
SecurityOptions contract.
securityProvider
ISecurityProviderThe provider of information about instruments.
dataProvider
IMarketDataProviderThe 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
SecurityThe derivative.
provider
ISecurityProviderThe 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
IOrderBookMessageThe order book quotes of which will be changed to volatility quotes.
model
IBlackScholesThe model for calculating Greeks values by the Black-Scholes formula.
currentTime
DateTimeOffsetThe 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
IOrderBookMessageThe order book quotes of which will be changed to volatility quotes.
securityProvider
ISecurityProviderThe provider of information about instruments.
dataProvider
IMarketDataProviderThe market data provider.
exchangeInfoProvider
IExchangeInfoProviderExchanges and trading boards provider.
currentTime
DateTimeOffsetThe current time.
riskFree
decimalThe risk free interest rate.
dividend
decimalThe 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
decimalThe 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
OptionTypesThe 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
SecuritySecurity.
exchangeInfoProvider
IExchangeInfoProviderExchanges and trading boards provider.
currentTime
DateTimeOffsetThe 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
optionType
OptionTypesOption type.
strike
decimalThe strike price.
assetPrice
decimalUnderlying asset price.
riskFree
decimalThe risk free interest rate.
dividend
decimalThe dividend amount on shares.
deviation
decimalStandard deviation.
timeToExp
doubleThe option period before the expiration.
d1
doubleThe 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
OptionTypesOption type.
strike
decimalThe strike price.
assetPrice
decimalUnderlying asset price.
riskFree
decimalThe risk free interest rate.
deviation
decimalStandard deviation.
timeToExp
doubleThe option period before the expiration.
d1
doubleThe 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
OptionTypesOption type.
strike
decimalThe strike price.
assetPrice
decimalUnderlying asset price.
riskFree
decimalThe risk free interest rate.
deviation
decimalStandard deviation.
timeToExp
doubleThe option period before the expiration.
d1
doubleThe d1 parameter of the option fulfilment probability estimating.
daysInYear
decimalDays 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
decimalUnderlying asset price.
timeToExp
doubleThe option period before the expiration.
d1
doubleThe d1 parameter of the option fulfilment probability estimating.
Returns
- decimal
Option vega.