Analysis API

Options Trading Strategies Module

Implements common options strategies with profit/loss calculations, risk analysis, and breakeven points.

Supported Strategies: - Single-leg: Covered Call, Protective Put, Cash-Secured Put - Vertical Spreads: Bull Call/Put, Bear Call/Put - Horizontal: Calendar Spread - Advanced: Iron Condor, Butterfly, Straddle, Strangle

class quantlab.analysis.options_strategies.OptionType(value)[source]

Bases: Enum

Option type

CALL = 'call'
PUT = 'put'
class quantlab.analysis.options_strategies.PositionType(value)[source]

Bases: Enum

Position type (long or short)

LONG = 'long'
SHORT = 'short'
class quantlab.analysis.options_strategies.StrategyType(value)[source]

Bases: Enum

Options strategy types

COVERED_CALL = 'covered_call'
PROTECTIVE_PUT = 'protective_put'
CASH_SECURED_PUT = 'cash_secured_put'
LONG_CALL = 'long_call'
LONG_PUT = 'long_put'
BULL_CALL_SPREAD = 'bull_call_spread'
BULL_PUT_SPREAD = 'bull_put_spread'
BEAR_CALL_SPREAD = 'bear_call_spread'
BEAR_PUT_SPREAD = 'bear_put_spread'
CALENDAR_SPREAD = 'calendar_spread'
IRON_CONDOR = 'iron_condor'
BUTTERFLY = 'butterfly'
STRADDLE = 'straddle'
STRANGLE = 'strangle'
class quantlab.analysis.options_strategies.OptionLeg(option_type, position_type, strike, premium, quantity=1, expiration=None, implied_volatility=None, risk_free_rate=0.05)[source]

Bases: object

Single option leg in a strategy

option_type: OptionType
position_type: PositionType
strike: float
premium: float
quantity: int = 1
expiration: Optional[date] = None
implied_volatility: Optional[float] = None
risk_free_rate: float = 0.05
pnl_at_price(stock_price)[source]

Calculate P&L for this leg at a given stock price

Return type:

float

calculate_advanced_greeks(stock_price)[source]

Calculate advanced Greeks using existing calculator

Requires implied_volatility and expiration to be set. Returns dictionary with delta, gamma, vega, theta, vanna, charm, vomma.

Return type:

Dict[str, float]

__init__(option_type, position_type, strike, premium, quantity=1, expiration=None, implied_volatility=None, risk_free_rate=0.05)
class quantlab.analysis.options_strategies.OptionsStrategy(name, strategy_type, legs, current_stock_price, stock_position=0, target_date=None, metadata=<factory>)[source]

Bases: object

Complete options strategy with multiple legs

name

Strategy name

strategy_type

Type of strategy

legs

List of option legs

stock_position

Shares of underlying stock (positive=long, negative=short)

current_stock_price

Current price of underlying

target_date

Target date for P&L calculation (default: expiration)

name: str
strategy_type: StrategyType
legs: List[OptionLeg]
current_stock_price: float
stock_position: int = 0
target_date: Optional[date] = None
metadata: Dict
net_premium()[source]

Calculate net premium (positive = credit, negative = debit)

Return type:

float

max_profit()[source]

Calculate maximum profit potential

Return type:

float

max_loss()[source]

Calculate maximum loss potential

Return type:

float

breakeven_points()[source]

Calculate breakeven stock prices

Return type:

List[float]

pnl_at_price(stock_price)[source]

Calculate total P&L at a given stock price

Return type:

float

payoff_diagram(price_range=None, num_points=100)[source]

Generate data for payoff diagram

Returns:

Arrays for plotting

Return type:

(prices, pnls)

risk_metrics()[source]

Calculate risk metrics for the strategy

Return type:

Dict

advanced_greeks()[source]

Calculate aggregate advanced Greeks for entire strategy

Returns dictionary with all Greeks summed across legs: - delta, gamma, theta, vega (first-order) - vanna, charm, vomma (second-order/advanced)

Return type:

Dict[str, float]

to_dict()[source]

Convert strategy to dictionary for serialization

Return type:

Dict

__init__(name, strategy_type, legs, current_stock_price, stock_position=0, target_date=None, metadata=<factory>)
class quantlab.analysis.options_strategies.StrategyBuilder[source]

Bases: object

Builder for common options strategies

static covered_call(stock_price, shares, call_strike, call_premium, expiration, ticker='UNKNOWN', implied_volatility=None, risk_free_rate=0.05)[source]

Covered Call: Own stock + Sell call

Strategy: Generate income on existing stock position Max Profit: (Strike - Stock Price) + Premium Max Loss: Stock price - Premium Breakeven: Stock Price - Premium

