Skip to content

Commit

Permalink
Chore: Make release 1.1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
martinroberson committed Sep 3, 2024
1 parent 4880552 commit 89a85df
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 17 deletions.
8 changes: 6 additions & 2 deletions gs_quant/api/gs/backtests_xasset/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,19 @@


class GsBacktestXassetApi:
HEADERS = {'Accept': 'application/json'}

@classmethod
def calculate_risk(cls, risk_request: RiskRequest) -> RiskResponse:
response = GsSession.current._post('/backtests/xasset/risk', risk_request.to_json())
response = GsSession.current._post('/backtests/xasset/risk', risk_request.to_json(),
request_headers=cls.HEADERS)
result = RiskResponse.from_dict(response)
return result

@classmethod
def calculate_basic_backtest(cls, backtest_request: BasicBacktestRequest, decode_instruments: bool = True) -> \
BasicBacktestResponse:
response = GsSession.current._post('/backtests/xasset/strategy/basic', backtest_request.to_json())
response = GsSession.current._post('/backtests/xasset/strategy/basic', backtest_request.to_json(),
request_headers=cls.HEADERS)
result = BasicBacktestResponse.from_dict_custom(response, decode_instruments)
return result
10 changes: 10 additions & 0 deletions gs_quant/backtests/equity_vol_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,16 @@ def check_strategy(cls, strategy):
check_results.append(
f'Error: {type(action).__name__} invalid expiration_date '
'modifier ' + expiry_date_modes[0])

size_fields = ('quantity', 'number_of_options', 'multiplier')
priceable_size_values = [[getattr(p, sf, 1) or 1 for sf in size_fields] for p in action.priceables]
priceable_sizes = [reduce(lambda x, y: x * y, size_vals, 1) for size_vals in priceable_size_values]

if not all(priceable_size == 1 for priceable_size in priceable_sizes):
check_results.append(
f'Error: {type(action).__name__} every priceable should have a unit size of 1. '
'Found [' + ', '.join([str(s) for s in priceable_sizes]) + ']'
)
elif isinstance(action, a.HedgeAction):
if not is_synthetic_forward(action.priceable):
check_results.append(
Expand Down
1 change: 1 addition & 0 deletions gs_quant/backtests/strategy_systematic.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def __init__(self,
if not isinstance(instrument, self._supported_instruments):
raise MqValueError('The format of the backtest asset is incorrect.')
elif isinstance(instrument, self._supported_fx_instruments):
instrument = instrument.clone()
instrument.notional_amount *= notional_percentage / 100

instrument = self.check_underlier_fields(instrument)
Expand Down
2 changes: 1 addition & 1 deletion gs_quant/datetime/gscalendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def holidays_from_dataset(self, dataset: Dataset, query_key: str, query_values:
return []

@property
def holidays(self) -> Tuple[dt.date]:
def holidays(self) -> Tuple[dt.date, ...]:
cached_data = _calendar_cache.get(hashkey(str(self.__calendars)))
if cached_data:
return cached_data
Expand Down
2 changes: 1 addition & 1 deletion gs_quant/risk/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ def aggregate_results(results: Iterable[ResultType], allow_mismatch_risk_keys=Fa

if result.unit:
if unit and unit != result.unit:
raise ValueError('Cannot aggregate results with different units')
raise ValueError(f'Cannot aggregate results with different units for {result.risk_key.risk_measure}')

unit = unit or result.unit

Expand Down
24 changes: 24 additions & 0 deletions gs_quant/test/backtest/test_backtest_eq_vol_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,3 +816,27 @@ def test_supports_strategy():
actions=add_trade_action_tc0)
strategy = Strategy(initial_portfolio=None, triggers=[trigger])
assert EquityVolEngine.supports_strategy(strategy)

# 18. Invalid - instrument non unit contract size

option_with_mult = EqOption('.STOXX50E', expiration_date='3m', strike_price='ATM', option_type=OptionType.Call,
option_style=OptionStyle.European, multiplier=100)

action = AddTradeAction(priceables=option_with_mult, trade_duration='1m')
trigger = PeriodicTrigger(
trigger_requirements=PeriodicTriggerRequirements(start_date=start_date, end_date=end_date, frequency='1m'),
actions=action)
strategy = Strategy(initial_portfolio=None, triggers=[trigger])
assert not EquityVolEngine.supports_strategy(strategy)

# 19. Invalid - instrument non unit contract count

option_with_contracts = EqOption('.STOXX50E', expiration_date='3m', strike_price='ATM', option_type=OptionType.Call,
option_style=OptionStyle.European, number_of_options=100)

action = AddTradeAction(priceables=option_with_contracts, trade_duration='1m')
trigger = PeriodicTrigger(
trigger_requirements=PeriodicTriggerRequirements(start_date=start_date, end_date=end_date, frequency='1m'),
actions=action)
strategy = Strategy(initial_portfolio=None, triggers=[trigger])
assert not EquityVolEngine.supports_strategy(strategy)
25 changes: 12 additions & 13 deletions gs_quant/test/datetime_/test_gscalendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,35 @@
under the License.
"""

from gs_quant.datetime import GsCalendar
import datetime as dt
from unittest import mock

import pandas as pd

from gs_quant.common import PricingLocation
from gs_quant.test.api.test_risk import set_session
from gs_quant.data import Dataset
from gs_quant.datetime import GsCalendar
from gs_quant.test.api.test_risk import set_session

from unittest import mock
import pandas as pd
import datetime
MOCK_HOLIDAY = pd.DataFrame(index=[dt.datetime(1999, 9, 12)], data={'holiday': 'Labor Day'})


# Test GsCalendar initiated with single PricingLocation
@mock.patch.object(Dataset, 'get_coverage', return_value=pd.DataFrame())
@mock.patch.object(Dataset, 'get_data')
def test_gs_calendar_single(mocker, mocker_cov):
@mock.patch.object(Dataset, 'get_data', return_value=MOCK_HOLIDAY)
def test_gs_calendar_single(mocker, _mocker_cov):
set_session()
mocker.return_value = pd.DataFrame(index=[datetime.datetime(1999, 9, 12)],
data={'holiday': 'Labor Day'})
nyc = PricingLocation.NYC
GsCalendar.reset()
days = GsCalendar(nyc).holidays
assert days


# Test GsCalendar initiated with tuple
@mock.patch.object(Dataset, 'get_data')
@mock.patch.object(Dataset, 'get_coverage', return_value=pd.DataFrame())
def test_gs_calendar_tuple(mocker_coverage, mocker):
@mock.patch.object(Dataset, 'get_data', return_value=MOCK_HOLIDAY)
def test_gs_calendar_tuple(mocker, _mocker_cov):
set_session()
mocker.return_value = pd.DataFrame(index=[datetime.datetime(1999, 9, 12)],
data={'holiday': 'Labor Day'})
locs = (PricingLocation.NYC, PricingLocation.LDN)
days = GsCalendar(locs).holidays
assert days

0 comments on commit 89a85df

Please sign in to comment.