Modeling Of A Box Spread Using Python

Box Spread

  • Combination of a bull spread made of call options and a bear spread made of put options.
  • Creating a bull spread involves the following:
    • Buying a call option with a strike price of K1
    • Selling a call option with a strike price of K2
    • Buying a put option with a strike price of K2
    • Selling a put option with a strike price of K1
  • Box spread is a delta neutral strategy.
  • The payoff the box spread is always K2-K1.

 

Example: Modeling Box Spread 

# Python example code that models option strategy - Box Spread

K1 = 100

K2 = 150

 

#K3 = 100

#K4 = 150

 

stockPrice = 130

 

i = 0

 

while i < 5:

    stockPrice  = stockPrice + 10

    payoff      = 0

    if (stockPrice <= K1):

        payoff      = K2-K1;

    elif (stockPrice > K1 and stockPrice < K2):

        payoff      = K2 - K1;

    elif (stockPrice >= K2):

        payoff  = K2-K1;

    else:

        print("Invalid");       

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

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

    print("-")

    i = i + 1;   

 

stockPrice = 130

i = 0;   

while i <= 5:

    stockPrice  = stockPrice - 10

    payoff      = 0

    if (stockPrice <= K1):

        payoff      = K2-K1;

    elif (stockPrice > K1 and stockPrice < K2):

        payoff      = K2 - K1;

    elif (stockPrice >= K2):

        payoff  = K2-K1;

    else:

        print("Invalid");       

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

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

    print("-")

    i = i + 1;

 

 

Output:

Stock price:140.00

Payoff from the box spread:50.00

-

Stock price:150.00

Payoff from the box spread:50.00

-

Stock price:160.00

Payoff from the box spread:50.00

-

Stock price:170.00

Payoff from the box spread:50.00

-

Stock price:180.00

Payoff from the box spread:50.00

-

Stock price:120.00

Payoff from the box spread:50.00

-

Stock price:110.00

Payoff from the box spread:50.00

-

Stock price:100.00

Payoff from the box spread:50.00

-

Stock price:90.00

Payoff from the box spread:50.00

-

Stock price:80.00

Payoff from the box spread:50.00

-

Stock price:70.00

Payoff from the box spread:50.00

-

 

 


Copyright 2022 © pythontic.com