mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 12:40:35 +00:00
Fix the greeks calculations of the chain command (#3812)
* Fix greeks * Improve readability Co-authored-by: James Maslek <jmaslek11@gmail.com>
This commit is contained in:
@@ -130,11 +130,12 @@ def get_option_chain_expiry(
|
||||
dt = (
|
||||
datetime.strptime(expiry, "%Y-%m-%d") + timedelta(hours=16) - datetime.now()
|
||||
).total_seconds() / (60 * 60 * 24)
|
||||
rf = get_rf()
|
||||
# Note the way the Option class is defined, put has a -1 input and call has a +1 input
|
||||
for df, option_type in zip(df_list, option_factor):
|
||||
df["Delta"] = df.apply(
|
||||
lambda x: Option(
|
||||
last_price, x.strike, 0.03, 0, dt, x.impliedVolatility, option_type
|
||||
last_price, x.strike, rf, 0, dt, x.impliedVolatility, option_type
|
||||
).Delta(),
|
||||
axis=1,
|
||||
)
|
||||
@@ -142,13 +143,13 @@ def get_option_chain_expiry(
|
||||
warnings.simplefilter("ignore")
|
||||
df["Gamma"] = df.apply(
|
||||
lambda x: Option(
|
||||
last_price, x.strike, 0.03, 0, dt, x.impliedVolatility, option_type
|
||||
last_price, x.strike, rf, 0, dt, x.impliedVolatility, option_type
|
||||
).Gamma(),
|
||||
axis=1,
|
||||
)
|
||||
df["Theta"] = df.apply(
|
||||
lambda x: Option(
|
||||
last_price, x.strike, 0.03, 0, dt, x.impliedVolatility, option_type
|
||||
last_price, x.strike, rf, 0, dt, x.impliedVolatility, option_type
|
||||
).Theta(),
|
||||
axis=1,
|
||||
)
|
||||
@@ -542,7 +543,6 @@ def get_greeks(
|
||||
dif = (expire_dt - datetime.now() + timedelta(hours=16)).total_seconds() / (
|
||||
60 * 60 * 24
|
||||
)
|
||||
print(dif)
|
||||
strikes = []
|
||||
for _, row in chain.iterrows():
|
||||
vol = row["impliedVolatility"]
|
||||
|
||||
Reference in New Issue
Block a user