core.payoff
Payoff Calculation Functions
This module provides pure functions for calculating put option payoffs at specific spot prices. These are used for analyzing hedge portfolio performance at various price scenarios.
All functions are pure (no side effects) and use Decimal for precision.
Functions
calculate_put_payoff_at_spot: Single put payoff at spot pricecalculate_total_hedge_payoff_at_spot: Total portfolio payoff at spot price
Example Usage
>>> from decimal import Decimal
>>> from f.domains.hedge.core.payoff import calculate_put_payoff_at_spot
>>>
>>> # ITM put: strike 2500, spot 2200
>>> payoff = calculate_put_payoff_at_spot(
... strike=Decimal("2500"),
... quantity=Decimal("10"),
... spot_price=Decimal("2200"),
... )
>>> payoff
Decimal('3000') # (2500 - 2200) * 10 = 3000
Calculate put option payoff at a specific spot price.
This is a pure function that computes the payoff at expiry for a put option given the strike price, quantity, and current spot price.
Mathematical Definition
$$\text{Payoff} = \max(K - S, 0) \times Q$$
Where:
- K: Strike price
- S: Spot price at expiry
- Q: Quantity of contracts
Parameters
strike : Decimal Option strike price K.
quantity : Decimal Number of contracts (positive = long, negative = short).
spot_price : Decimal Current spot price S.
Returns
Decimal Total payoff in USD. - Positive if ITM (spot < strike) - Zero if OTM (spot >= strike)
Example
>>> # ITM put: strike 2500, spot 2200, qty 10
>>> calculate_put_payoff_at_spot(
... Decimal("2500"), Decimal("10"), Decimal("2200")
... )
Decimal('3000') # (2500 - 2200) * 10
>>> # OTM put: strike 2500, spot 3000, qty 10
>>> calculate_put_payoff_at_spot(
... Decimal("2500"), Decimal("10"), Decimal("3000")
... )
Decimal('0') # max(2500 - 3000, 0) * 10 = 0
>>> # ATM put: strike 2500, spot 2500, qty 10
>>> calculate_put_payoff_at_spot(
... Decimal("2500"), Decimal("10"), Decimal("2500")
... )
Decimal('0') # max(2500 - 2500, 0) * 10 = 0
NUMERICAL EXAMPLE
Input: K = 2500 (strike) S = 2200 (spot) Q = 10 (quantity)
Calculation: intrinsic = max(2500 - 2200, 0) = 300 payoff = 300 × 10 = 3000
Notes
- This function computes payoff at expiry (intrinsic value only)
- For time-value adjusted payoffs, use Black-Scholes pricing
- Quantity can be negative for short positions
Calculate total hedge portfolio payoff at a specific spot price.
This is a pure function that sums the payoffs of all put positions in the hedge portfolio at a given spot price.
Mathematical Definition
$$\text{Total Payoff} = \sum_{i} \max(K_i - S, 0) \times Q_i$$
Where:
- K_i: Strike price of position i
- S: Spot price at expiry
- Q_i: Quantity of position i
Parameters
positions : List[HedgePosition] List of hedge positions (put options).
spot_price : Decimal Current spot price S.
Returns
Decimal Total payoff from all positions in USD.
Example
>>> from f.domains.hedge.core.models import HedgePosition, Direction
>>> positions = [
... HedgePosition(
... direction=Direction.BUY,
... instrument="Put 2200",
... amount=Decimal("10"),
... strike=Decimal("2200"),
... price=Decimal("0.03"),
... premium=Decimal("915"),
... ),
... HedgePosition(
... direction=Direction.BUY,
... instrument="Put 2600",
... amount=Decimal("5"),
... strike=Decimal("2600"),
... price=Decimal("0.06"),
... premium=Decimal("915"),
... ),
... ]
>>> calculate_total_hedge_payoff_at_spot(positions, Decimal("2000"))
Decimal('5000') # (2200-2000)*10 + (2600-2000)*5 = 2000 + 3000
>>> calculate_total_hedge_payoff_at_spot(positions, Decimal("2400"))
Decimal('1000') # (2200-2400)*10=0 + (2600-2400)*5 = 0 + 1000
>>> calculate_total_hedge_payoff_at_spot(positions, Decimal("3000"))
Decimal('0') # Both OTM
>>> # Empty portfolio
>>> calculate_total_hedge_payoff_at_spot([], Decimal("2500"))
Decimal('0')
NUMERICAL EXAMPLE
Input: Positions: [Put 2200 × 10, Put 2600 × 5] S = 2000 (spot)
Calculation: Put 2200: max(2200 - 2000, 0) × 10 = 200 × 10 = 2000 Put 2600: max(2600 - 2000, 0) × 5 = 600 × 5 = 3000 Total = 2000 + 3000 = 5000
Notes
- Only considers payoff at expiry (no time value)
- Empty portfolio returns zero
- All positions are assumed to be puts