Parameters:
  • implied_volatility (Optional[float]) – IV as decimal (e.g., 0.35 for 35%) - optional for Greeks

  • risk_free_rate (float) – Risk-free rate as decimal (default: 0.05)

Return type:

OptionsStrategy

static protective_put(stock_price, shares, put_strike, put_premium, expiration, ticker='UNKNOWN', implied_volatility=None, risk_free_rate=0.05)[source]

Protective Put: Own stock + Buy put

Strategy: Protect downside on stock position Max Profit: Unlimited (stock can rise infinitely) Max Loss: (Stock Price - Strike) + Premium Breakeven: Stock Price + Premium

Parameters:
  • implied_volatility (Optional[float]) – IV as decimal (e.g., 0.25 for 25%) - optional for Greeks

  • risk_free_rate (float) – Risk-free rate as decimal (default: 0.05)

Return type:

OptionsStrategy

static cash_secured_put(stock_price, put_strike, put_premium, quantity, expiration, ticker='UNKNOWN', implied_volatility=None, risk_free_rate=0.05)[source]

Cash-Secured Put: Sell put (with cash to buy stock if assigned)

Strategy: Generate income or acquire stock at lower price Max Profit: Premium received Max Loss: Strike - Premium (if stock goes to zero) Breakeven: Strike - Premium

Parameters:
  • implied_volatility (Optional[float]) – IV as decimal (e.g., 0.30 for 30%) - optional for Greeks

  • risk_free_rate (float) – Risk-free rate as decimal (default: 0.05)

Return type:

OptionsStrategy

static bull_call_spread(stock_price, long_strike, short_strike, long_premium, short_premium, quantity, expiration, ticker='UNKNOWN', implied_volatility=None, risk_free_rate=0.05)[source]

Bull Call Spread: Buy lower strike call + Sell higher strike call

Strategy: Moderately bullish with limited risk Max Profit: (Short Strike - Long Strike) - Net Debit Max Loss: Net Debit Breakeven: Long Strike + Net Debit

Parameters:
  • implied_volatility (Optional[float]) – IV as decimal (e.g., 0.35 for 35%) - optional for Greeks

  • risk_free_rate (float) – Risk-free rate as decimal (default: 0.05)

Return type:

OptionsStrategy

static iron_condor(stock_price, put_long_strike, put_short_strike, call_short_strike, call_long_strike, put_long_premium, put_short_premium, call_short_premium, call_long_premium, quantity, expiration, ticker='UNKNOWN', implied_volatility=None, risk_free_rate=0.05)[source]

Iron Condor: Sell put spread + Sell call spread

Strategy: Profit from low volatility (stock stays in range) Max Profit: Net Credit Max Loss: Width of widest spread - Net Credit Breakevens: Two points (at put spread and call spread)

Parameters:
  • implied_volatility (Optional[float]) – IV as decimal (e.g., 0.20 for 20%) - optional for Greeks

  • risk_free_rate (float) – Risk-free rate as decimal (default: 0.05)

Return type:

OptionsStrategy

static long_call(stock_price, strike, premium, quantity, expiration, ticker='UNKNOWN', implied_volatility=None, risk_free_rate=0.05)[source]

Long Call: Buy call option

Strategy: Bullish - profit from stock rise with limited risk Max Profit: Unlimited (stock can rise infinitely) Max Loss: Premium paid Breakeven: Strike + Premium

Parameters:
  • implied_volatility (Optional[float]) – IV as decimal (e.g., 0.35 for 35%) - optional for Greeks

  • risk_free_rate (float) – Risk-free rate as decimal (default: 0.05)

Return type:

OptionsStrategy

static long_put(stock_price, strike, premium, quantity, expiration, ticker='UNKNOWN', implied_volatility=None, risk_free_rate=0.05)[source]

Long Put: Buy put option

Strategy: Bearish - profit from stock decline with limited risk Max Profit: Strike - Premium (if stock goes to zero) Max Loss: Premium paid Breakeven: Strike - Premium

Parameters:
  • implied_volatility (Optional[float]) – IV as decimal (e.g., 0.35 for 35%) - optional for Greeks

  • risk_free_rate (float) – Risk-free rate as decimal (default: 0.05)

Return type:

OptionsStrategy

static bull_put_spread(stock_price, long_strike, short_strike, long_premium, short_premium, quantity, expiration, ticker='UNKNOWN', implied_volatility=None, risk_free_rate=0.05)[source]

Bull Put Spread: Buy lower strike put + Sell higher strike put

Strategy: Moderately bullish with limited risk (credit spread) Max Profit: Net Credit Max Loss: (Short Strike - Long Strike) - Net Credit Breakeven: Short Strike - Net Credit

