Skip to content

Commit 9992837

Browse files
committed
BTC example
1 parent a0a0860 commit 9992837

File tree

1 file changed

+36
-33
lines changed

1 file changed

+36
-33
lines changed

option.py

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ def theo(self, S, K, V, T, dT):
2727
else:
2828
return K * self.cdf(-self.d2(S, K, V, T)) - S * self.cdf(-self.d1(S, K, V, T))
2929

30-
3130
def delta(self, S, K, V, T, dT):
3231
if dT == 'C':
3332
delta = self.cdf(self.d1(S, K, V, T))
@@ -226,55 +225,52 @@ def searchDelta(self, fPrice, deep, acc, paramD, params):
226225

227226
calc = Calculation()
228227

229-
deep = 2
230-
231-
acc = 0.0001
232228

233-
exp = 15 / god
229+
'''deep = 2
234230
235-
fPrice = 55
231+
exp = 30 / god
236232
237-
volaShift = 0/100
233+
fPrice = 21000
238234
239-
exp2 = 12
240-
exp3 = 9
235+
exp2 = 15 / god
236+
exp3 = 5 / god
241237
242238
params = []
243239
244240
dType = 'F'
245-
quant = 4
246-
price = 55.36
241+
quant = 1
242+
price = 20000
247243
strike = 0
248244
vola = 0
249245
params.append({'dType': dType, 'price': price, 'quant': quant, 'strike': strike, 'vola': vola, 'exp': exp})
250246
251247
dType = 'C'
252248
quant = 10
253249
price = 1.31
254-
strike = 56
255-
vola = 27.25/100 + volaShift
250+
strike = 25000
251+
vola = 27.25
256252
params.append({'dType': dType, 'price': price, 'quant': quant, 'strike': strike, 'vola': vola, 'exp': exp})
257253
258254
dType = 'P'
259255
quant = 8
260256
price = 1.24
261257
strike = 56
262-
vola = 27.25/100 + volaShift
258+
vola = 27.25
263259
params.append({'dType': dType, 'price': price, 'quant': quant, 'strike': strike, 'vola': vola, 'exp': exp})
264260
265261
dType = 'P'
266262
quant = 5
267263
price = 0.82
268264
strike = 55
269-
vola = 27.7/100 + volaShift
265+
vola = 27.7
270266
params.append({'dType': dType, 'price': price, 'quant': quant, 'strike': strike, 'vola': vola, 'exp': exp})
271267
272268
bePriceS = fPrice - deep
273-
bePriceF = fPrice + deep
269+
bePriceF = fPrice + deep'''
274270

275-
calc.plotPL(bePriceS, bePriceF, params, exp)
276-
calc.plotPL(bePriceS, bePriceF, params, exp2/god)
277-
calc.plotPL(bePriceS, bePriceF, params, exp3/god)
271+
'''calc.plotPL(bePriceS, bePriceF, params, exp)
272+
calc.plotPL(bePriceS, bePriceF, params, exp2)
273+
calc.plotPL(bePriceS, bePriceF, params, exp3)
278274
plt.ylabel("P/L")
279275
plt.xlabel("Price")
280276
plt.title("Option")
@@ -283,8 +279,8 @@ def searchDelta(self, fPrice, deep, acc, paramD, params):
283279
plt.show()
284280
285281
calc.plotDelta(bePriceS, bePriceF, params, exp)
286-
calc.plotDelta(bePriceS, bePriceF, params, exp2/god)
287-
calc.plotDelta(bePriceS, bePriceF, params, exp3/god)
282+
calc.plotDelta(bePriceS, bePriceF, params, exp2)
283+
calc.plotDelta(bePriceS, bePriceF, params, exp3)
288284
plt.xlabel("Price")
289285
plt.title("Option")
290286
plt.grid(True)
@@ -331,9 +327,11 @@ def searchDelta(self, fPrice, deep, acc, paramD, params):
331327
332328
print('G:\t', round(calc.gammaFull(fPrice, params, exp), 2))
333329
334-
print('P/L:\t', calc.p_l(fPrice, params, exp))
330+
print('P/L:\t', calc.p_l(fPrice, params, exp))'''
331+
335332

336-
#Donee
333+
"""
334+
acc = 0.0001
337335
338336
dType = 'F'
339337
strike = 0
@@ -377,20 +375,25 @@ def searchDelta(self, fPrice, deep, acc, paramD, params):
377375
vola = 0
378376
paramD3 = {'dType': dType, 'price': price, 'quant': quant, 'strike': strike, 'vola': vola, 'exp': exp}
379377
380-
381-
382-
383-
'''calc.searchDelta(fPrice, deep, acc, paramD1, params)
378+
calc.searchDelta(fPrice, deep, acc, paramD1, params)
384379
calc.searchDelta(fPrice, deep, acc, paramD_1, params)
385380
calc.searchDelta(fPrice, deep, acc, paramD2, params)
386381
calc.searchDelta(fPrice, deep, acc, paramD_2, params)
387382
calc.searchDelta(fPrice, deep, acc, paramD3, params)
388383
calc.searchDelta(fPrice, deep, acc, paramD_3, params)
384+
"""
385+
386+
387+
#Bitcon example
389388

390-
S = 54
391-
K = 53
392-
V = 0.35
393-
T = 3
394-
dT = "P"'''
389+
S = 21000 #Underlying (price now)
390+
K = 30000 #Strike
391+
V = 0.75 #Implied Volatility (1 / 100%)
392+
T = 30 / god #Expiration date (days from now / 365)
393+
dT = "C" #Call / Put
395394

396-
#print('One: ', round(calc.theo(S, K, V, T/god, dT), 2))
395+
print('Theo: ', round(calc.theo(S, K, V, T, dT), 2))
396+
print('Delta: ', round(calc.delta(S, K, V, T, dT), 2))
397+
print('Theta: ', round(calc.theta(S, K, V, T), 2))
398+
print('Vega: ', round(calc.vega(S, K, V, T), 2))
399+
print('Gamma: ', round(calc.gamma(S, K, V, T), 2))

0 commit comments

Comments
 (0)