options module

btQuant.options.asian(S, K, T, r, sigma, q=0.0, nSteps=100, optType='call', avgType='geometric')[source]

Asian option pricing (option on average price).

Parameters:
  • S – current stock price

  • K – strike price

  • T – time to maturity (years)

  • r – risk-free rate

  • sigma – volatility

  • q – dividend yield

  • nSteps – number of averaging steps

  • optType – ‘call’ or ‘put’

  • avgType – ‘geometric’ or ‘arithmetic’

Returns:

price, delta, gamma, vega, rho, theta (or price, stderr for arithmetic)

Return type:

dict

btQuant.options.barrier(S, K, T, r, sigma, barrierLevel, q=0.0, optType='call', barrierType='down-and-out', rebate=0.0)[source]

Barrier option pricing (option that activates or deactivates at a barrier level).

Parameters:
  • S – current stock price

  • K – strike price

  • T – time to maturity (years)

  • r – risk-free rate

  • sigma – volatility

  • barrierLevel – barrier price level

  • q – dividend yield

  • optType – ‘call’ or ‘put’

  • barrierType – ‘down-and-out’, ‘down-and-in’, ‘up-and-out’, ‘up-and-in’

  • rebate – rebate payment if barrier is hit

Returns:

price, delta, gamma, vega

Return type:

dict

btQuant.options.binary(S, K, T, r, sigma, q=0.0, optType='call')[source]

Binary (digital) option pricing with Greeks.

Parameters:
  • S – current stock price

  • K – strike price

  • T – time to maturity (years)

  • r – risk-free rate

  • sigma – volatility

  • q – dividend yield

  • optType – ‘call’ or ‘put’

Returns:

price, delta, gamma, vega, rho, theta

Return type:

dict

btQuant.options.binomial(S, K, T, r, sigma, q=0.0, N=100, optType='call', american=False)[source]

Binomial tree option pricing model.

Parameters:
  • S – current stock price

  • K – strike price

  • T – time to maturity (years)

  • r – risk-free rate

  • sigma – volatility

  • q – dividend yield

  • N – number of time steps

  • optType – ‘call’ or ‘put’

  • american – True for American options, False for European

Returns:

price, delta, gamma, theta

Return type:

dict

btQuant.options.blackScholes(S, K, T, r, sigma, q=0.0, optType='call')[source]

Black-Scholes option pricing model with Greeks.

Parameters:
  • S – current stock price

  • K – strike price

  • T – time to maturity (years)

  • r – risk-free rate

  • sigma – volatility

  • q – dividend yield

  • optType – ‘call’ or ‘put’

Returns:

price, delta, gamma, vega, rho, theta

Return type:

dict

btQuant.options.bootstrapCurve(spotPrice, futuresPrices, tenors, assumedRate=0.05)[source]

Bootstrap convenience yields from futures prices.

Parameters:
  • spotPrice – current spot price

  • futuresPrices – observed futures prices array

  • tenors – time to maturity array (years)

  • assumedRate – assumed risk-free rate

Returns:

convenience_yields, storage_costs

Return type:

dict

btQuant.options.buildForwardCurve(spotPrice, tenors, rates, storageCosts=None, convenienceYields=None)[source]

Build forward curve for commodities or other assets.

Parameters:
  • spotPrice – current spot price

  • tenors – time to maturity array (years)

  • rates – risk-free rates array

  • storageCosts – storage cost rates array

  • convenienceYields – convenience yield rates array

Returns:

forward prices

Return type:

array

btQuant.options.impliedVol(price, S, K, T, r, optType='call', q=0.0, tol=1e-06, maxIter=100)[source]

Calculate implied volatility using Newton-Raphson method.

Parameters:
  • price – observed option price

  • S – current stock price

  • K – strike price

  • T – time to maturity (years)

  • r – risk-free rate

  • optType – ‘call’ or ‘put’

  • q – dividend yield

  • tol – convergence tolerance

  • maxIter – maximum iterations

Returns:

implied volatility (or np.nan if not converged)

Return type:

float

btQuant.options.simulate(pricingModel, paths, r, T, **modelParams)[source]

Monte Carlo simulation wrapper for option pricing.

Parameters:
  • pricingModel – pricing function to use

  • paths – simulated price paths (nSims x nSteps)

  • r – risk-free rate

  • T – time to maturity (years)

  • **modelParams – additional parameters for pricing model

Returns:

price, stderr

Return type:

dict

btQuant.options.spread(S1, S2, K, T, r, sigma1, sigma2, rho, q1=0.0, q2=0.0, optType='call')[source]

Spread option pricing (option on the difference between two assets).

Parameters:
  • S1 – current price of asset 1

  • S2 – current price of asset 2

  • K – strike price

  • T – time to maturity (years)

  • r – risk-free rate

  • sigma1 – volatility of asset 1

  • sigma2 – volatility of asset 2

  • rho – correlation between assets

  • q1 – dividend yield of asset 1

  • q2 – dividend yield of asset 2

  • optType – ‘call’ or ‘put’

Returns:

price, delta1, delta2, gamma1, gamma2, vega1, vega2

Return type:

dict

btQuant.options.trinomial(S, K, T, r, sigma, q=0.0, N=50, optType='call', american=False)[source]

Trinomial tree option pricing model.

Parameters:
  • S – current stock price

  • K – strike price

  • T – time to maturity (years)

  • r – risk-free rate

  • sigma – volatility

  • q – dividend yield

  • N – number of time steps

  • optType – ‘call’ or ‘put’

  • american – True for American options, False for European

Returns:

price, delta, gamma, theta

Return type:

dict