forked from mmarose14/options
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwheels.py
80 lines (65 loc) · 2.87 KB
/
wheels.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
import api
import files
import util
import panda_files
def findWheels(ListOfSymbols):
#filename_out = "output_{}.txt".format(config.STRATEGY)
MAX_BID_ASK_SPREAD = .10
MIN_PRICE = 10
MAX_PRICE = 20
MIN_PREM = .2
MAX_DELTA = -.16
matching_options = []
data_frame = []
for symbol in ListOfSymbols:
print(f"Processing {symbol}...")
last_price = api.getLastStockPrice(symbol)
if (last_price <= MIN_PRICE or last_price >= MAX_PRICE):
continue
expirations_list = util.listOfLimitedExpirations(symbol,30,45)
numOptions = 0
for expiration in expirations_list:
options = api.getOptionsChain(symbol, expiration)
for option_item in options:
option = util.gatherOptionData(option_item)
if (option['bid'] is None):
continue
#Estimated premium (mid price)
premium = round((option['bid'] + option['ask']) / 2,2)
if ('delta' in option):
delta = option['delta']
if (option['type'] == "put"
and option['bid'] > 0
and delta >= MAX_DELTA
and premium >= MIN_PREM
and (option['ask'] - option['bid']) <= MAX_BID_ASK_SPREAD
and option['volume'] > 0
):
option_output = '{}, {}, BID:{}, ASK:{}, {}, {}(D), Premium: {}'\
.format(
option['expiration'],
option['strike'],
option['bid'],
option['ask'],
option['volume'],
option['delta'],
premium)
if (numOptions == 0):
matching_options.append(f"Symbol: {symbol}")
numOptions += 1
#matching_options.append(f"Wheel: {option_output} - ({datetime.now()})")
#line = f"Wheel: {symbol} {option_output} - ({datetime.now()})"
#files.appendLineToFile(line, filename_out)
#Print the screen when a match is found
print(f"Wheel: {option_output} - ({datetime.now()})")
data_frame.append([symbol,
option['expiration'],
option['strike'],
option['bid'],
option['ask'],
option['volume'],
delta,
premium,
""])
panda_files.exportToFile(data_frame, "output_wheels.csv")
return ""