#172easyOptions & Derivatives
Option Strategy Payoff
Time Limit: 2sMemory: 256MB
Problem
Given a multi-leg option strategy, compute the total profit at expiry for a given stock price.
Each leg specifies:
- Type:
callorput - Direction:
long(bought) orshort(sold) - Strike price
- Premium paid or received
Input Format
Line 1: n (number of legs)
Next n lines: type direction strike premium
Last line: S_expiry (stock price at expiry)
Output Format
Total profit rounded to 2 decimal places.
Payoff Logic
- Long call profit:
- Short call profit:
- Long put profit:
- Short put profit:
Examples
Example 1
Input(Line 1: n (number of legs))
1 call long 100.0 5.0 110.0
Output
5.00
Long call struck at 100, premium 5. At S=110, intrinsic=10, profit=10-5=5.
Example 2
Input(Line 1: n (number of legs))
2 call long 100.0 5.0 call short 110.0 2.0 115.0
Output
7.00
Bull call spread. Long 100-call pays 15-5=10, short 110-call costs 5-2=-3, total=7.
Constraints
- •1 <= number of legs <= 20
- •type is 'call' or 'put'
- •direction is 'long' or 'short'
- •0.0 <= strike <= 100000.0
- •0.0 <= premium <= 100000.0
- •0.0 <= S_expiry <= 100000.0
- •Output total profit to 2 decimal places
Loading interactive editor…