Skip to main content

Option stategy visualizer

Project description

opstrat

PyPI PyPI - License GitHub top language GitHub Repo stars Twitter Follow Youtube

Python library for visualizing options.

Requirements

pandas, numpy, matplotlib, seaborn, yfinance

Installation

Use the package manager pip to install opstrat.

pip install opstrat

Usage

Import opstrat

import opstrat

Version check

op.__version__

If you are using an older version upgrade to the latest package using:

pip install opstrat --upgrade

1. single_plotter()

Used for plotting payoff diagram involving multiple options.

Parameters

op_type: kind {'c','p'}, default:'c'
  Opion type>> 'c': call option, 'p':put option

spot: int, float, default: 100
 Spot Price

spot_range: int, float, optional, default: 5
 Range of spot variation in percentage

strike: int, float, default: 102
 Strike Price

tr_type: kind {'b', 's'} default:'b'
 Transaction Type>> 'b': long, 's': short

op_pr: int, float, default: 10
 Option Price

1.a Default plot

Option type : Call
Spot Price : 100
Spot range : +/- 5%
Strike price: 102
Position : Long
Option Premium: 10

op.single_plotter()

png

Green : Profit
Red : Loss

1.b Input parameters

Strike Price : 450
Spot price : 460
Option type : Put Option
Position : Short
Option Premium : 12.5

op.single_plotter(spot=460, strike=460, op_type='p', tr_type='s', op_pr=12.5)

png

2. multi_plotter()

Used for plotting a single option
Parameters

spot: int, float, default: 100
  Spot Price

spot_range: int, float, optional, default: 20
  Range of spot variation in percentage

op_list: list of dictionary

 Each dictionary must contiain following keys:
  'strike': int, float, default: 720
  Strike Price
  'tr_type': kind {'b', 's'} default:'b'
  Transaction Type>> 'b': long, 's': short
  'op_pr': int, float, default: 10
  Option Price
  'op_type': kind {'c','p'}, default:'c'
  Opion type>> 'c': call option, 'p':put option

2.a Default plot : The short strangle

Options trading that involve:
 (a)selling of a slightly out-of-the-money put and
 (b)a slightly out-of-the-money call of the same underlying stock and expiration date.
spot_range=+/-20%
spot=100

Option 1:Short call at strike price 110
 op_type: 'c','strike': 110 'tr_type': 's', 'op_pr': 2
Option 2 : Short put at strike price 95
 'op_type': 'p', 'strike': 95, 'tr_type': 's', 'op_pr': 6

op.multi_plotter()

png

2.b Example: Iron Condor (Option strategy with 4 options)

An iron condor is an options strategy consisting of two puts (one long and one short) and two calls (one long and one short), and four strike prices, all with the same expiration date.

stock currently trading at 212.26 (Spot Price)

Option 1: Sell a call with a 215 strike, which gives 7.63 in premium
Option 2: Buy a call with a strike of 220, which costs 5.35.
Option 3: Sell a put with a strike of 210 with premium received 7.20
Option 4: Buy a put with a strike of 205 costing 5.52.

op1={'op_type': 'c', 'strike': 215, 'tr_type': 's', 'op_pr': 7.63}
op2={'op_type': 'c', 'strike': 220, 'tr_type': 'b', 'op_pr': 5.35}
op3={'op_type': 'p', 'strike': 210, 'tr_type': 's', 'op_pr': 7.20}
op4={'op_type': 'p', 'strike': 205, 'tr_type': 'b', 'op_pr': 5.52}

op_list=[op1, op2, op3, op4]
op.multi_plotter(spot=212.26,spot_range=10, op_list=op_list)

png

3. yf_plotter()

Parameters

ticker: string, default: 'msft' stock ticker for Microsoft.Inc
  Stock Ticker
exp: string default: next option expiration date
  Option expiration date in 'YYYY-MM-DD' format

spot_range: int, float, optional, default: 10
  Range of spot variation in percentage

op_list: list of dictionary

  Each dictionary must contiain following keys
  'strike': int, float, default: 720
   Strike Price
  'tr_type': kind {'b', 's'} default:'b'
   Transaction Type>> 'b': long, 's': short
  'op_type': kind {'c','p'}, default:'c'
   Opion type>> 'c': call option, 'p':put option

3.a Default plot

Strangle on Microsoft stock
Stock ticker : msft(Microsoft Inc.)
  Option 1: Buy Call at Strike Price 250
  Option 2: Buy Put option at Strike price 225

op.yf_plotter()

png

3.b Example: Strangle on Amazon

Strangle:
A simultaneous purchase of options to buy and to sell a security or commodity at a fixed price, allowing the purchaser to make a profit whether the price of the security or commodity goes up or down.

Stock ticker : AMZN(Amazon Inc.)
  Option 1: Buy Call at Strike Price 3070
  Option 2: Buy Put option at Strike price 3070

op_1={'op_type': 'c', 'strike':3070, 'tr_type': 'b'}
op_2={'op_type': 'p', 'strike':3070, 'tr_type': 'b'}
op.yf_plotter(ticker='amzn', 
              exp='default', 
              op_list=[op_1, op_2])

png

4. Save figure

Figure can be saved in the current directory setting save=True
Filename with extension has to be provided as file.
If no filename is provided, the figure will be saved as fig in png format.

op.single_plotter(save=True,file='simple_option.jpeg')

png

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Content License

MIT

Thanks to

Stackoverflow Community
Ran Aroussi : yfinance
Daniel Goldfarb : mplfinance

Tutorial in Video Format

Watch the video

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

opstrat-0.1.7.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

opstrat-0.1.7-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file opstrat-0.1.7.tar.gz.

File metadata

  • Download URL: opstrat-0.1.7.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.5.0.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.4

File hashes

Hashes for opstrat-0.1.7.tar.gz
Algorithm Hash digest
SHA256 e3a4da1aab4a8ab9af53791d85bebd1aa2369674382b0df2283c6a27a988bf88
MD5 25729444568976d0558f46c48d9174e6
BLAKE2b-256 2d409bde4fc68a5f45f0763bbc11fd4ba49cb56c0c8e9cdaa2d386bca17cb397

See more details on using hashes here.

File details

Details for the file opstrat-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: opstrat-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.5.0.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.4

File hashes

Hashes for opstrat-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 12f690accac79c01e7d74f85d09eea53339f87f15e132d85c9a316ab30d9b342
MD5 7836d8633a09bcb613de867fb6aa7336
BLAKE2b-256 738a8ee19d840716deaae0b64d17f3f661b05e062c08bd33328f27932ec41c93

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page