-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter_options_greeks.py
39 lines (33 loc) · 1.33 KB
/
filter_options_greeks.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
# region imports
from AlgorithmImports import *
from datetime import timedelta
# endregion
class GreeksFilterAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2020, 1, 1)
self.SetEndDate(2020, 1, 31)
self.SetCash(100000)
# Add the underlying equity
self.equity = self.AddEquity("SPY", Resolution.Minute).Symbol
# Add options and set a broad filter
option = self.AddOption("SPY", Resolution.Minute)
option.SetFilter(
lambda universe: universe.IncludeWeeklys()
.Strikes(-10, 10)
.Expiration(timedelta(0), timedelta(60))
)
self.optionSymbol = option.Symbol
def OnData(self, data):
if self.optionSymbol in data.OptionChains:
chain = data.OptionChains[self.optionSymbol]
for contract in chain:
# Check if Greeks data is available
if contract.Greeks is not None:
delta = abs(contract.Greeks.Delta)
if 0.2 <= delta <= 0.5:
self.Debug(
"Selected option by Greeks (Delta: {:.2f}): {}".format(
delta, contract.Symbol
)
)
break