-
Notifications
You must be signed in to change notification settings - Fork 834
/
futures_sim_data_with_data_blob.py
131 lines (100 loc) · 4.38 KB
/
futures_sim_data_with_data_blob.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
from sysdata.sim.futures_sim_data import futuresSimData
from sysdata.futures.adjusted_prices import futuresAdjustedPricesData
from sysdata.fx.spotfx import fxPricesData
from sysdata.futures.instruments import futuresInstrumentData
from sysdata.futures.multiple_prices import futuresMultiplePricesData
from sysdata.futures.rolls_parameters import rollParametersData
from sysdata.futures.spread_costs import spreadCostData
from sysdata.data_blob import dataBlob
from sysobjects.instruments import (
assetClassesAndInstruments,
futuresInstrumentWithMetaData,
)
from syscore.exceptions import missingData
from sysobjects.spot_fx_prices import fxPrices
from sysobjects.adjusted_prices import futuresAdjustedPrices
from sysobjects.multiple_prices import futuresMultiplePrices
from sysobjects.rolls import rollParameters
class genericBlobUsingFuturesSimData(futuresSimData):
"""
dataBlob must have the appropriate classes added or it won't work
"""
def __init__(self, data: dataBlob):
super().__init__(log=data.log)
self._data = data
def get_instrument_list(self):
return self.db_futures_adjusted_prices_data.get_list_of_instruments()
def _get_fx_data_from_start_date(
self, currency1: str, currency2: str, start_date
) -> fxPrices:
fx_code = currency1 + currency2
data = self.db_fx_prices_data.get_fx_prices(fx_code)
data_after_start = data[start_date:]
return data_after_start
def get_instrument_asset_classes(self) -> assetClassesAndInstruments:
all_instrument_data = self.get_all_instrument_data_as_df()
asset_classes = all_instrument_data["AssetClass"]
asset_class_data = assetClassesAndInstruments.from_pd_series(asset_classes)
return asset_class_data
def get_all_instrument_data_as_df(self):
all_instrument_data = (
self.db_futures_instrument_data.get_all_instrument_data_as_df()
)
instrument_list = self.get_instrument_list()
all_instrument_data = all_instrument_data[
all_instrument_data.index.isin(instrument_list)
]
return all_instrument_data
def get_backadjusted_futures_price(
self, instrument_code: str
) -> futuresAdjustedPrices:
data = self.db_futures_adjusted_prices_data.get_adjusted_prices(instrument_code)
return data
def get_multiple_prices_from_start_date(
self, instrument_code: str, start_date
) -> futuresMultiplePrices:
data = self.db_futures_multiple_prices_data.get_multiple_prices(instrument_code)
if len(data) == 0:
raise missingData(
"Data for %s not found! Remove from instrument list, or add to config.ignore_instruments"
% instrument_code
)
return data[start_date:]
def get_instrument_meta_data(
self, instrument_code: str
) -> futuresInstrumentWithMetaData:
## cost and other meta data stored in the same place
return self.get_instrument_object_with_meta_data(instrument_code)
def get_instrument_object_with_meta_data(
self, instrument_code: str
) -> futuresInstrumentWithMetaData:
instrument = self.db_futures_instrument_data.get_instrument_data(
instrument_code
)
return instrument
def get_roll_parameters(self, instrument_code: str) -> rollParameters:
roll_parameters = self.db_roll_parameters.get_roll_parameters(instrument_code)
return roll_parameters
def get_spread_cost(self, instrument_code: str) -> float:
return self.db_spread_cost_data.get_spread_cost(instrument_code)
@property
def data(self):
return self._data
@property
def db_fx_prices_data(self) -> fxPricesData:
return self.data.db_fx_prices
@property
def db_futures_adjusted_prices_data(self) -> futuresAdjustedPricesData:
return self.data.db_futures_adjusted_prices
@property
def db_futures_instrument_data(self) -> futuresInstrumentData:
return self.data.db_futures_instrument
@property
def db_futures_multiple_prices_data(self) -> futuresMultiplePricesData:
return self.data.db_futures_multiple_prices
@property
def db_roll_parameters(self) -> rollParametersData:
return self.data.db_roll_parameters
@property
def db_spread_cost_data(self) -> spreadCostData:
return self.data.db_spread_cost