Parameters:
  • implied_volatility (Optional[float]) – IV as decimal (e.g., 0.25 for 25%) - optional for Greeks

  • risk_free_rate (float) – Risk-free rate as decimal (default: 0.05)

Return type:

OptionsStrategy

static bear_call_spread(stock_price, long_strike, short_strike, long_premium, short_premium, quantity, expiration, ticker='UNKNOWN', implied_volatility=None, risk_free_rate=0.05)[source]

Bear Call Spread: Sell lower strike call + Buy higher strike call

Strategy: Moderately bearish with limited risk (credit spread) Max Profit: Net Credit Max Loss: (Long Strike - Short Strike) - Net Credit Breakeven: Short Strike + Net Credit

Parameters:
  • implied_volatility (Optional[float]) – IV as decimal (e.g., 0.25 for 25%) - optional for Greeks

  • risk_free_rate (float) – Risk-free rate as decimal (default: 0.05)

Return type:

OptionsStrategy

static bear_put_spread(stock_price, long_strike, short_strike, long_premium, short_premium, quantity, expiration, ticker='UNKNOWN', implied_volatility=None, risk_free_rate=0.05)[source]

Bear Put Spread: Buy higher strike put + Sell lower strike put

Strategy: Moderately bearish with limited risk (debit spread) Max Profit: (Long Strike - Short Strike) - Net Debit Max Loss: Net Debit Breakeven: Long Strike - Net Debit

Parameters:
  • implied_volatility (Optional[float]) – IV as decimal (e.g., 0.30 for 30%) - optional for Greeks

  • risk_free_rate (float) – Risk-free rate as decimal (default: 0.05)

Return type:

OptionsStrategy

static butterfly(stock_price, lower_strike, middle_strike, upper_strike, lower_premium, middle_premium, upper_premium, quantity, expiration, option_type='call', ticker='UNKNOWN', implied_volatility=None, risk_free_rate=0.05)[source]

Butterfly Spread: Buy 1 low strike + Sell 2 middle strikes + Buy 1 high strike

Strategy: Profit from low volatility (stock stays near middle strike) Max Profit: (Middle Strike - Lower Strike) - Net Debit Max Loss: Net Debit Breakevens: Two points around middle strike

Parameters:
  • implied_volatility (Optional[float]) – IV as decimal (e.g., 0.25 for 25%) - optional for Greeks

  • risk_free_rate (float) – Risk-free rate as decimal (default: 0.05)

Return type:

OptionsStrategy

static straddle(stock_price, strike, call_premium, put_premium, quantity, expiration, position='long', ticker='UNKNOWN', implied_volatility=None, risk_free_rate=0.05)[source]

Straddle: Buy/Sell both call and put at same strike

Long Straddle: Profit from high volatility (big move in either direction) Short Straddle: Profit from low volatility (stock stays near strike)

Long Straddle:

Max Profit: Unlimited Max Loss: Total premium paid Breakevens: Strike ± Total Premium

Short Straddle:

Max Profit: Total premium received Max Loss: Unlimited Breakevens: Strike ± Total Premium

Parameters:
  • implied_volatility (Optional[float]) – IV as decimal (e.g., 0.30 for 30%) - optional for Greeks

  • risk_free_rate (float) – Risk-free rate as decimal (default: 0.05)

Return type:

OptionsStrategy

static strangle(stock_price, put_strike, call_strike, put_premium, call_premium, quantity, expiration, position='long', ticker='UNKNOWN', implied_volatility=None, risk_free_rate=0.05)[source]

Strangle: Buy/Sell call and put at different strikes

Long Strangle: Profit from high volatility (cheaper than straddle) Short Strangle: Profit from low volatility (higher risk than short straddle)

Long Strangle:

Max Profit: Unlimited Max Loss: Total premium paid Breakevens: Put Strike - Premium, Call Strike + Premium

Short Strangle:

Max Profit: Total premium received Max Loss: Unlimited Breakevens: Put Strike - Premium, Call Strike + Premium

Parameters:
  • implied_volatility (Optional[float]) – IV as decimal (e.g., 0.30 for 30%) - optional for Greeks

  • risk_free_rate (float) – Risk-free rate as decimal (default: 0.05)

Return type:

OptionsStrategy

static calendar_spread(stock_price, strike, near_premium, far_premium, near_expiration, far_expiration, quantity, option_type='call', ticker='UNKNOWN')[source]

Calendar Spread (Time Spread): Sell near-term + Buy far-term at same strike

Strategy: Profit from time decay difference and volatility Max Profit: Varies (depends on volatility changes) Max Loss: Net Debit Best Case: Stock stays near strike at near expiration

Return type:

OptionsStrategy