Skip to content

Commit 9f482a3

Browse files
author
rob
committed
1 parent 8b247b0 commit 9f482a3

13 files changed

+157
-371
lines changed
+54-43
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,63 @@
11
DATE_TIME,current_contract,next_contract,carry_contract
2-
2008-06-04 23:00:00,20080600,20080900,20080900
3-
2008-09-04 23:00:00,20080900,20081200,20081200
4-
2008-12-04 23:00:00,20081200,20090300,20090300
5-
2009-03-04 23:00:00,20090300,20090600,20090600
6-
2009-06-04 23:00:00,20090600,20090900,20090900
2+
2007-12-05 23:00:00,20071200,20080300,20080300
3+
2008-03-05 23:00:00,20080300,20080600,20080600
4+
2008-06-05 23:00:00,20080600,20080900,20080900
5+
2008-09-05 23:00:00,20080900,20081200,20081200
6+
2008-12-05 23:00:00,20081200,20090300,20090300
7+
2009-03-05 23:00:00,20090300,20090600,20090600
8+
2009-06-05 23:00:00,20090600,20090900,20090900
79
2009-09-04 23:00:00,20090900,20091200,20091200
810
2009-12-04 23:00:00,20091200,20100300,20100300
9-
2010-03-04 23:00:00,20100300,20100600,20100600
11+
2010-03-05 23:00:00,20100300,20100600,20100600
1012
2010-06-04 23:00:00,20100600,20100900,20100900
1113
2010-09-06 23:00:00,20100900,20101200,20101200
1214
2010-12-06 23:00:00,20101200,20110300,20110300
1315
2011-03-04 23:00:00,20110300,20110600,20110600
1416
2011-06-06 23:00:00,20110600,20110900,20110900
15-
2011-09-06 23:00:00,20110900,20111200,20111200
16-
2011-12-06 23:00:00,20111200,20120300,20120300
17-
2012-03-06 23:00:00,20120300,20120600,20120600
17+
2011-09-05 23:00:00,20110900,20111200,20111200
18+
2011-12-05 23:00:00,20111200,20120300,20120300
19+
2012-03-05 23:00:00,20120300,20120600,20120600
1820
2012-06-05 23:00:00,20120600,20120900,20120900
19-
2012-09-06 07:00:00,20120900,20121200,20121200
20-
2012-12-03 07:30:00,20121200,20130300,20130300
21-
2013-03-01 07:30:00,20130300,20130600,20130600
22-
2013-06-03 07:30:00,20130600,20130900,20130900
23-
2013-09-06 23:00:00,20130900,20131200,20131200
24-
2013-12-04 09:00:17,20131200,20140300,20140300
25-
2014-03-05 07:32:13,20140300,20140600,20140600
26-
2014-06-04 07:41:53,20140600,20140900,20140900
27-
2014-09-04 23:00:00,20140900,20141200,20141200
28-
2014-12-04 23:00:00,20141200,20150300,20150300
29-
2015-03-04 07:37:57,20150300,20150600,20150600
30-
2015-06-04 07:31:10,20150600,20150900,20150900
31-
2015-09-04 07:00:00,20150900,20151200,20151200
32-
2015-12-02 07:30:00,20151200,20160300,20160300
33-
2016-03-02 07:30:00,20160300,20160600,20160600
34-
2016-06-02 07:30:00,20160600,20160900,20160900
35-
2016-09-02 07:30:00,20160900,20161200,20161200
36-
2016-12-02 07:30:00,20161200,20170300,20170300
37-
2017-03-02 07:30:00,20170300,20170600,20170600
38-
2017-06-02 07:30:00,20170600,20170900,20170900
39-
2017-09-01 07:30:00,20170900,20171200,20171200
40-
2017-12-01 07:30:00,20171200,20180300,20180300
41-
2018-03-02 07:30:00,20180300,20180600,20180600
42-
2018-06-01 07:30:00,20180600,20180900,20180900
43-
2018-09-03 07:30:00,20180900,20181200,20181200
44-
2018-12-03 07:30:00,20181200,20190300,20190300
45-
2019-03-01 04:15:00,20190300,20190600,20190600
46-
2019-06-03 01:45:00,20190600,20190900,20190900
47-
2019-09-02 02:45:00,20190900,20191200,20191200
48-
2019-12-02 01:00:00,20191200,20200300,20200300
49-
2020-03-02 00:45:00,20200300,20200600,20200600
50-
2020-05-29 02:00:00,20200600,20200900,20200900
51-
2020-09-01 02:00:00,20200900,20201200,20201200
52-
2020-11-24 09:00:00,20201200,20210300,20210300
21+
2012-09-05 23:00:00,20120900,20121200,20121200
22+
2012-12-05 07:00:00,20121200,20130300,20130300
23+
2013-03-05 07:00:00,20130300,20130600,20130600
24+
2013-06-05 07:00:00,20130600,20130900,20130900
25+
2013-09-05 23:00:00,20130900,20131200,20131200
26+
2013-12-05 23:00:00,20131200,20140300,20140300
27+
2014-03-04 23:00:00,20140300,20140600,20140600
28+
2014-06-05 23:00:00,20140600,20140900,20140900
29+
2014-09-05 23:00:00,20140900,20141200,20141200
30+
2014-12-05 23:00:00,20141200,20150300,20150300
31+
2015-03-05 23:00:00,20150300,20150600,20150600
32+
2015-06-05 23:00:00,20150600,20150900,20150900
33+
2015-09-04 23:00:00,20150900,20151200,20151200
34+
2015-12-04 07:00:00,20151200,20160300,20160300
35+
2016-03-04 07:00:00,20160300,20160600,20160600
36+
2016-06-06 07:00:00,20160600,20160900,20160900
37+
2016-09-05 07:00:00,20160900,20161200,20161200
38+
2016-12-05 07:00:00,20161200,20170300,20170300
39+
2017-03-06 07:00:00,20170300,20170600,20170600
40+
2017-06-05 07:00:00,20170600,20170900,20170900
41+
2017-09-05 07:00:00,20170900,20171200,20171200
42+
2017-12-05 07:00:00,20171200,20180300,20180300
43+
2018-03-05 07:00:00,20180300,20180600,20180600
44+
2018-06-05 07:00:00,20180600,20180900,20180900
45+
2018-09-05 07:00:00,20180900,20181200,20181200
46+
2018-12-05 07:00:00,20181200,20190300,20190300
47+
2019-03-05 00:15:00,20190300,20190600,20190600
48+
2019-06-05 01:15:00,20190600,20190900,20190900
49+
2019-09-05 01:15:00,20190900,20191200,20191200
50+
2019-12-05 00:30:00,20191200,20200300,20200300
51+
2020-03-05 00:15:00,20200300,20200600,20200600
52+
2020-06-05 01:15:00,20200600,20200900,20200900
53+
2020-09-04 01:15:00,20200900,20201200,20201200
54+
2020-11-30 01:00:00,20201200,20210300,20210300
55+
2021-03-05 00:15:00,20210300,20210600,20210600
56+
2021-06-04 02:15:00,20210600,20210900,20210900
57+
2021-09-06 01:15:00,20210900,20211200,20211200
58+
2021-12-06 00:15:00,20211200,20220300,20220300
59+
2022-03-04 00:15:00,20220300,20220600,20220600
60+
2022-06-06 02:00:00,20220600,20220900,20220900
61+
2022-09-05 01:15:00,20220900,20221200,20221200
62+
2022-12-05 00:15:00,20221200,20230300,20230300
63+
2022-12-29 23:00:00,20230300,20230600,20230600

