Package: opstrat
opstratPython library for visualizing options.Requirementspandas, numpy, matplotlib, seaborn, yfinanceInstallationUse the package managerpipto install opstrat.pipinstallopstratUsageImport opstratimportopstratVersion checkop.__version__If you are using an older version upgrade to the latest package using:pipinstallopstrat--upgrade1. single_plotter()Used for plotting payoff diagram involving multiple options.Parametersop_type: kind {'c','p'}, default:'c'Opion type>> 'c': call option, 'p':put optionspot: int, float, default: 100Spot Pricespot_range: int, float, optional, default: 5Range of spot variation in percentagestrike: int, float, default: 102Strike Pricetr_type: kind {'b', 's'} default:'b'Transaction Type>> 'b': long, 's': shortop_pr: int, float, default: 10Option Price1.a Default plotOption type : CallSpot Price : 100Spot range : +/- 5%Strike price: 102Position : LongOption Premium: 10op.single_plotter()Green : ProfitRed : Loss1.b Input parametersStrike Price : 450Spot price : 460Option type : Put OptionPosition : ShortOption Premium : 12.5op.single_plotter(spot=460,strike=460,op_type='p',tr_type='s',op_pr=12.5)2. multi_plotter()Used for plotting a single optionParametersspot: int, float, default: 100Spot Pricespot_range: int, float, optional, default: 20Range of spot variation in percentageop_list: list of dictionaryEach dictionary must contiain following keys:'strike': int, float, default: 720Strike Price'tr_type': kind {'b', 's'} default:'b'Transaction Type>> 'b': long, 's': short'op_pr': int, float, default: 10Option Price'op_type': kind {'c','p'}, default:'c'Opion type>> 'c': call option, 'p':put option2.a Default plot : The short strangleOptions 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=100Option 1:Short call at strike price 110op_type: 'c','strike': 110 'tr_type': 's', 'op_pr': 2Option 2 : Short put at strike price 95'op_type': 'p', 'strike': 95, 'tr_type': 's', 'op_pr': 6op.multi_plotter()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 premiumOption 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.20Option 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)3. yf_plotter()Parametersticker: string, default: 'msft' stock ticker for Microsoft.IncStock Tickerexp: string default: next option expiration dateOption expiration date in 'YYYY-MM-DD' formatspot_range: int, float, optional, default: 10Range of spot variation in percentageop_list: list of dictionaryEach dictionary must contiain following keys'strike': int, float, default: 720Strike 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 option3.a Default plotStrangle on Microsoft stockStock ticker : msft(Microsoft Inc.)Option 1: Buy Call at Strike Price 250Option 2: Buy Put option at Strike price 225op.yf_plotter()3.b Example: Strangle on AmazonStrangle: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 3070Option 2: Buy Put option at Strike price 3070op_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])4. Save figureFigure can be saved in the current directory settingsave=TrueFilename with extension has to be provided asfile.If no filename is provided, the figure will be saved as fig in png format.op.single_plotter(save=True,file='simple_option.jpeg')ContributingPull 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 LicenseMITThanks toStackoverflow CommunityRan Aroussi:yfinanceDaniel Goldfarb:mplfinanceTutorial in Video Format