Skip to content

Commit 404a215

Browse files
author
rob
committed
black lines matter
1 parent 95de657 commit 404a215

File tree

3 files changed

+120
-59
lines changed

3 files changed

+120
-59
lines changed

sysproduction/interactive_controls.py

+73-37
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,12 @@ def view_trade_limits(data):
156156
def change_limit_for_instrument(data):
157157
trade_limits = dataTradeLimits(data)
158158
instrument_code = get_valid_instrument_code_from_user(data)
159-
period_days = get_input_from_user_and_convert_to_type("Period of days?", type_expected=int, allow_default=True,
160-
default_value=1)
161-
new_limit = get_input_from_user_and_convert_to_type("Limit (in contracts?)", type_expected=int, allow_default=False)
159+
period_days = get_input_from_user_and_convert_to_type(
160+
"Period of days?", type_expected=int, allow_default=True, default_value=1
161+
)
162+
new_limit = get_input_from_user_and_convert_to_type(
163+
"Limit (in contracts?)", type_expected=int, allow_default=False
164+
)
162165
ans = input(
163166
"Update will change number of trades allowed in periods, but won't reset 'clock'. Are you sure? (y/other)"
164167
)
@@ -171,8 +174,9 @@ def change_limit_for_instrument(data):
171174
def reset_limit_for_instrument(data):
172175
trade_limits = dataTradeLimits(data)
173176
instrument_code = get_valid_instrument_code_from_user(data)
174-
period_days = get_input_from_user_and_convert_to_type("Period of days?", type_expected=int, allow_default=True,
175-
default_value=1)
177+
period_days = get_input_from_user_and_convert_to_type(
178+
"Period of days?", type_expected=int, allow_default=True, default_value=1
179+
)
176180
ans = input("Reset means trade 'clock' will restart. Are you sure? (y/other)")
177181
if ans == "y":
178182
trade_limits.reset_instrument_limit(instrument_code, period_days)
@@ -189,9 +193,12 @@ def change_limit_for_instrument_strategy(data):
189193
trade_limits = dataTradeLimits(data)
190194
instrument_code = get_valid_instrument_code_from_user(data)
191195
strategy_name = get_valid_strategy_name_from_user(data)
192-
period_days = get_input_from_user_and_convert_to_type("Period of days?", type_expected=int, allow_default=True,
193-
default_value=1)
194-
new_limit = get_input_from_user_and_convert_to_type("Limit (in contracts?)", type_expected=int, allow_default=False)
196+
period_days = get_input_from_user_and_convert_to_type(
197+
"Period of days?", type_expected=int, allow_default=True, default_value=1
198+
)
199+
new_limit = get_input_from_user_and_convert_to_type(
200+
"Limit (in contracts?)", type_expected=int, allow_default=False
201+
)
195202

