Skip to content

Commit

Permalink
Chore: Make release 1.0.107
Browse files Browse the repository at this point in the history
  • Loading branch information
martinroberson committed Aug 6, 2024
1 parent 654f9c4 commit ac7fc09
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
15 changes: 14 additions & 1 deletion gs_quant/markets/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ def __init__(self,
self.__provider = provider
self.__max_per_batch = None
self.__max_concurrent = None
self.__dates_per_batch = None
self.__use_historical_diddles_only = use_historical_diddles_only
self.__set_parameters_only = set_parameters_only

Expand All @@ -216,6 +217,7 @@ def __save_attrs_to(self, attr_dict):
attr_dict['provider'] = self.__provider
attr_dict['_max_concurrent'] = self.__max_concurrent
attr_dict['_max_per_batch'] = self.__max_per_batch
attr_dict['_dates_per_batch'] = self.__dates_per_batch
attr_dict['use_historical_diddles_only'] = self.__use_historical_diddles_only

def _inherited_val(self, parameter, default=None, from_active=False):
Expand Down Expand Up @@ -255,6 +257,7 @@ def _on_enter(self):
self.__provider = self.provider
self.__max_concurrent = self._max_concurrent
self.__max_per_batch = self._max_per_batch
self.__dates_per_batch = self._dates_per_batch
self.__use_historical_diddles_only = self.use_historical_diddles_only

def __reset_atts(self):
Expand All @@ -274,6 +277,7 @@ def __reset_atts(self):
self.__provider = self.__attrs_on_entry.get('provider')
self.__max_concurrent = self.__attrs_on_entry.get('_max_concurrent')
self.__max_per_batch = self.__attrs_on_entry.get('_max_per_batch')
self.__dates_per_batch = self.__attrs_on_entry.get('_dates_per_batch')

self.__attrs_on_entry = {}

Expand Down Expand Up @@ -324,7 +328,8 @@ def run_requests(requests_: list, provider_, create_event_loop: bool, pc_attrs:
# Restrict to 1,000 instruments and 1 date in a batch, until server side changes are made

for (params, scenario, dates_markets, risk_measures), instruments in grouped_requests.items():
date_chunk_size = (1 if self._group_by_date else self._max_per_batch) if provider.batch_dates \
date_chunk_size = (self._dates_per_batch if self._group_by_date
else self._max_per_batch) if provider.batch_dates \
else len(dates_markets)
for insts_chunk in [tuple(filter(None, i)) for i in
zip_longest(*[iter(instruments)] * self._max_per_batch)]:
Expand Down Expand Up @@ -419,6 +424,14 @@ def _max_per_batch(self) -> int:
def _max_per_batch(self, value):
self.__max_per_batch = value

@property
def _dates_per_batch(self) -> int:
return self.__dates_per_batch if self.__dates_per_batch else self._inherited_val('_dates_per_batch', default=1)

@_dates_per_batch.setter
def _dates_per_batch(self, value):
self.__dates_per_batch = value

@property
def is_async(self) -> bool:
if self.__is_async is not None:
Expand Down
23 changes: 23 additions & 0 deletions gs_quant/test/markets/test_pricing_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def test_creation():
assert c1.use_cache is False
assert c1._max_concurrent == 1000
assert c1.provider is None
assert c1._dates_per_batch == 1

assert c1.pricing_date == datetime.date(2022, 6, 15)

Expand All @@ -171,6 +172,7 @@ def test_inheritance():
assert c2.use_cache is False
assert c2._max_concurrent == 1000
assert not c2.use_historical_diddles_only
assert c2._dates_per_batch == 1
with c3:
# market data location is inherited from c1 (the active context)
assert c3.market_data_location == c1.market_data_location
Expand All @@ -181,6 +183,7 @@ def test_inheritance():
assert c3.use_cache is False
assert c3._max_concurrent == 1000
assert c3.use_historical_diddles_only
assert c3._dates_per_batch == 1


def test_max_concurrent():
Expand All @@ -203,6 +206,26 @@ def test_max_concurrent():
assert PricingContext.current._max_concurrent == 3000 # should be same as above property accessor


def test_dates_per_batch():
a = PricingContext()
assert a._dates_per_batch == 1

b = PricingContext()
b._dates_per_batch = 2

c = PricingContext()
c._dates_per_batch = 3

assert b._dates_per_batch == 2
with b:
assert a._dates_per_batch == 2
assert c._dates_per_batch == 3
with a:
assert PricingContext.current._dates_per_batch == 2
with c:
assert PricingContext.current._dates_per_batch == 3


def test_current_inheritance():
cur = PricingContext.current
assert cur.market_data_location == PricingLocation.LDN
Expand Down

0 comments on commit ac7fc09

Please sign in to comment.