Skip to content

Commit

Permalink
Fixing the greeks command (#3690)
Browse files Browse the repository at this point in the history
  • Loading branch information
northern-64bit authored Dec 4, 2022
1 parent faca7ab commit 5dbe9f5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
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

0 comments on commit 5dbe9f5

Please sign in to comment.