Course Name: Options Trading Strategies In Python: Basic, Section No: 1, Unit No: 11, Unit type: Exercise
Can you please help me with writing the put option payoff code
Hello,
The put option payoff is interesting to look at.
How Payoff Works for the Put Buyer:
- If the stock price falls below the strike price:
The put option buyer earns the difference between the strike price and the stock price.
Profit without premium = (Strike Price - Stock Price at Expiration)
- If the stock price stays the same or rises:
The put option becomes worthless, so the option put buyer will not exercise the option and hence, the payoff will be 0.
Payoff = 0
This is the same logic we are applying in the code, payoff_put = np.where(sT < strike_price, strike_price - sT, 0)
Let's look at the np.where statement.
np.where(condition, true_value, false_value)
works like an
if-else statement for arrays.
- If the condition is true, it assigns the
true_value
.
- If the condition is false, it assigns the
false_value
.
The condition is "
sT < strike_price"
You are checking if the stock price at expiration (sT) is less than the strike price.
If true: The option has value (because the buyer benefits when the stock price is below the strike).
If false: The option is worthless.
If the stock price is below the strike price, the payoff is the difference:
Payoff = Strike Price − Stock Price at Expiration (sT)
If sT = 420 and strike_price = 430, the payoff is 430−420=10.
If the stock price is not less than the strike price, the option is worthless, and the payoff is 0
Hope this helps.