sysdata/csv/csv_roll_parameters.py

+70-46
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,53 @@
1010
ROLLS_CONFIG_FILE = "rollconfig.csv"
1111

1212

13+
class allRollParameters(pd.DataFrame):
14+
@classmethod
15+
def read_from_file(allRollParameters, filename):
16+
try:
17+
roll_data = pd.read_csv(filename)
18+
except BaseException:
19+
raise Exception("Can't read file %s" % filename)
20+
21+
try:
22+
roll_data.index = roll_data.Instrument
23+
roll_data.drop(labels="Instrument", axis=1, inplace=True)
24+
25+
except BaseException:
26+
raise Exception("Badly configured file %s" % (filename))
27+
28+
return allRollParameters(roll_data)
29+
30+
def get_list_of_instruments(self) -> list:
31+
return list(self.index)
32+
33+
def get_roll_parameters_for_instrument(
34+
self, instrument_code: str
35+
) -> rollParameters:
36+
config_for_this_instrument = self.loc[instrument_code]
37+
roll_parameters_object = rollParameters(
38+
hold_rollcycle=config_for_this_instrument.HoldRollCycle,
39+
roll_offset_day=config_for_this_instrument.RollOffsetDays,
40+
carry_offset=config_for_this_instrument.CarryOffset,
41+
priced_rollcycle=config_for_this_instrument.PricedRollCycle,
42+
approx_expiry_offset=config_for_this_instrument.ExpiryOffset,
43+
)
44+
45+
return roll_parameters_object
46+
47+
def update_roll_parameters_for_instrument(
48+
self, instrument_code: str, roll_parameters: rollParameters
49+
):
50+
self.at[instrument_code, "HoldRollCycle"] = roll_parameters.hold_rollcycle
51+
self.at[instrument_code, "RollOffsetDays"] = rollParameters.roll_offset_day
52+
self.at[instrument_code, "CarryOffset"] = roll_parameters.carry_offset
53+
self.at[instrument_code, "PricedRollCycle"] = roll_parameters.priced_rollcycle
54+
self.at[instrument_code, "ExpiryOffset"] = roll_parameters.approx_expiry_offset
55+
56+
def write_to_file(self, filename: str):
57+
self.to_csv(filename, index_label="Instrument")
58+
59+
1360
class csvRollParametersData(rollParametersData):
1461
"""
1562
Get data about instruments from a special configuration used for initialising the system
@@ -27,50 +74,19 @@ def __init__(
2774

2875
self._config_file = config_file
2976

30-
def _get_config_information(self):
31-
"""
32-
Get configuration information
33-
34-
:return: dict of config information
35-
"""
36-
37-
try:
38-
config_data = pd.read_csv(self._config_file)
39-
except BaseException:
40-
raise Exception("Can't read file %s" % self._config_file)
41-
42-
try:
43-
config_data.index = config_data.Instrument
44-
config_data.drop(labels="Instrument", axis=1, inplace=True)
45-
46-
except BaseException:
47-
raise Exception("Badly configured file %s" % (self._config_file))
48-
49-
return config_data
50-
51-
@property
52-
def config_file(self):
53-
return self._config_file
54-
5577
def __repr__(self):
5678
return "Roll data for initialising system config"
5779

5880
def get_list_of_instruments(self) -> list:
59-
return list(self._get_config_information().index)
81+
all_roll_parameters = self.get_roll_parameters_all_instruments()
82+
return all_roll_parameters.get_list_of_instruments()
6083

6184
def _get_roll_parameters_without_checking(
6285
self, instrument_code: str
6386
) -> rollParameters:
64-
config_for_this_instrument = self._get_config_information().loc[instrument_code]
65-
roll_parameters_object = rollParameters(
66-
hold_rollcycle=config_for_this_instrument.HoldRollCycle,
67-
roll_offset_day=config_for_this_instrument.RollOffsetDays,
68-
carry_offset=config_for_this_instrument.CarryOffset,
69-
priced_rollcycle=config_for_this_instrument.PricedRollCycle,
70-
approx_expiry_offset=config_for_this_instrument.ExpiryOffset,
71-
)
7287

73-
return roll_parameters_object
88+
all_parameters = self.get_roll_parameters_all_instruments()
89+
return all_parameters.get_roll_parameters_for_instrument(instrument_code)
7490

7591
def _delete_roll_parameters_data_without_any_warning_be_careful(
7692
self, instrument_code: str
@@ -80,17 +96,25 @@ def _delete_roll_parameters_data_without_any_warning_be_careful(
8096
def _add_roll_parameters_without_checking_for_existing_entry(
8197
self, instrument_code: str, roll_parameters: rollParameters
8298
):
83-
raise NotImplementedError("csv is read only")
99+
## We don't normally allow this, but a special case as we safe modify
100+
all_parameters = self.get_roll_parameters_all_instruments()
101+
all_parameters.update_roll_parameters_for_instrument(
102+
instrument_code, roll_parameters
103+
)
104+
all_parameters.write_to_file(self.config_file)
84105

85-
def write_all_roll_parameters_data(self, roll_parameters_df: pd.DataFrame):
86-
roll_parameters_df_to_write = pd.DataFrame(
87-
dict(
88-
HoldRollCycle=roll_parameters_df.hold_rollcycle,
89-
RollOffsetDays=roll_parameters_df.roll_offset_day,
90-
CarryOffset=roll_parameters_df.carry_offset,
91-
PricedRollCycle=roll_parameters_df.priced_rollcycle,
92-
ExpiryOffset=roll_parameters_df.approx_expiry_offset,
93-
)
106+
self.log.warn(
107+
"*** WRITTEN NEW ROLL PARAMETERS TO %s - copy to /data/futures/csvconfig/rollconfig.csv NOW ***"
108+
% self.config_file
94109
)
95110

96-
roll_parameters_df_to_write.to_csv(self._config_file, index_label="Instrument")
111+
def write_all_roll_parameters_data(self, roll_parameters_df: pd.DataFrame):
112+
all_roll_parameters = allRollParameters(roll_parameters_df)
113+
all_roll_parameters.write_to_file(self.config_file)
114+
115+
def get_roll_parameters_all_instruments(self) -> allRollParameters:
116+
return allRollParameters.read_from_file(self.config_file)
117+
118+
@property
119+
def config_file(self):
120+
return self._config_file

sysdata/mongodb/mongo_roll_data.py

-66
This file was deleted.

sysdata/sim/db_futures_sim_data.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from sysdata.arctic.arctic_multiple_prices import arcticFuturesMultiplePricesData
1010
from sysdata.arctic.arctic_spotfx_prices import arcticFxPricesData
1111
from sysdata.csv.csv_instrument_data import csvFuturesInstrumentData
12-
from sysdata.mongodb.mongo_roll_data import mongoRollParametersData
12+
from sysdata.csv.csv_roll_parameters import csvRollParametersData
1313
from sysdata.mongodb.mongo_spread_costs import mongoSpreadCostData
1414
from sysdata.data_blob import dataBlob
1515
from sysdata.sim.futures_sim_data_with_data_blob import genericBlobUsingFuturesSimData
@@ -30,7 +30,7 @@ def __init__(
3030
arcticFuturesMultiplePricesData,
3131
arcticFxPricesData,
3232
csvFuturesInstrumentData,
33-
mongoRollParametersData,
33+
csvRollParametersData,
3434
mongoSpreadCostData,
3535
],
3636
)

sysinit/futures/multipleprices_from_arcticprices_and_csv_calendars_to_arctic.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424

2525
from sysdata.csv.csv_roll_calendars import csvRollCalendarData
2626
from sysdata.csv.csv_multiple_prices import csvFuturesMultiplePricesData
27+
from sysdata.csv.csv_roll_parameters import csvRollParametersData
2728
from sysdata.arctic.arctic_multiple_prices import arcticFuturesMultiplePricesData
2829
from sysdata.arctic.arctic_futures_per_contract_prices import (
2930
arcticFuturesContractPriceData,
3031
)
3132
from sysinit.futures.build_roll_calendars import adjust_to_price_series
3233
from sysobjects.multiple_prices import futuresMultiplePrices
33-
from sysdata.mongodb.mongo_roll_data import mongoRollParametersData
3434

3535

3636
def _get_data_inputs(csv_roll_data_path, csv_multiple_data_path):
@@ -110,7 +110,7 @@ def process_multiple_prices_single_instrument(
110110

111111
# Add first phantom row so that the last calendar entry won't be consumed by adjust_roll_calendar()
112112
if roll_parameters is arg_not_supplied:
113-
m = mongoRollParametersData()
113+
m = csvRollParametersData()
114114
roll_parameters = m.get_roll_parameters(instrument_code)
115115

116116
roll_calendar = add_phantom_row(

0 commit comments

Comments
 (0)