Skip to content

Commit

Permalink
Update for better UI
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmayHundekari committed Jul 28, 2013
1 parent c351601 commit 342d59f
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions option.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def __init__(self, k, s, rf, t, vol=0.1):
self.rf = float(rf)
self.vol = float(vol)
self.t = float(t)
self.calc_D()

def calc_D(self):
self.d1 = ((math.log(self.s/self.k) +
Expand All @@ -37,19 +38,15 @@ def get_delta(self, d=0.01, callorput='C'):
else:
return -norm.cdf(-self.d1)

def get_theta(self, dt=1.0/365, callorput='C'):
def get_theta(self, callorput='C'):
t1 = self.t
_b_ = math.e**-(self.rf* t1)
if callorput == 'C':
self.t += dt
after_call_price = self.get_call()
self.t -= dt
org_call_price = self.get_call()
return (after_call_price - org_call_price) * -1.0
theta = -self.s * norm.pdf(self.d1) * self.vol / (2 * self.t ** 0.5) - (1.0+self.rf) * self.k * _b_ * norm.cdf(self.d2)
else:
self.t += dt
after_put_price = self.get_put()
self.t -= dt
org_put_price = self.get_put()
return (after_put_price - org_put_price) * -1.0
theta = -(-self.s * norm.pdf(self.d1) * self.vol /(2 * self.t **0.5) + (1.0+self.rf) *self.k * _b_ * norm.cdf(-self.d2))
return theta / 365


def get_vega(self):
return self.s * norm.pdf(self.d1) * (self.t) ** 0.5 / 100
Expand All @@ -76,10 +73,33 @@ def get_iv(self, price, callorput='C'):

def print_greeks(self, price, callorput):
self.vol = self.get_iv(price, callorput)
self.calc_D()
delta = self.get_delta(callorput=callorput)
theta = self.get_theta(callorput=callorput)
vega = self.get_vega()
print "Delta :", delta
print "Theta :", theta
print "Vega :", vega
print "Vol :", self.vol * 100

def getGreeks(self, price, callorput):
self.vol = self.get_iv(price, callorput)
self.calc_D()
delta = self.get_delta(callorput=callorput)
theta = self.get_theta(callorput=callorput)
vega = self.get_vega()
return delta, theta, vega, self.vol


def getProbITM(self, be, bo):
v = self.vol * math.sqrt(self.t*256)/math.sqrt(256)
if be:
becdf = 1 - norm.cdf(be[0],self.s,self.s*v)
else:
becdf = 1.0
if bo:
bocdf = 1.0 - norm.cdf(bo[0],self.s,self.s*v)
else:
bocdf = 0.0
print "Probability of ITM",(becdf-bocdf) * 100, "%"
return becdf-bocdf

0 comments on commit 342d59f

Please sign in to comment.