-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathsearching.py
145 lines (125 loc) · 3.81 KB
/
searching.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
from pricing import Pricing
#in deep development
class Search(Pricing):
def searchDelta(self, fPrice, deep, acc, paramD, params):
"""if paramD['dType'] == 'C':
if paramD['quant'] < 0:
direct = 'U'
else:
direct = 'D'
else:
if paramD['quant'] < 0:
direct = 'D'
else:
direct = 'U'
if direct == 'U':
start = fPrice
finish = fPrice + deep
else:
start = fPrice - deep
finish = fPrice"""
matrix = []
start = fPrice - deep
finish = fPrice + deep
while start <= finish:
deltaD = round((self.delta(start, paramD['strike'], paramD['vola'], paramD['exp'], paramD['dType'])) * paramD['quant'], 4)
deltaF = round(self.deltaFull(start, params, 0), 3)
#print(start, '|', deltaD, '|', deltaF)
if deltaD == -deltaF:
if paramD['dType'] != 'F':
theo = round(self.theo(start, paramD['strike'], paramD['vola'], paramD['exp'], paramD['dType']), 3)
else:
theo = 0
matrix.append([round(start, 2), paramD['dType'], paramD['strike'], paramD['quant'], deltaD, deltaF , theo])
#break
start = start + acc
i = 0
n = len(matrix)
prices = []
while i < n:
if prices:
if matrix[i-1][4] != matrix[i][4]:
prices.append(matrix[i])
else:
prices.append(matrix[i])
i = i + 1
for j in prices:
print(j[0], '|', j[1], '|', j[2], '|', j[3], '|', j[4], '|', j[5], '|', j[6])
search = Search()
god = 365
step = 10
deep = 7500
exp = 30 / god
exp2 = 15 / god
exp3 = 5 / god
fPrice = 21000
params = []
dType = 'F'
quant = 1
price = 20000
strike = 0
vola = 0
params.append({'dType': dType, 'price': price, 'quant': quant, 'strike': strike, 'vola': vola, 'exp': exp})
dType = 'C'
quant = 1
price = 500
strike = 25000
vola = 0.75
params.append({'dType': dType, 'price': price, 'quant': quant, 'strike': strike, 'vola': vola, 'exp': exp})
dType = 'P'
quant = 1
price = 100
strike = 15000
vola = 0.75
params.append({'dType': dType, 'price': price, 'quant': quant, 'strike': strike, 'vola': vola, 'exp': exp})
dType = 'P'
quant = -1
price = 25
strike = 10000
vola = 1.5
params.append({'dType': dType, 'price': price, 'quant': quant, 'strike': strike, 'vola': vola, 'exp': exp})
bePriceS = fPrice - deep
bePriceF = fPrice + deep
acc = 0.1
dType = 'F'
strike = 0
price = 0
quant = -1
vola = 0
paramD_1 = {'dType': dType, 'price': price, 'quant': quant, 'strike': strike, 'vola': vola, 'exp': exp}
dType = 'F'
strike = 0
price = 0
quant = 1
vola = 0
paramD1 = {'dType': dType, 'price': price, 'quant': quant, 'strike': strike, 'vola': vola, 'exp': exp}
dType = 'F'
strike = 0
price = 0
quant = -2
vola = 0
paramD_2 = {'dType': dType, 'price': price, 'quant': quant, 'strike': strike, 'vola': vola, 'exp': exp}
dType = 'F'
strike = 0
price = 0
quant = 2
vola = 0
paramD2 = {'dType': dType, 'price': price, 'quant': quant, 'strike': strike, 'vola': vola, 'exp': exp}
dType = 'F'
strike = 0
price = 0
quant = -3
vola = 0
paramD_3 = {'dType': dType, 'price': price, 'quant': quant, 'strike': strike, 'vola': vola, 'exp': exp}
dType = 'F'
strike = 0
price = 0
quant = 3
vola = 0
paramD3 = {'dType': dType, 'price': price, 'quant': quant, 'strike': strike, 'vola': vola, 'exp': exp}
search.searchDelta(fPrice, deep, acc, paramD1, params)
search.searchDelta(fPrice, deep, acc, paramD_1, params)
search.searchDelta(fPrice, deep, acc, paramD2, params)
search.searchDelta(fPrice, deep, acc, paramD_2, params)
search.searchDelta(fPrice, deep, acc, paramD3, params)
search.searchDelta(fPrice, deep, acc, paramD_3, params)