196203
ans = input(
197204
"Update will change number of trades allowed in periods, but won't reset 'clock'. Are you sure? (y/other)"
@@ -210,8 +217,9 @@ def change_limit_for_instrument_strategy(data):
210217
def reset_limit_for_instrument_strategy(data):
211218
trade_limits = dataTradeLimits(data)
212219
instrument_code = get_valid_instrument_code_from_user(data)
213-
period_days = get_input_from_user_and_convert_to_type("Period of days?", type_expected=int, allow_default=True,
214-
default_value=1)
220+
period_days = get_input_from_user_and_convert_to_type(
221+
"Period of days?", type_expected=int, allow_default=True, default_value=1
222+
)
215223
strategy_name = get_valid_strategy_name_from_user(data=data, source="positions")
216224

217225
ans = input("Reset means trade 'clock' will restart. Are you sure? (y/other)")
@@ -232,10 +240,13 @@ def auto_populate_limits(data: dataBlob):
232240
auto_parameters = get_auto_population_parameters()
233241

234242
trade_multiplier = get_input_from_user_and_convert_to_type(
235-
"Higgest proportion of standard position expected to trade daily?", type_expected=float,
236-
default_value=MAX_POSITION_TRADED_DAILY)
237-
period_days = get_input_from_user_and_convert_to_type("What period in days to set limit for?", type_expected=int,
238-
default_value=1)
243+
"Higgest proportion of standard position expected to trade daily?",
244+
type_expected=float,
245+
default_value=MAX_POSITION_TRADED_DAILY,
246+
)
247+
period_days = get_input_from_user_and_convert_to_type(
248+
"What period in days to set limit for?", type_expected=int, default_value=1
249+
)
239250
_ = [
240251
set_trade_limit_for_instrument(
241252
data,
@@ -306,25 +317,36 @@ def calc_trade_limit_for_instrument(
306317

307318
def get_auto_population_parameters() -> parametersForAutoPopulation:
308319
print("Enter parameters to estimate typical position sizes")
309-
notional_risk_target = get_input_from_user_and_convert_to_type("Notional risk target (% per year, 0.25 = 25%%)",
310-
type_expected=float,
311-
default_value=RISK_TARGET_ASSUMED / 100.0)
312-
approx_IDM = get_input_from_user_and_convert_to_type("Approximate IDM", type_expected=float,
313-
default_value=IDM_ASSUMED)
320+
notional_risk_target = get_input_from_user_and_convert_to_type(
321+
"Notional risk target (% per year, 0.25 = 25%%)",
322+
type_expected=float,
323+
default_value=RISK_TARGET_ASSUMED / 100.0,
324+
)
325+
approx_IDM = get_input_from_user_and_convert_to_type(
326+
"Approximate IDM", type_expected=float, default_value=IDM_ASSUMED
327+
)
314328
notional_instrument_weight = get_input_from_user_and_convert_to_type(
315-
"Notional instrument weight (go large for safety!)", type_expected=float,
316-
default_value=INSTRUMENT_WEIGHT_ASSUMED)
329+
"Notional instrument weight (go large for safety!)",
330+
type_expected=float,
331+
default_value=INSTRUMENT_WEIGHT_ASSUMED,
332+
)
317333
raw_max_leverage = get_input_from_user_and_convert_to_type(
318-
"Maximum Leverage per instrument (notional exposure*# contracts / capital)", type_expected=float,
319-
default_value=RAW_MAX_LEVERAGE)
334+
"Maximum Leverage per instrument (notional exposure*# contracts / capital)",
335+
type_expected=float,
336+
default_value=RAW_MAX_LEVERAGE,
337+
)
320338

321339
max_proportion_risk_one_contract = get_input_from_user_and_convert_to_type(
322-
"Maximum proportion of risk in a single instrument (0.1 = 10%%)", type_expected=float,
323-
default_value=MAX_RISK_EXPOSURE_ONE_INSTRUMENT)
340+
"Maximum proportion of risk in a single instrument (0.1 = 10%%)",
341+
type_expected=float,
342+
default_value=MAX_RISK_EXPOSURE_ONE_INSTRUMENT,
343+
)
324344

325345
max_proportion_of_volume = get_input_from_user_and_convert_to_type(
326-
"Maximum proportion of volume for expiry with largest volume (0.1 = 10%)", type_expected=float,
327-
default_value=MAX_PROPORTION_OF_VOLUME)
346+
"Maximum proportion of volume for expiry with largest volume (0.1 = 10%)",
347+
type_expected=float,
348+
default_value=MAX_PROPORTION_OF_VOLUME,
349+
)
328350

