core.test_payoff
Tests for hedge payoff calculation functions.
Tests the pure functions in f.domains.hedge.core.payoff:
- calculate_put_payoff_at_spot
- calculate_total_hedge_payoff_at_spot
Each function has 3 tests covering different scenarios.
EXCEL VERIFICATION GUIDE
For a mathematician to verify these tests in Excel:
Single Put Payoff:
- Formula:
=MAX(Strike - Spot, 0) * Quantity
- Formula:
Total Portfolio Payoff:
- List positions in a table (Strike, Quantity).
- Calculate individual payoffs using the formula above.
- Sum the results:
=SUM(PayoffColumn).
Create sample hedge positions for testing.
Test: ITM put option payoff.
NUMERICAL EXAMPLE
Input: strike = 2500 quantity = 10 spot_price = 2200
Calculation: intrinsic = max(2500 - 2200, 0) = 300 payoff = 300 × 10 = 3000
Expected: payoff = 3000
EXCEL REPRODUCTION
1. Inputs (Cells A1:B3)
| Cell | Parameter | Value |
|---|---|---|
| B1 | Strike | 2500 |
| B2 | Spot | 2200 |
| B3 | Quantity | 10 |
2. Calculation (Cells A4:B4)
| Cell | Name | Formula | Expectation |
|---|---|---|---|
| B4 | Payoff | =MAX(B1-B2, 0) * B3 |
3000 |
Test: OTM put option payoff (should be zero).
NUMERICAL EXAMPLE
Input: strike = 2500 quantity = 10 spot_price = 3000
Calculation: intrinsic = max(2500 - 3000, 0) = max(-500, 0) = 0 payoff = 0 × 10 = 0
Expected: payoff = 0
Test: ATM put option payoff (exactly at strike, should be zero).
NUMERICAL EXAMPLE
Input: strike = 2500 quantity = 10 spot_price = 2500
Calculation: intrinsic = max(2500 - 2500, 0) = 0 payoff = 0 × 10 = 0
Expected: payoff = 0
Test: Total payoff from multiple positions.
NUMERICAL EXAMPLE
Input: Positions: [Put 2200 × 10, Put 2600 × 5] spot_price = 2000
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
Expected: total_payoff = 5000
EXCEL REPRODUCTION
1. Global Inputs (Cell B1)
| Cell | Parameter | Value |
|---|---|---|
| B1 | SpotPrice | 2000 |
2. Positions Table (Columns A, B, C)
| Row | Strike (A) | Quantity (B) | Payoff (C) |
|---|---|---|---|
| 3 | 2200 | 10 | =MAX(A3-B$1, 0) * B3 |
| 4 | 2600 | 5 | =MAX(A4-B$1, 0) * B4 |
3. Total (Cell C5)
| Cell | Name | Formula | Expectation |
|---|---|---|---|
| C5 | Total | =SUM(C3:C4)| 5000 |
Test: Total payoff from single position.
NUMERICAL EXAMPLE
Input: Positions: [Put 2500 × 8] spot_price = 2300
Calculation: Put 2500: max(2500 - 2300, 0) × 8 = 200 × 8 = 1600 Total = 1600
Expected: total_payoff = 1600
Test: Total payoff from empty position list.
NUMERICAL EXAMPLE
Input: Positions: [] spot_price = 2000
Expected: total_payoff = 0