def test_custom_aum(): data = { 'aum': [ 101, 102, 103 ], 'date': [ '2020-01-01', '2020-01-02', '2020-01-03' ] } idx = pd.date_range('2020-01-01', freq='D', periods=3) df = MarketDataResponseFrame(data=data, index=idx) df.dataset_ids = ('AUM',) replace = Replacer() # mock GsPortfolioApi.get_reports() mock = replace('gs_quant.api.gs.portfolios.GsPortfolioApi.get_custom_aum', Mock()) mock.return_value = df with DataContext(datetime.date(2020, 1, 1), datetime.date(2019, 1, 3)): actual = mp.aum('MP1') assert actual.index.equals(idx) assert all(actual.values == data['aum']) replace.restore()
def test_fci(): with pytest.raises(NotImplementedError): mc.fci('IN', real_time=True) data = { 'fci': [101, 102, 103], 'realFCI': [100, 99, 98], 'realTWIContribution': [100, 100, 98] } idx = pd.date_range('2020-01-01', freq='D', periods=3) df = MarketDataResponseFrame(data=data, index=idx) df.dataset_ids = ('FCI', ) replace = Replacer() mock = replace('gs_quant.timeseries.measures.GsDataApi.get_market_data', Mock()) mock.return_value = df with DataContext(datetime.date(2020, 1, 1), datetime.date(2019, 1, 3)): actual = mc.fci('IN') assert actual.index.equals(idx) assert all(actual.values == data['fci']) mock = replace('gs_quant.timeseries.measures.Dataset.get_data', Mock()) mock.return_value = df with DataContext(datetime.date(2020, 1, 1), datetime.date(2019, 1, 3)): actual = mc.fci('IN', mc._FCI_MEASURE.REAL_FCI) assert actual.index.equals(idx) assert all(actual.values == data['realFCI']) with DataContext(datetime.date(2020, 1, 1), datetime.date(2019, 1, 3)): actual = mc.fci('IN', mc._FCI_MEASURE.REAL_TWI_CONTRIBUTION) assert actual.index.equals(idx) assert all(actual.values == data['realTWIContribution']) replace.restore()
def mock_curr(_cls, _q): d = { 'swapRate': [1, 2, 3], } df = MarketDataResponseFrame(data=d, index=_index * 3) df.dataset_ids = _test_datasets return df
def mock_curr(_cls, _q): d = { 'impliedVolatility': [1, 2, 3], } df = MarketDataResponseFrame(data=d, index=_index * 3) df.dataset_ids = _test_datasets return df
def mock_df(): d = { 'strikeVol': [5, 1, 2], } df = MarketDataResponseFrame(data=d, index=_index * 3) df.dataset_ids = "FX_VOLATILITY_SWAP" return df
def test_financial_conditions_index(): data = { 'pnl': [ 101, 102, 103 ], 'date': [ '2020-01-01', '2020-01-02', '2020-01-03' ] } idx = pd.date_range('2020-01-01', freq='D', periods=3) df = MarketDataResponseFrame(data=data, index=idx) df.dataset_ids = ('PNL',) replace = Replacer() # mock PerformanceReport.get_pnl() mock = replace('gs_quant.markets.report.PerformanceReport.get_pnl', Mock()) mock.return_value = df # mock GsPortfolioApi.get_reports() mock = replace('gs_quant.api.gs.portfolios.GsPortfolioApi.get_reports', Mock()) mock.return_value = [Report.from_dict({'id': 'RP1', 'positionSourceType': 'Portfolio', 'positionSourceId': 'MP1', 'type': 'Portfolio Performance Analytics', 'parameters': {'transactionCostModel': 'FIXED'}})] with DataContext(datetime.date(2020, 1, 1), datetime.date(2019, 1, 3)): actual = mp.pnl('MP1') assert actual.index.equals(idx) assert all(actual.values == data['pnl']) replace.restore()
def mock_natgas_forward_price(_cls, _q): d = { 'forwardPrice': [ 2.880, 2.844, 2.726, ], 'contract': [ "F21", "G21", "H21", ] } df = MarketDataResponseFrame(data=d, index=pd.to_datetime( [datetime.date(2019, 1, 2)] * 3)) df.dataset_ids = _test_datasets return df