329351
auto_parameters = parametersForAutoPopulation(
330352
raw_max_leverage=raw_max_leverage,
@@ -537,9 +559,13 @@ def change_position_limit_for_instrument(data):
537559
view_position_limit(data)
538560
data_position_limits = dataPositionLimits(data)
539561
instrument_code = get_valid_instrument_code_from_user(data, allow_all=False)
540-
new_position_limit = get_input_from_user_and_convert_to_type("New position limit?", type_expected=int,
541-
allow_default=True, default_value=-1,
542-
default_str="No limit")
562+
new_position_limit = get_input_from_user_and_convert_to_type(
563+
"New position limit?",
564+
type_expected=int,
565+
allow_default=True,
566+
default_value=-1,
567+
default_str="No limit",
568+
)
543569
if new_position_limit == -1:
544570
data_position_limits.delete_position_limit_for_instrument(instrument_code)
545571
else:
@@ -556,9 +582,13 @@ def change_position_limit_for_instrument_strategy(data):
556582
data, allow_all=False, source="positions"
557583
)
558584
instrument_code = get_valid_instrument_code_from_user(data, allow_all=False)
559-
new_position_limit = get_input_from_user_and_convert_to_type("New position limit?", type_expected=int,
560-
allow_default=True, default_value=-1,
561-
default_str="No limit")
585+
new_position_limit = get_input_from_user_and_convert_to_type(
586+
"New position limit?",
587+
type_expected=int,
588+
allow_default=True,
589+
default_value=-1,
590+
default_str="No limit",
591+
)
562592

563593
instrument_strategy = instrumentStrategy(
564594
instrument_code=instrument_code, strategy_name=strategy_name
@@ -862,8 +892,11 @@ def get_list_of_changes_to_make_to_slippage(
862892

863893
estimate_to_use_with_mult = get_input_from_user_and_convert_to_type(
864894
"New configured slippage value (current %f, default is estimate %f)"
865-
% (configured_estimate_multiplied, suggested_estimate_multiplied), type_expected=float, allow_default=True,
866-
default_value=suggested_estimate_multiplied)
895+
% (configured_estimate_multiplied, suggested_estimate_multiplied),
896+
type_expected=float,
897+
allow_default=True,
898+
default_value=suggested_estimate_multiplied,
899+
)
867900

868901
if estimate_to_use_with_mult == configured_estimate_multiplied:
869902
print("Same as configured, do nothing...")
@@ -888,8 +921,11 @@ def get_list_of_changes_to_make_to_slippage(
888921

889922
def get_filter_size_for_slippage() -> float:
890923
filter = get_input_from_user_and_convert_to_type(
891-
"% difference to filter on? (eg 30 means we ignore differences<30%", type_expected=float, allow_default=True,
892-
default_value=30.0)
924+
"% difference to filter on? (eg 30 means we ignore differences<30%",
925+
type_expected=float,
926+
allow_default=True,
927+
default_value=30.0,
928+
)
893929

894930
return filter
895931

sysproduction/interactive_update_capital_manual.py

+35-18
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,29 @@ def setup_initial_capital(data: dataBlob):
107107

108108

109109
def get_initial_capital_values_from_user(data: dataBlob):
110-
broker_account_value = get_input_from_user_and_convert_to_type("Broker account value", type_expected=float,
111-
default_value=arg_not_supplied,
112-
default_str="get from IB")
110+
broker_account_value = get_input_from_user_and_convert_to_type(
111+
"Broker account value",
112+
type_expected=float,
113+
default_value=arg_not_supplied,
114+
default_str="get from IB",
115+
)
113116
if broker_account_value is arg_not_supplied:
114117
broker_account_value = get_broker_account_value(data)
115118
print("Got broker account value of %f from IB" % broker_account_value)
116119

117-
total_capital = get_input_from_user_and_convert_to_type("Total capital at risk", type_expected=float,
118-
default_value=broker_account_value)
120+
total_capital = get_input_from_user_and_convert_to_type(
121+
"Total capital at risk", type_expected=float, default_value=broker_account_value
122+
)
119123

120-
maximum_capital = get_input_from_user_and_convert_to_type("Max capital, only used for half compounding",
121-
type_expected=float, default_value=total_capital)
124+
maximum_capital = get_input_from_user_and_convert_to_type(
125+
"Max capital, only used for half compounding",
126+
type_expected=float,
127+
default_value=total_capital,
128+
)
122129

123-
acc_pandl = get_input_from_user_and_convert_to_type("Accumulated profit", type_expected=float, default_value=0.0)
130+
acc_pandl = get_input_from_user_and_convert_to_type(
131+
"Accumulated profit", type_expected=float, default_value=0.0
132+
)
124133

125134
return broker_account_value, total_capital, maximum_capital, acc_pandl
126135

@@ -167,7 +176,8 @@ def adjust_capital_for_delta(data: dataBlob):
167176

168177
capital_delta = get_input_from_user_and_convert_to_type(
169178
"What change have you made to brokerage account that will not change capital +ve deposit, -ve withdrawal",
170-
type_expected=float)
179+
type_expected=float,
180+
)
171181
effect = data_capital.return_str_with_effect_of_delta_adjustment(capital_delta)
172182

