Closed robcarver17 closed 2 years ago
We want some kind of interactive process that will take you through the process, then if all is well will write the results to
If user is happy, write results:
Some of this could also be useful when putting new data into the system.
Seems to work
/usr/bin/python3.8 /home/rob/pysystemtrade/sysinit/futures/safely_modify_roll_parameters.py
Strongly suggest you backup and/or do this on a test machine first
Enter instrument code: Must be defined in database config
Instrument code?SILVER
Existing roll parameters: Must be defined in database config
Rollcycle parameters hold_rollcycle:FHKMNQUZ, priced_rollcycle:FHKMNQUZ, roll_offset_day:-45.0, carry_offset:-1.0, approx_expiry_offset:14.0
Hold rollcycle (use FGHJKMNQUVXZ) <RETURN for default FHKMNQUZ> HKNUZ
Priced rollcycle (use FGHJKMNQUVXZ) <RETURN for default FHKMNQUZ> FGHJKMNQUVXZ
Roll offset days versus expiry (normally negative) <RETURN for default -45.0>
Carry offset (ideally -1, 1 if trading front) <RETURN for default -1.0>
Approximate expiry day in month <RETURN for default 14.0> 26
New parameters: Rollcycle parameters hold_rollcycle:HKNUZ, priced_rollcycle:FGHJKMNQUVXZ, roll_offset_day:-45.0, carry_offset:-1.0, approx_expiry_offset:26
Happy with these?Yes
Path for writing roll calendar; must be absolute with leading \ or / eg /home/rob/pysystemtrade/data/futures/roll_calendars_csv//home/rob/pysystemtrade/data/futures/roll_calendars_csv/
Writing to /home/rob/pysystemtrade/data/futures/roll_calendars_csv/
/home/rob/pysystemtrade/sysobjects/futures_per_contract_prices.py:32: UserWarning: Pandas doesn't allow columns to be created via a new attribute name - see https://pandas.pydata.org/pandas-docs/stable/indexing.html#attribute-access
self._as_df = price_data_as_df
Prepping roll calendar... might take a few seconds
Warning! Before 19700700 the previous expected contract 19700600 in the priced roll cycle ( FGHJKMNQUVXZ ) not available! (OK if this is at the end of the calendar)
....
....
Changed date from 2022-06-13 15:00:00 to 2022-06-13 15:00:00 for row with contracts dict_items([('current_roll_date', Timestamp('2022-06-13 15:00:00')), ('current_contract', 20220700), ('next_contract', 20220900), ('carry_contract', 20220600)])
Changed date from 2022-08-12 23:00:00 to 2022-08-12 23:00:00 for row with contracts dict_items([('current_roll_date', Timestamp('2022-08-12 23:00:00')), ('current_contract', 20220900), ('next_contract', 20221200), ('carry_contract', 20220800)])
PRICE FORWARD ... FORWARD_CONTRACT CARRY_CONTRACT
index ...
1970-06-15 23:00:00 1.666 NaN ... 19701200 19700700
1970-06-16 23:00:00 1.679 NaN ... 19701200 19700700
1970-06-17 23:00:00 1.676 NaN ... 19701200 19700700
1970-06-18 23:00:00 1.682 NaN ... 19701200 19700700
1970-06-19 23:00:00 1.696 NaN ... 19701200 19700700
... ... ... ... ... ...
2022-09-09 14:30:00 18.575 NaN ... 20230100 20220900
2022-09-09 15:00:00 18.650 NaN ... 20230100 20220900
2022-09-09 16:00:00 18.700 NaN ... 20230100 20220900
2022-09-09 17:00:00 18.805 NaN ... 20230100 20220900
2022-09-09 18:00:00 18.760 NaN ... 20230100 20220900
[78767 rows x 6 columns]
index
1970-06-15 23:00:00 24.946998
1970-06-16 23:00:00 24.959998
1970-06-17 23:00:00 24.956998
1970-06-18 23:00:00 24.962998
1970-06-19 23:00:00 24.976998
...
2022-09-09 14:30:00 18.575000
2022-09-09 15:00:00 18.650000
2022-09-09 16:00:00 18.700000
2022-09-09 17:00:00 18.805000
2022-09-09 18:00:00 18.760000
Length: 78767, dtype: float64
Display diagnostic plots? Answer NO on headless serveryes
Press return to see plots
Happy to continue? Saying YES will overwrite existing data!
2022-09-14 15:08:40 {'type': '', 'component': 'mongoRollParametersData', 'instrument_code': 'SILVER'} Added roll parameters for instrument SILVER
Updated roll parameters in database. Use interactive controls to copy to .csv
2022-09-14 15:08:41 {'type': '', 'component': 'arcticFuturesMultiplePricesData', 'instrument_code': 'SILVER'} Wrote 78767 lines of prices for SILVER to Arctic connection: host 127.0.0.1, db production, collection futures_multiple_prices
2022-09-14 15:08:42 {'type': '', 'component': 'arcticFuturesMultiplePricesData', 'instrument_code': 'SILVER'} Added data for instrument SILVER
Updated multiple prices in database: copy backup files for .csv
2022-09-14 15:08:43 {'type': '', 'component': 'arcticFuturesAdjustedPricesData', 'instrument_code': 'SILVER'} Wrote 78767 lines of prices for SILVER to Arctic connection: host 127.0.0.1, db production, collection futures_adjusted_prices
2022-09-14 15:08:45 {'type': '', 'component': 'arcticFuturesAdjustedPricesData', 'instrument_code': 'SILVER'} Added data for instrument SILVER
Updated adjusted prices in database: copy backup files for .csv
All done!
'Use interactive controls to copy to .csv' -> this isn't implemented yet see #675
My gut feeling is some kind of 'make change to roll config' in interactive controls that would do the neccessary changes would be easier than lot's of defensive code that expected to see potential issues with roll configs the whole time. I feel like thoroughly testing this change would take less time than implementing that sort of behaviour.
Referencing: https://github.com/robcarver17/pysystemtrade/pull/672