From 1ec92c374a66f123f30e4a5de8183368aa6a27f5 Mon Sep 17 00:00:00 2001 From: sgttux <116453812+sgttux@users.noreply.github.com> Date: Wed, 6 Sep 2023 19:06:28 -0600 Subject: [PATCH] Fixed Issues with Stock Corrected some references to stock. Updated the payoff function for stocks. Corrected the payoff function to use contract equivalent amount for stocks to align with calls and puts. --- opstrat/basic_multi.py | 7 +++---- opstrat/helpers.py | 8 ++++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/opstrat/basic_multi.py b/opstrat/basic_multi.py index 59a1f6c..dbabcb0 100644 --- a/opstrat/basic_multi.py +++ b/opstrat/basic_multi.py @@ -140,12 +140,12 @@ def multi_plotter(spot_range, spot, op_list, # Calculate Payoff Prices for each x Underlying Price Value with Days to Expiration y_list.append(payoff_calculator(x, row['op_type'], row['strike'], row['op_pr'], row['tr_type'] - , row['contracts'], row['days_to_expiration'], r, v )) + , row['contract_equiv'], row['days_to_expiration'], r, v )) # Calculate Payoff Prices with Adjusted Days to Expiration if exp_adjust > 0: y_exp_list.append(payoff_calculator(x, row['op_type'], row['strike'], row['op_pr'], row['tr_type'] - , row['contracts'], row['days_to_expiration_adjusted'], r, v )) + , row['contract_equiv'], row['days_to_expiration_adjusted'], r, v )) def plotter(): @@ -228,5 +228,4 @@ def plotter(): print('You have selected to not show individual option legs, combined transaction legs, or combined graph. No graph will be generated.') return else: - plotter() - + plotter() \ No newline at end of file diff --git a/opstrat/helpers.py b/opstrat/helpers.py index 3d6ef0f..203e6d8 100644 --- a/opstrat/helpers.py +++ b/opstrat/helpers.py @@ -4,8 +4,8 @@ from .blackscholes import black_scholes def check_optype(op_type): - if (op_type not in ['p','c','s']): - raise ValueError("Input 'p' for put, 'c' for call, 's' for stock!") + if (op_type not in ['p','c','st']): + raise ValueError("Input 'p' for put, 'c' for call, 'st' for stock!") def check_trtype(tr_type): if (tr_type not in ['b','s']): @@ -30,9 +30,9 @@ def payoff_calculator(x, op_type, strike, op_pr, tr_type, n, days_to_expiration, y=[] # If Leg is a Stock - calculate payoff graph for a stock position - if op_type=='s': + if op_type=='st': for i in range(len(x)): - y.append(x[i]-strike-op_pr) + y.append(x[i]-strike) # If Leg is an Option and Future Expiration, - calculate value of option using Black Scholes Pricing Model elif days_to_expiration > 0: