11import math
2- import scipy .stats
32import matplotlib .pyplot as plt
43
54global god
109
1110class Calculation ():
1211
12+ def pdf (self , x ):
13+ return math .exp (- x ** 2 / 2 ) / math .sqrt (2 * math .pi )
14+
15+ def cdf (self , x ):
16+ return (1 + math .erf (x / math .sqrt (2 ))) / 2
17+
1318 def d1 (self , S , K , V , T ):
1419 return (math .log (S / float (K )) + (V ** 2 / 2 ) * T ) / (V * math .sqrt (T ))
1520
@@ -18,30 +23,30 @@ def d2(self, S, K, V, T):
1823
1924 def theo (self , S , K , V , T , dT ):
2025 if dT == 'C' :
21- return S * scipy . stats . norm . cdf (self .d1 (S , K , V , T )) - K * scipy . stats . norm .cdf (self .d2 (S , K , V , T ))
26+ return S * self . cdf (self .d1 (S , K , V , T )) - K * self .cdf (self .d2 (S , K , V , T ))
2227 else :
23- return K * scipy . stats . norm . cdf (- self .d2 (S , K , V , T )) - S * scipy . stats . norm .cdf (- self .d1 (S , K , V , T ))
28+ return K * self . cdf (- self .d2 (S , K , V , T )) - S * self .cdf (- self .d1 (S , K , V , T ))
2429
2530
2631 def delta (self , S , K , V , T , dT ):
2732 if dT == 'C' :
28- delta = scipy . stats . norm .cdf (self .d1 (S , K , V , T ))
33+ delta = self .cdf (self .d1 (S , K , V , T ))
2934 elif dT == 'P' :
30- delta = scipy . stats . norm .cdf (self .d1 (S , K , V , T )) - 1
35+ delta = self .cdf (self .d1 (S , K , V , T )) - 1
3136 else :
3237 delta = 1
3338 return delta
3439
3540 def vega (self , S , K , V , T ):
36- vega = (S * math .sqrt (T ) * scipy . stats . norm .pdf (self .d1 (S , K , V , T ))) / 100
41+ vega = (S * math .sqrt (T ) * self .pdf (self .d1 (S , K , V , T ))) / 100
3742 return vega
3843
3944 def theta (self , S , K , V , T ):
40- theta = - ((S * V * scipy . stats . norm .pdf (self .d1 (S , K , V , T ))) / (2 * math .sqrt (T ))) / god
45+ theta = - ((S * V * self .pdf (self .d1 (S , K , V , T ))) / (2 * math .sqrt (T ))) / god
4146 return theta
4247
4348 def gamma (self , S , K , V , T ):
44- gamma = scipy . stats . norm .pdf (self .d1 (S , K , V , T ))/ (S * V * math .sqrt (T ))
49+ gamma = self .pdf (self .d1 (S , K , V , T ))/ (S * V * math .sqrt (T ))
4550 return gamma
4651
4752
@@ -375,7 +380,7 @@ def searchDelta(self, fPrice, deep, acc, paramD, params):
375380
376381
377382
378- calc .searchDelta (fPrice , deep , acc , paramD1 , params )
383+ ''' calc.searchDelta(fPrice, deep, acc, paramD1, params)
379384calc.searchDelta(fPrice, deep, acc, paramD_1, params)
380385calc.searchDelta(fPrice, deep, acc, paramD2, params)
381386calc.searchDelta(fPrice, deep, acc, paramD_2, params)
@@ -386,6 +391,6 @@ def searchDelta(self, fPrice, deep, acc, paramD, params):
386391K = 53
387392V = 0.35
388393T = 3
389- dT = "P"
394+ dT = "P"'''
390395
391396#print('One: ', round(calc.theo(S, K, V, T/god, dT), 2))
0 commit comments