-
-
Notifications
You must be signed in to change notification settings - Fork 266
/
thetagang.toml
331 lines (281 loc) · 11.4 KB
/
thetagang.toml
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
# NOTE: It is STRONGLY recommended you read through all notes, config options,
# and documentation before proceeding. Be sure to update the configuration
# values according to your preferences. Additionally, any default values in
# this config do not constitute a recommendation or endorsement, or any provide
# claims abount returns or performance.
#
# Should you decide to use ThetaGang, please experiment with a paper trading
# account before trying on a live account.
[account]
# The account number to operate on
number = "DU1234567"
# Cancel any existing orders for the symbols configured at startup
cancel_orders = true
# Maximum amount of margin to use, as a ratio of net liquidation. IB lets
# you use varying amounts of margin, depending on the assets. To use up to 4x
# margin, set this to 4. It's recommended you always leave some additional
# cushion. IB will start to close positions if you go below certain thresholds
# of available margin in your account.
#
# For details on margin usage, see:
# https://www.interactivebrokers.com/en/index.php?f=24176
#
# The default value uses 50% of your available net liquidation value
# (i.e., half of your funds). Set this to 1.0 to use all your funds,
# or 1.5 to use 150% (which may incur margin interest charges).
#
# In other words, ThetaGang's buying power is calculated by taking your NLV and
# multiplying it by margin_usage.
margin_usage = 0.5
# Market data type (see
# https://interactivebrokers.github.io/tws-api/market_data_type.html)
market_data_type = 1
[orders]
# The exchange to route orders to. Can be overridden if desired. This is also
# used for fetching tickers/prices.
exchange = "SMART"
[orders.algo]
# By default we use adaptive orders with patient priority which gives reasonable
# results. You can also experiment with TWAP or other options, however the
# available order algos vary depending on what you trade.
#
# Note that the algo orders don't seem to work with combo orders, which are used
# when rolling positions, so AFAIK this has no effect for those orders. It only
# seems to take effect with regular open/close orders.
# Optional IBKR algo strategy. See
# https://interactivebrokers.github.io/tws-api/ibalgos.html for option details.
strategy = "Adaptive"
# For `algoParams`, the TagValue parameter has 2 values, so any values with
# anything other than 2 parameters are invalid. Pass an empty list to use the
# defaults (i.e., params = []).
params = [["adaptivePriority", "Patient"]]
[option_chains]
# The option chains are lazy loaded, and before you can determine the greeks
# (delta) or prices, you need to scan the chains. The settings here tell
# thetagang how many contracts to load. Don't make these values too high, as
# they will cause the chain scanning process to take too long, and it may fail.
#
# If you have issues where thetagang can't find suitable contracts, try
# increasing these values slightly.
#
# Number of expirations to load from option chains
expirations = 4
# Number of strikes to load from option chains
strikes = 15
[roll_when]
# Roll when P&L reaches 90%
pnl = 0.9
# Or, roll options when there are <= 15 days to expiry and P&L is at least
# min_pnl (min_pnl defaults to 0)
#
# NOTE: For cases where an option ends up deep ITM, notably when selling
# covered calls, it's possible that the P&L would be significantly negative,
# i.e., -100%. If you want to roll anyway in these situations, set min_pnl to a
# negative value such as -1 (for -100%).
dte = 15
min_pnl = 0.0
# Optional: Don't roll contracts when the current DTE is greater than this
# number of days. This helps avoid cases where you end up rolling out to LEAPs.
# max_dte = 180
# Optional: Create a closing order when the P&L reaches this threshold. This
# overrides the other parameters, i.e., it ignores DTE and everything else.
# If not specified, it has no effect. This can handle the case where you have
# long-dated options that have slowly become worthless and you just want to get
# them out of your portfolio.
# close_at_pnl = 0.99
[roll_when.calls]
# Roll calls to the next expiration even if they're in the money. Defaults to
# true if not specified.
itm = true
# Only roll when there's a suitable contract available that will result in a
# credit.
credit_only = false
# If set to false, calls will not be rolled if there are any number of calls in
# excess of the target call quantity. A truthy value means thetagang will keep
# rolling calls regardless of the total quantity.
has_excess = true
[roll_when.puts]
# Roll puts if they're in the money. Defaults to false if not specified.
itm = false
# Only roll when there's a suitable contract available that will result in a
# credit.
credit_only = false
# If set to false, puts will not be rolled if there are any number of puts in
# excess of the target put quantity. A truthy value means thetagang will keep
# rolling puts regardless of the total quantity.
has_excess = true
[write_when.calls]
# Optionally, only write calls when the underlying is green
green = true
# With covered calls, we can cap the number of calls to write by this factor. At
# 1.0, we write covered calls on 100% of our positions. At 0.5, we'd only write
# on 50% of our positions. This value must be between 1 and 0 inclusive.
cap_factor = 1.0
[write_when.puts]
# Optionally, only write puts when the underlying is red
red = true
[target]
# Target 45 or more days to expiry
dte = 45
# Target delta of 0.3 or less. Defaults to 0.3 if not specified.
delta = 0.3
# When writing new contracts (either covered calls or naked puts), or rolling
# before `roll_when.dte` is reached, never write more than this amount of
# contracts at once. This can be useful to avoid bunching by spreading contract
# placement out over time (and possibly expirations) in order to protect
# yourself from large swings. This value does not affect rolling existing
# contracts to the next expiration. This value is expressed as a percentage of
# buying power based on the market price of the underlying ticker, as a range
# from [0.0-1.0].
#
# Once the `roll_when.dte` date is reached, all the remaining positions are
# rolled regardless of the current position quantity.
#
# Defaults to 5% of buying power. Set this to 1.0 to effectively disable the
# limit.
maximum_new_contracts_percent = 0.05
# Minimum amount of open interest for a contract to qualify
minimum_open_interest = 10
# Optional: specify delta separately for puts/calls. Takes precedent over
# target.delta.
#
# [target.puts]
# delta = 0.5
# [target.calls]
# delta = 0.3
[symbols]
# NOTE: Please change these symbols and weights according to your preferences.
# These are provided only as an example for the purpose of configuration. These
# values were chosen as sane values should someone decide to run this code
# without changes, however it is in no way a recommendation or endorsement.
#
# You can specify the weight either as a percentage of your buying power (which
# is calculated as your NLV * account.margin_usage), or in terms of parts. Parts
# are summed from all symbols, then the weight is calculated by dividing the
# parts by the total parts.
#
# You should try to choose ETFs or stocks that:
#
# 1) Have sufficient trading volume for the underlying
# 2) Have standard options contracts (100 shares per contract)
# 3) Have options with sufficient open interest and trading volume
#
# The target delta may also be specified per-symbol, and takes precedence over
# `target.delta` or `target.puts/calls.delta`. You can specify a value for the
# symbol, or override individually for puts/calls.
[symbols.SPY]
weight = 0.4
# OR: specify in terms of parts. Must use either weight or parts, but cannot mix
# both.
# parts = 40
[symbols.QQQ]
weight = 0.3
# parts = 30
[symbols.QQQ.puts]
# Override delta just for QQQ puts
delta = 0.5
# Also, optionally specify a strike limit, for either puts or calls.
# Interpreted as an upper bound for puts, and a lower bound for calls.
strike_limit = 1000.0 # never write a put with a strike above $1000
# Optionally, if we only write new contracts when the underlying is green or
# red (`write_when.calls.green=true` or `write_when.puts.red=true`), specify a
# minimum threshold as an absolute value daily percentage change (in this
# example, use 1% for puts only, but could also be specified as
# `symbols.QQQ.write_threshold`).
#
# In this example, we'd only write puts on QQQ when the daily change is -1% or
# greater (provided that we also set `write_when.puts.red=true`).
write_threshold = 0.01 # 1%, absolute value
[symbols.QQQ.calls]
strike_limit = 100.0 # never write a call with a strike below $100
[symbols.TLT]
weight = 0.2
# parts = 20
# Override delta for this particular symbol, for both puts and calls.
delta = 0.4
[symbols.ABNB]
# For symbols that require an exchange, which is typically any company stock,
# you must specify the primary exchange.
primary_exchange = "NASDAQ"
weight = 0.05
# parts = 5
# Sometimes you may need to wrap the symbol in quotes.
[symbols."BRK B"]
# For symbols that require an exchange, which is typically any company stock,
# you must specify the primary exchange.
primary_exchange = "NYSE"
weight = 0.05
# parts = 5
[ib_insync]
logfile = '/etc/thetagang/ib_insync.log'
[ibc]
# IBC configuration parameters. See
# https://ib-insync.readthedocs.io/api.html#ibc for details.
gateway = true
ibcPath = '/opt/ibc'
tradingMode = 'paper'
# Set this to true if you want to raise an exception on request errors. Under
# normal operation this should be false because we often try to make "invalid"
# requests when scanning option chains for example.
RaiseRequestErrors = false
password = 'demo'
userid = 'demo'
# Change this to point to your config.ini for IBC
ibcIni = '/etc/thetagang/config.ini'
# Change or unset this to use something other than the Docker bundled OpenJDK.
javaPath = '/opt/java/openjdk/bin'
# twsPath = ''
# twsSettingsPath = ''
# fixuserid = ''
# fixpassword = ''
[watchdog]
# Watchdog configuration params. See
# https://ib-insync.readthedocs.io/api.html#watchdog for details.
appStartupTime = 30
appTimeout = 20
clientId = 1
connectTimeout = 2
host = '127.0.0.1'
port = 7497
probeTimeout = 4
readonly = false
retryDelay = 2
[watchdog.probeContract]
currency = 'USD'
exchange = 'SMART'
secType = 'STK'
symbol = 'SPY'
# Optional VIX call hedging, based on the methodology described by the Cboe VIX
# Tail Hedge Index, described here:
# https://www.cboe.com/us/indices/dashboard/vxth/
[vix_call_hedge]
enabled = false
# Target delta for calls that are purchased
delta = 0.30
# If the current spot VIX exceeds this value, long VIX call positions will be
# closed
close_hedges_when_vix_exceeds = 50.0
# The allocations are specified as an ordered list of allocation weights
# according to an upper/lower bound on VIXMO (the 30 day VIX). Default values
# are the same as those described in the VXTH methodology. These are evaluated
# in order, and the weight from the first allocation that matches will be
# applied. The lower bound is inclusive, and the upper bound is exclusive
# (.i.e., the code checks that lower <= VIXMO < upper). The upper/lower bounds
# are only checked if they're present.
#
# The allocation weights are multiplied by the account's net liquidation value,
# and that amount is allocated to purchasing VIX calls.
[[vix_call_hedge.allocation]]
upper_bound = 15.0
weight = 0.00
[[vix_call_hedge.allocation]]
lower_bound = 15.0
upper_bound = 30.0
weight = 0.01
[[vix_call_hedge.allocation]]
lower_bound = 30.0
upper_bound = 50.0
weight = 0.005
[[vix_call_hedge.allocation]]
lower_bound = 50.0
weight = 0.00