173183
user_wants_adjustment = true_if_answer_is_yes("%s, are you sure? " % effect)
@@ -202,21 +212,28 @@ def get_values_from_user_to_modify(data: dataBlob):
202212
data_capital = dataCapital(data)
203213

204214
current_broker_value = data_capital.get_current_broker_account_value()
205-
broker_account_value = get_input_from_user_and_convert_to_type("Broker account value", type_expected=float,
206-
default_value=current_broker_value)
215+
broker_account_value = get_input_from_user_and_convert_to_type(
216+
"Broker account value", type_expected=float, default_value=current_broker_value
217+
)
207218

208219
current_total_capital = data_capital.get_current_total_capital()
209-
total_capital = get_input_from_user_and_convert_to_type("Total capital at risk", type_expected=float,
210-
default_value=current_total_capital)
220+
total_capital = get_input_from_user_and_convert_to_type(
221+
"Total capital at risk",
222+
type_expected=float,
223+
default_value=current_total_capital,
224+
)
211225

212226
current_maximum_capital = data_capital.get_current_maximum_capital()
213-
maximum_capital = get_input_from_user_and_convert_to_type("Max capital, only used for half compounding",
214-
type_expected=float,
215-
default_value=current_maximum_capital)
227+
maximum_capital = get_input_from_user_and_convert_to_type(
228+
"Max capital, only used for half compounding",
229+
type_expected=float,
230+
default_value=current_maximum_capital,
231+
)
216232

217233
current_acc_profit = data_capital.get_current_accumulated_pandl()
218-
acc_pandl = get_input_from_user_and_convert_to_type("Accumulated profit", type_expected=float,
219-
default_value=current_acc_profit)
234+
acc_pandl = get_input_from_user_and_convert_to_type(
235+
"Accumulated profit", type_expected=float, default_value=current_acc_profit
236+
)
220237

221238
return broker_account_value, total_capital, maximum_capital, acc_pandl
222239

sysproduction/interactive_update_roll_status.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,12 @@ def update_roll_status_full_auto(data: dataBlob):
186186

187187

188188
def get_days_ahead_to_consider_when_auto_cycling() -> int:
189-
days_ahead = get_input_from_user_and_convert_to_type("How many days ahead should I look for expiries?",
190-
type_expected=int, allow_default=True, default_value=10)
189+
days_ahead = get_input_from_user_and_convert_to_type(
190+
"How many days ahead should I look for expiries?",
191+
type_expected=int,
192+
allow_default=True,
193+
default_value=10,
194+
)
191195

192196
return days_ahead
193197

@@ -240,8 +244,12 @@ class autoRollParameters:
240244

241245

242246
def get_auto_roll_parameters() -> autoRollParameters:
243-
min_volume = get_input_from_user_and_convert_to_type("Minimum relative volume before rolling", type_expected=float,
244-
allow_default=True, default_value=0.1)
247+
min_volume = get_input_from_user_and_convert_to_type(
248+
"Minimum relative volume before rolling",
249+
type_expected=float,
250+
allow_default=True,
251+
default_value=0.1,
252+
)
245253

246254
manual_prompt_for_position = true_if_answer_is_yes(
247255
"Manually prompt for state if have position? (y/n)"

0 commit comments

Comments
 (0)