Skip to content

Instantly share code, notes, and snippets.

@ti-ka
Created June 17, 2022 18:01
Show Gist options
  • Save ti-ka/9260182bf35ac167bb9a55fac5648d07 to your computer and use it in GitHub Desktop.
Save ti-ka/9260182bf35ac167bb9a55fac5648d07 to your computer and use it in GitHub Desktop.
Python fuction to plot the y value of option at expiration
def option_fx(x, longShort: str, callPut: str, strike, cost):
s = strike
u = cost
if longShort == 'L':
if callPut == 'C':
return (0 if x < s else x - s) - u # Long call
else:
return (0 if x > s else s - x) - u # Long Put
else:
if callPut == 'C':
return (0 if x < s else s - x) + u # Short call
else:
return (0 if x > s else x - s) + u # Short Put
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment