I am continuing on with a bigger project and for this part I am trying to use wallstreet to pull the implied volatility of a certain call or put for options trading. I am able to get it to work individually for calls and puts, but not when I combine them to make it one action.
input variables like aapl 180 call 5 days till expiration -> use an if elif statement for the functions for calls and puts to get the respective IV -> return that IV as a variable for further math in a different section
here is an example of the latest that I have. Any help is appreciated I am newer to coding so if this is obvious apologies.
And for reference my problem is that when I run the call and put functions separately they give two different numbers, but like this regardless of a P or C input, i get the value for calls.
Thanks.
from wallstreet import Call, Put
import datetime
from datetime import date
ticker = "tsla"
K = 900
today = date.today()
expiry = today + datetime.timedelta(days=5)
y = expiry.year
d = expiry.day
m = expiry.month
CorP = "P"
if CorP == "c" or "C":
call = Call(ticker, d=d, m=m, y=y, strike=K)
sigma = call.implied_volatility()
elif CorP == "p" or "P":
put = Put(ticker, d=d, m=m, y=y, strike=K)
sigma = put.implied_volatility()
print(sigma)