forked from robcarver17/pysystemtrade
-
Notifications
You must be signed in to change notification settings - Fork 1
/
adjustedprices_from_mongo_multiple_to_mongo.py
executable file
·71 lines (57 loc) · 2.47 KB
/
adjustedprices_from_mongo_multiple_to_mongo.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
"""
We create adjusted prices using multiple prices stored in arctic
We then store those adjusted prices in arctic and/or csv
"""
from syscore.objects import arg_not_supplied
from sysdata.arctic.arctic_multiple_prices import arcticFuturesMultiplePricesData
from sysdata.arctic.arctic_adjusted_prices import arcticFuturesAdjustedPricesData
from sysdata.csv.csv_adjusted_prices import csvFuturesAdjustedPricesData
from sysobjects.adjusted_prices import futuresAdjustedPrices
def _get_data_inputs(csv_adj_data_path):
arctic_multiple_prices = arcticFuturesMultiplePricesData()
arctic_adjusted_prices = arcticFuturesAdjustedPricesData()
csv_adjusted_prices = csvFuturesAdjustedPricesData(csv_adj_data_path)
return arctic_multiple_prices, arctic_adjusted_prices, csv_adjusted_prices
def process_adjusted_prices_all_instruments(
csv_adj_data_path=arg_not_supplied, ADD_TO_ARCTIC=True, ADD_TO_CSV=False
):
arctic_multiple_prices, _notused, _alsonotused = _get_data_inputs(
csv_adj_data_path)
instrument_list = arctic_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_ARCTIC=ADD_TO_ARCTIC,
ADD_TO_CSV=ADD_TO_CSV,
)
def process_adjusted_prices_single_instrument(
instrument_code,
csv_adj_data_path=arg_not_supplied,
ADD_TO_ARCTIC=True,
ADD_TO_CSV=False):
(
arctic_multiple_prices,
arctic_adjusted_prices,
csv_adjusted_prices,
) = _get_data_inputs(csv_adj_data_path)
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_ARCTIC:
arctic_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(ADD_TO_ARCTIC=True, ADD_TO_CSV=True, csv_adj_data_path=arg_not_supplied)