forked from robcarver17/pysystemtrade
-
Notifications
You must be signed in to change notification settings - Fork 0
/
adjustedprices_from_db_multiple_to_db.py
executable file
·77 lines (60 loc) · 2.44 KB
/
adjustedprices_from_db_multiple_to_db.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
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
"""
We create adjusted prices using multiple prices stored in database
We then store those adjusted prices in database and/or csv
"""
from syscore.constants import arg_not_supplied
from sysdata.csv.csv_adjusted_prices import csvFuturesAdjustedPricesData
from sysobjects.adjusted_prices import futuresAdjustedPrices
from sysproduction.data.prices import diagPrices
diag_prices = diagPrices()
def _get_data_inputs(csv_adj_data_path):
db_multiple_prices = diag_prices.db_futures_multiple_prices_data
db_adjusted_prices = diag_prices.db_futures_adjusted_prices_data
csv_adjusted_prices = csvFuturesAdjustedPricesData(csv_adj_data_path)
return db_multiple_prices, db_adjusted_prices, csv_adjusted_prices
def process_adjusted_prices_all_instruments(
csv_adj_data_path=arg_not_supplied, ADD_TO_DB=True, ADD_TO_CSV=False
):
db_multiple_prices, _notused, _alsonotused = _get_data_inputs(csv_adj_data_path)
instrument_list = db_multiple_prices.get_list_of_instruments()
for instrument_code in instrument_list:
print(instrument_code)
process_adjusted_prices_single_instrument(
instrument_code,
csv_adj_data_path=csv_adj_data_path,
ADD_TO_DB=ADD_TO_DB,
ADD_TO_CSV=ADD_TO_CSV,
)
def process_adjusted_prices_single_instrument(
instrument_code,
csv_adj_data_path=arg_not_supplied,
multiple_prices=arg_not_supplied,
ADD_TO_DB=True,
ADD_TO_CSV=False,
):
(
arctic_multiple_prices,
parquet_adjusted_prices,
csv_adjusted_prices,
) = _get_data_inputs(csv_adj_data_path)
if multiple_prices is arg_not_supplied:
multiple_prices = arctic_multiple_prices.get_multiple_prices(instrument_code)
adjusted_prices = futuresAdjustedPrices.stitch_multiple_prices(
multiple_prices, forward_fill=True
)
print(adjusted_prices)
if ADD_TO_DB:
parquet_adjusted_prices.add_adjusted_prices(
instrument_code, adjusted_prices, ignore_duplication=True
)
if ADD_TO_CSV:
csv_adjusted_prices.add_adjusted_prices(
instrument_code, adjusted_prices, ignore_duplication=True
)
return adjusted_prices
if __name__ == "__main__":
input("Will overwrite existing prices are you sure?! CTL-C to abort")
# modify flags and datapath as required
process_adjusted_prices_all_instruments(
csv_adj_data_path=arg_not_supplied, ADD_TO_DB=True, ADD_TO_CSV=True
)