Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing the greeks calculations #3690

Merged
merged 1 commit into from
Dec 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 14 additions & 21 deletions openbb_terminal/stocks/options/op_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,19 +282,14 @@ def Delta(self):

def Vega(self):
"""Vega for 1% change in vol"""
return (
0.01
* self.price
* np.exp(-self.div_cont * self.exp_time)
* norm.pdf(self.d1)
* self.exp_time**0.5
)
dfq = np.exp(-self.div_cont * self.exp_time)
return 0.01 * self.price * dfq * norm.pdf(self.d1) * self.exp_time**0.5

def Theta(self):
"""Theta for 1 day change"""
def Theta(self, time_factor=1.0 / 365.0):
"""Theta, by default for 1 calendar day change"""
df = np.exp(-self.risk_free * self.exp_time)
dfq = np.exp(-self.div_cont * self.exp_time)
tmptheta = (1.0 / 365.0) * (
tmptheta = time_factor * (
-0.5
* self.price
* dfq
Expand All @@ -310,7 +305,7 @@ def Theta(self):
return tmptheta

def Rho(self):
df = e ** -(self.risk_free * self.exp_time)
df = np.exp(-self.risk_free * self.exp_time)
return (
self.Type
* self.strike
Expand All @@ -321,30 +316,28 @@ def Rho(self):
)

def Phi(self):
dfq = np.exp(-self.div_cont * self.exp_time)
return (
0.01
* -self.Type
* self.exp_time
* self.price
* e ** (-self.div_cont * self.exp_time)
* dfq
* norm.cdf(self.Type * self.d1)
)

# 2nd order greeks

def Gamma(self):
return (
e ** (-self.div_cont * self.exp_time)
* norm.pdf(self.d1)
/ (self.price * self.sigmaT)
)
dfq = np.exp(-self.div_cont * self.exp_time)
return dfq * norm.pdf(self.d1) / (self.price * self.sigmaT)

def Charm(self):
"""Calculates Charm for one day change"""
dfq = e ** (-self.div_cont * self.exp_time)
def Charm(self, time_factor=1.0 / 365.0):
"""Calculates Charm, by default for 1 calendar day change"""
dfq = np.exp(-self.div_cont * self.exp_time)
cdf = norm.cdf(self.Type * self.d1)
return (
(1.0 / 365.0)
time_factor
* -dfq
* (
norm.pdf(self.d1)
Expand Down
2 changes: 1 addition & 1 deletion openbb_terminal/stocks/options/yfinance_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ def get_greeks(

risk_free = rf if rf is not None else get_rf()
expire_dt = datetime.strptime(expire, "%Y-%m-%d")
dif = (expire_dt - datetime.now()).seconds / (60 * 60 * 24)
dif = (expire_dt - datetime.now()).total_seconds() / (60 * 60 * 24)

strikes = []
for _, row in chain.iterrows():
Expand Down