Modeling a butterfly spread using Python

A butterfly spread involves buying a call option with strike price K1 and buying of another call option with strike price K2 and selling of two call options with strike price K3 in such a ways that k1<k2<k3. The Python examples models the butterfly spread for a stock and computes the payoffs for upward price momentum and downward price momentum.

Options Updated 22 Mar 2019 2 min read

Overview

  • When the investors assume that market volatility is going to be very little they employ butterfly spread strategy.

  • In a butterfly spread, when the stock price wanders around K2, the midpoint - it gives profit.

  • However, at the date of expiry if the stock price is less than K1 or greater than K3, the whole position will expire worthless.

  • Construction of a butterfly spread involves,

  1. Buying of a European call option at price K1
  2. Buying of a European call option at price K3
  3. Selling of two European call options at a price, which is a midpoint between K1 and K3.

Example

python
# Python example code that models the option strategy - butterfly spread

K1 = 100

K2 = 200

K3 = 300

stockPrice = 200

i = 0

while i < 10:

    stockPrice  = stockPrice + 25

    payoff      = 0

    if (stockPrice > K1 and stockPrice <= K2):

        payoff      = stockPrice - K1;

    elif (stockPrice > K2 and stockPrice < K3):

        payoff      = K3 - stockPrice;

    elif (stockPrice <= K1):

        payoff  = 0;

    elif (stockPrice >= K3):

        payoff  = 0;

    else:

        payoff  = 0;

    print("Stock price:%2.2f"%stockPrice);

    print("Payoff from butterfly spread:%2.2f"%payoff);

    print("-")

    i = i + 1;

stockPrice = 200

while i >= 0 :

    stockPrice  = stockPrice - 25

    payoff      = 0

    if (stockPrice > K1 and stockPrice <= K2):

        payoff      = stockPrice - K1;

    elif (stockPrice > K2 and stockPrice < K3):

        payoff      = K3 - stockPrice;

    elif (stockPrice <= K1):

        payoff  = 0;

    elif (stockPrice >= K3):

        payoff  = 0;

    else:

        payoff  = 0;

    print("Stock price:%2.2f"%stockPrice);

    print("Payoff from butterfly spread:%2.2f"%payoff);

    print("-")

    i = i - 1;

Output

Output
Stock price:225.00

Payoff from butterfly spread:75.00

-

Stock price:250.00

Payoff from butterfly spread:50.00

-

Stock price:275.00

Payoff from butterfly spread:25.00

-

Stock price:300.00

Payoff from butterfly spread:0.00

-

Stock price:325.00

Payoff from butterfly spread:0.00

-

Stock price:350.00

Payoff from butterfly spread:0.00

-

Stock price:375.00

Payoff from butterfly spread:0.00

-

Stock price:400.00

Payoff from butterfly spread:0.00

-

Stock price:425.00

Payoff from butterfly spread:0.00

-

Stock price:450.00

Payoff from butterfly spread:0.00

-

Stock price:175.00

Payoff from butterfly spread:75.00

-

Stock price:150.00

Payoff from butterfly spread:50.00

-

Stock price:125.00

Payoff from butterfly spread:25.00

-

Stock price:100.00

Payoff from butterfly spread:0.00

-

Stock price:75.00

Payoff from butterfly spread:0.00

-

Stock price:50.00

Payoff from butterfly spread:0.00

-

Stock price:25.00

Payoff from butterfly spread:0.00

-

Stock price:0.00

Payoff from butterfly spread:0.00

-

Stock price:-25.00

Payoff from butterfly spread:0.00

-

Stock price:-50.00

Payoff from butterfly spread:0.00

-

Stock price:-75.00

Payoff from butterfly spread:0.00

-