BlackScholes
The model for calculating Greeks values by the Black-Scholes formula.
Implements: IBlackScholes
Constructors
protected BlackScholes(IMarketDataProvider dataProvider, DateTime? expirationTime)
blackScholes = BlackScholes(dataProvider, expirationTime)
Base constructor for inherited models.
- dataProvider
- The market data provider.
- expirationTime
- Explicit option expiration moment. If null, midnight of ExpiryDate is used when available.
public BlackScholes(Security option, Security underlyingAsset, IMarketDataProvider dataProvider, DateTime? expirationTime)
blackScholes = BlackScholes(option, underlyingAsset, dataProvider, expirationTime)
Initializes a new instance of BlackScholes for a specific option with its underlying asset.
- option
- Options contract.
- underlyingAsset
- Underlying asset.
- dataProvider
- The market data provider.
- expirationTime
- Explicit option expiration moment. If null, midnight of ExpiryDate is used when available.
protected BlackScholes(Security underlyingAsset, IMarketDataProvider dataProvider, DateTime? expirationTime)
blackScholes = BlackScholes(underlyingAsset, dataProvider, expirationTime)
Initializes a new instance of the BlackScholes for an underlying asset only (non-option models).
- underlyingAsset
- Underlying asset.
- dataProvider
- The market data provider.
- expirationTime
- Explicit option expiration moment. If null, midnight of ExpiryDate is used when available.
Properties
public virtual IMarketDataProvider DataProvider { get; }
value = blackScholes.DataProvider
The market data provider.
public decimal DefaultDeviation { get; }
value = blackScholes.DefaultDeviation
The standard deviation by default.
public virtual decimal Dividend { get; set; }
value = blackScholes.Dividend
blackScholes.Dividend = value
The dividend amount on shares.
public DateTime? ExpirationTime { get; set; }
value = blackScholes.ExpirationTime
blackScholes.ExpirationTime = value
Explicit expiration moment. If null, midnight of ExpiryDate is used when available.
public decimal RiskFree { get; set; }
value = blackScholes.RiskFree
blackScholes.RiskFree = value
The risk free interest rate.
public virtual int RoundDecimals { get; set; }
value = blackScholes.RoundDecimals
blackScholes.RoundDecimals = value
The number of decimal places at calculated values. The default is -1, which means no values rounding.
public virtual Security UnderlyingAsset { get; set; }
value = blackScholes.UnderlyingAsset
blackScholes.UnderlyingAsset = value
Underlying asset.
Methods
protected virtual double D1(decimal deviation, decimal assetPrice, double timeToExp)
result = blackScholes.D1(deviation, assetPrice, timeToExp)
To calculate the d1 parameter of the option fulfilment probability estimating.
- deviation
- Standard deviation.
- assetPrice
- Underlying asset price.
- timeToExp
- The option period before the expiration.
Returns: The d1 parameter.
public virtual decimal? Delta(DateTime currentTime, decimal? deviation, decimal? assetPrice)
result = blackScholes.Delta(currentTime, deviation, assetPrice)
To calculate the option delta.
- currentTime
- The current time.
- deviation
- Standard deviation.
- assetPrice
- Underlying asset price.
Returns: The option delta. If the value is equal to , then the value calculation currently is impossible.
public virtual decimal? Gamma(DateTime currentTime, decimal? deviation, decimal? assetPrice)
result = blackScholes.Gamma(currentTime, deviation, assetPrice)
To calculate the option gamma.
- currentTime
- The current time.
- deviation
- Standard deviation.
- assetPrice
- Underlying asset price.
Returns: The option gamma. If the value is equal to , then the value calculation currently is impossible.
public decimal? GetAssetPrice(decimal? assetPrice)
result = blackScholes.GetAssetPrice(assetPrice)
To get the price of the underlying asset.
- assetPrice
- The price of the underlying asset if it is specified.
Returns: The price of the underlying asset. If the value is equal to , then the value calculation currently is impossible.
public virtual double? GetExpirationTimeLine(DateTime currentTime)
result = blackScholes.GetExpirationTimeLine(currentTime)
The time before expiration calculation.
- currentTime
- The current time.
Returns: The time remaining until expiration. If the value is equal to , then the value calculation currently is impossible.
public virtual decimal? ImpliedVolatility(DateTime currentTime, decimal premium)
result = blackScholes.ImpliedVolatility(currentTime, premium)
To calculate the implied volatility.
- currentTime
- The current time.
- premium
- The option premium.
Returns: The implied volatility. If the value is equal to , then the value calculation currently is impossible.
public virtual decimal? Premium(DateTime currentTime, decimal? deviation, decimal? assetPrice)
result = blackScholes.Premium(currentTime, deviation, assetPrice)
To calculate the option premium.
- currentTime
- The current time.
- deviation
- Standard deviation.
- assetPrice
- Underlying asset price.
Returns: The option premium. If the value is equal to , then the value calculation currently is impossible.
public virtual decimal? Rho(DateTime currentTime, decimal? deviation, decimal? assetPrice)
result = blackScholes.Rho(currentTime, deviation, assetPrice)
To calculate the option rho.
- currentTime
- The current time.
- deviation
- Standard deviation.
- assetPrice
- Underlying asset price.
Returns: The option rho. If the value is equal to , then the value calculation currently is impossible.
public virtual decimal? Theta(DateTime currentTime, decimal? deviation, decimal? assetPrice)
result = blackScholes.Theta(currentTime, deviation, assetPrice)
To calculate the option theta.
- currentTime
- The current time.
- deviation
- Standard deviation.
- assetPrice
- Underlying asset price.
Returns: The option theta. If the value is equal to , then the value calculation currently is impossible.
protected decimal? TryRound(decimal? value)
result = blackScholes.TryRound(value)
To round to RoundDecimals.
- value
- The initial value.
Returns: The rounded value.
public virtual decimal? Vega(DateTime currentTime, decimal? deviation, decimal? assetPrice)
result = blackScholes.Vega(currentTime, deviation, assetPrice)
To calculate the option vega.
- currentTime
- The current time.
- deviation
- Standard deviation.
- assetPrice
- Underlying asset price.
Returns: The option vega. If the value is equal to , then the value calculation currently is impossible.