Visualizing Option Trading Strategies in Python - by Abhijith Chandradas - DataDrivenInvestor
Visualizing Option Trading Strategies in Python - by Abhijith Chandradas - DataDrivenInvestor
Published in DataDrivenInvestor
Save
Introduction
An option is a derivative, a contract that gives the buyer the right, but not the
obligation, to buy or sell the underlying asset by a certain date (expiration date) at a
specified price (strike price).
There are two types of options: calls and puts. Traders can construct option
strategies ranging from buying or selling a single option to very complex ones that
involve multiple simultaneous option positions.
Option payoff diagrams are profit and loss charts that show the risk/reward profile
of an option or combination of options. As option probability can be complex to
understand, payoff diagrams gives an insight into the risk/reward for the trading
strategy.
Opstrat Package
Opstrat is a python package which can be used for visualizing options, without the
need of complex coding. The package provides functions for constructing payoff
https://medium.datadriveninvestor.com/visualizing-option-trading-strategies-in-python-35bfa61151d9 1/11
1/4/23, 11:47 PM Visualizing Option Trading Strategies in Python | by Abhijith Chandradas | DataDrivenInvestor
Installing the package also installs the dependencies- pandas, matplotlib, seaborn
and yfinance packages.
Time to Code
Once the package is installed successfully, it can be imported as below:
import opstrat as op
Default plot:
op.single_plotter()
https://medium.datadriveninvestor.com/visualizing-option-trading-strategies-in-python-35bfa61151d9 2/11
1/4/23, 11:47 PM Visualizing Option Trading Strategies in Python | by Abhijith Chandradas | DataDrivenInvestor
Image by Author
If no arguments are provided, payoff diagram for a long call option will be
generated with strike price as $102 and spot price $100.
Note that the trader’s profit is shown in green shade and loss is shown in red. The
call option buyer’s loss is limited to $2 regardless of how low the share price falls.
The trader’s profit increases if the stock price increase beyond $104(break-even
price)
https://medium.datadriveninvestor.com/visualizing-option-trading-strategies-in-python-35bfa61151d9 3/11
1/4/23, 11:47 PM Visualizing Option Trading Strategies in Python | by Abhijith Chandradas | DataDrivenInvestor
Image by author
op_1 = {'op_type':'c','strike':110,'tr_type':'s','op_pr':2}
op_2 = {'op_type':'p','strike':95,'tr_type':'s','op_pr':6}
op.multi_plotter(spot=100, op_list=[op_1,op_2])
https://medium.datadriveninvestor.com/visualizing-option-trading-strategies-in-python-35bfa61151d9 4/11
1/4/23, 11:47 PM Visualizing Option Trading Strategies in Python | by Abhijith Chandradas | DataDrivenInvestor
Image by Author
https://medium.datadriveninvestor.com/visualizing-option-trading-strategies-in-python-35bfa61151d9 5/11
1/4/23, 11:47 PM Visualizing Option Trading Strategies in Python | by Abhijith Chandradas | DataDrivenInvestor
Image by Author
The optional argument, spot range limits the range of spot values covered in the
plot. The default spot range in +/-20%. If the underlying asset is less volatile and the
strike price of options are within a small range, smaller spot range like 5% can be
considered. For highly volatile underlying asset, higher spot range can be used.
https://medium.datadriveninvestor.com/visualizing-option-trading-strategies-in-python-35bfa61151d9 6/11
1/4/23, 11:47 PM Visualizing Option Trading Strategies in Python | by Abhijith Chandradas | DataDrivenInvestor
Image by Author
Image by Author
If you prefer the tutorial in video format, you can check out the below video:
946 8
https://medium.datadriveninvestor.com/visualizing-option-trading-strategies-in-python-35bfa61151d9 8/11
1/4/23, 11:47 PM Visualizing Option Trading Strategies in Python | by Abhijith Chandradas | DataDrivenInvestor
Become a Member
I hope you like the article, I would highly recommend signing up for Medium
Membership to read more articles by me or stories by thousands of other authors on
variety of topics.
Your membership fee directly supports me and other writers you read. You’ll also
get full access to every story on Medium.
Here are a few related articles which you may find interesting
https://medium.datadriveninvestor.com/visualizing-option-trading-strategies-in-python-35bfa61151d9 9/11
1/4/23, 11:47 PM Visualizing Option Trading Strategies in Python | by Abhijith Chandradas | DataDrivenInvestor
Subscribe
https://medium.datadriveninvestor.com/visualizing-option-trading-strategies-in-python-35bfa61151d9 10/11
1/4/23, 11:47 PM Visualizing Option Trading Strategies in Python | by Abhijith Chandradas | DataDrivenInvestor
https://medium.datadriveninvestor.com/visualizing-option-trading-strategies-in-python-35bfa61151d9 11/11