Exemplo n.º 1
0
def test_coordinates_data(mocker):
    start = dt.datetime(2019, 1, 2, 1, 0)
    end = dt.datetime(2019, 1, 2, 1, 10)
    # mock GsSession and data response
    mocker.patch.object(GsSession.__class__, 'default_value',
                        return_value=GsSession.get(Environment.QA, 'client_id', 'secret'))
    mocker.patch.object(GsSession.current, '_post', side_effect=[{'responses': [{'data': bond_data}]},
                                                                 {'responses': [{'data': swap_data}]},
                                                                 {'responses': [{'data': bond_data},
                                                                                {'data': swap_data}]},
                                                                 {'responses': [{'data': bond_data},
                                                                                {'data': swap_data}]}
                                                                 ])

    coord_data_result = GsDataApi.coordinates_data(coordinates=test_coordinates[0], start=start, end=end)
    assert_frame_equal(coord_data_result, bond_expected_frame)

    str_coord_data_result = GsDataApi.coordinates_data(coordinates=test_str_coordinates[1], start=start, end=end)
    assert_frame_equal(str_coord_data_result, swap_expected_frame)

    coords_data_result = GsDataApi.coordinates_data(coordinates=test_coordinates, start=start, end=end,
                                                    as_multiple_dataframes=True)
    assert len(coords_data_result) == 2
    assert_frame_equal(coords_data_result[0], bond_expected_frame)
    assert_frame_equal(coords_data_result[1], swap_expected_frame)

    GsSession.current._post.reset_mock()
    str_coords_data_result = GsDataApi.coordinates_data(coordinates=test_str_coordinates, start=start, end=end,
                                                        as_multiple_dataframes=True)
    assert len(str_coords_data_result) == 2
    assert_frame_equal(str_coords_data_result[0], bond_expected_frame)
    assert_frame_equal(str_coords_data_result[1], swap_expected_frame)
    GsSession.current._post.assert_called_once_with('/data/coordinates/query',
                                                    payload=MDAPIDataQuery(market_data_coordinates=test_coordinates,
                                                                           start_time=start,
                                                                           end_time=end,
                                                                           vendor=MarketDataVendor.Goldman_Sachs,
                                                                           format="MessagePack"),
                                                    request_headers={'Accept': 'application/msgpack'}
                                                    )
Exemplo n.º 2
0
def test_coordinates_data(mocker):
    # mock GsSession and data response
    mocker.patch.object(GsSession.__class__, 'current',
                        return_value=GsSession.get(Environment.QA, 'client_id', 'secret'))
    mocker.patch.object(GsSession.current, '_post', side_effect=[{'responses': [{'data': bond_data}]},
                                                                 {'responses': [{'data': swap_data}]},
                                                                 {'responses': [{'data': bond_data},
                                                                                {'data': swap_data}]},
                                                                 {'responses': [{'data': bond_data},
                                                                                {'data': swap_data}]}
                                                                 ])

    coord_data_result = GsDataApi.coordinates_data(coordinates=test_coordinates[0], start=dt.datetime(2019, 1, 2, 1, 0),
                                                   end=dt.datetime(2019, 1, 2, 1, 10))
    assert_frame_equal(coord_data_result, bond_expected_frame)

    str_coord_data_result = GsDataApi.coordinates_data(coordinates=test_str_coordinates[1],
                                                       start=dt.datetime(2019, 1, 2, 1, 0),
                                                       end=dt.datetime(2019, 1, 2, 1, 10))
    assert_frame_equal(str_coord_data_result, swap_expected_frame)

    coords_data_result = GsDataApi.coordinates_data(coordinates=test_coordinates, start=dt.datetime(2019, 1, 2, 1, 0),
                                                    end=dt.datetime(2019, 1, 2, 1, 10), as_multiple_dataframes=True)
    assert len(coords_data_result) == 2
    assert_frame_equal(coords_data_result[0], bond_expected_frame)
    assert_frame_equal(coords_data_result[1], swap_expected_frame)

    str_coords_data_result = GsDataApi.coordinates_data(coordinates=test_str_coordinates,
                                                        start=dt.datetime(2019, 1, 2, 1, 0),
                                                        end=dt.datetime(2019, 1, 2, 1, 10), as_multiple_dataframes=True)
    assert len(str_coords_data_result) == 2
    assert_frame_equal(str_coords_data_result[0], bond_expected_frame)
    assert_frame_equal(str_coords_data_result[1], swap_expected_frame)

    GsSession.current._post.assert_called_with('/data/coordinates/query', payload=mocker.ANY)
    assert GsSession.current._post.call_count == 4
Exemplo n.º 3
0
def test_coordinates_data(mocker):
    bond_data = [{
        'mktType': 'Prime',
        'mktAsset': '335320934',
        'mktQuotingStyle': 'price',
        'price': 1.0139,
        'time': pd.to_datetime('2019-01-20T01:03:00Z')
    }, {
        'mktType': 'Prime',
        'mktAsset': '335320934',
        'mktQuotingStyle': 'price',
        'price': 1.0141,
        'time': pd.to_datetime('2019-01-20T01:08:00Z')
    }]
    swap_data = [{
        'mktType': 'IR',
        'mktAsset': 'USD',
        'mktClass': 'Swap',
        'mktPoint': ('2Y', ),
        'mktQuotingStyle': 'ATMRate',
        'ATMRate': 0.02592,
        'time': pd.to_datetime('2019-01-20T01:09:45Z')
    }]

    bond_expected_result = pd.DataFrame(
        data={
            'time': [
                pd.to_datetime('2019-01-20T01:03:00Z'),
                pd.to_datetime('2019-01-20T01:08:00Z')
            ],
            'mktType': ['Prime', 'Prime'],
            'mktAsset': ['335320934', '335320934'],
            'mktQuotingStyle': ['price', 'price'],
            'value': [1.0139, 1.0141]
        },
        index=pd.DatetimeIndex(['2019-01-20T01:03:00', '2019-01-20T01:08:00']),
    )

    swap_expected_result = pd.DataFrame(
        data={
            'time': [pd.to_datetime('2019-01-20T01:09:45Z')],
            'mktType': ['IR'],
            'mktAsset': ['USD'],
            'mktClass': ['Swap'],
            'mktPoint': [('2Y', )],
            'mktQuotingStyle': ['ATMRate'],
            'value': [0.02592]
        },
        index=pd.DatetimeIndex(['2019-01-20T01:09:45']),
    )

    # mock GsSession
    mocker.patch.object(GsSession.__class__,
                        'current',
                        return_value=GsSession.get(Environment.QA, 'client_id',
                                                   'secret'))

    mocker.patch.object(GsSession.current,
                        '_post',
                        side_effect=[{
                            'responses': [{
                                'data': bond_data
                            }]
                        }, {
                            'responses': [{
                                'data': swap_data
                            }]
                        }, {
                            'responses': [{
                                'data': bond_data
                            }, {
                                'data': swap_data
                            }]
                        }, {
                            'responses': [{
                                'data': bond_data
                            }, {
                                'data': swap_data
                            }]
                        }])

    coord_data_result = GsDataApi.coordinates_data(
        coordinates=test_coordinates[0],
        start=dt.datetime(2019, 1, 2, 1, 0),
        end=dt.datetime(2019, 1, 2, 1, 10))
    assert_frame_equal(coord_data_result, bond_expected_result)

    str_coord_data_result = GsDataApi.coordinates_data(
        coordinates=test_str_coordinates[1],
        start=dt.datetime(2019, 1, 2, 1, 0),
        end=dt.datetime(2019, 1, 2, 1, 10))
    assert_frame_equal(str_coord_data_result, swap_expected_result)

    coords_data_result = GsDataApi.coordinates_data(
        coordinates=test_coordinates,
        start=dt.datetime(2019, 1, 2, 1, 0),
        end=dt.datetime(2019, 1, 2, 1, 10),
        as_multiple_dataframes=True)
    assert len(coords_data_result) == 2
    assert_frame_equal(coords_data_result[0], bond_expected_result)
    assert_frame_equal(coords_data_result[1], swap_expected_result)

    str_coords_data_result = GsDataApi.coordinates_data(
        coordinates=test_str_coordinates,
        start=dt.datetime(2019, 1, 2, 1, 0),
        end=dt.datetime(2019, 1, 2, 1, 10),
        as_multiple_dataframes=True)
    assert len(str_coords_data_result) == 2
    assert_frame_equal(str_coords_data_result[0], bond_expected_result)
    assert_frame_equal(str_coords_data_result[1], swap_expected_result)

    GsSession.current._post.assert_called_with('/data/coordinates/query',
                                               payload=mocker.ANY)
    assert GsSession.current._post.call_count == 4
Exemplo n.º 4
0
def test_coordinates_data(mocker):
    bond_data = [{
        'marketDataType': 'Prime',
        'marketDataAsset': '335320934',
        'field': 'price',
        'price': 1.0139,
        'time': pd.to_datetime('2019-01-20T01:03:00Z')
    }, {
        'marketDataType': 'Prime',
        'marketDataAsset': '335320934',
        'field': 'price',
        'price': 1.0141,
        'time': pd.to_datetime('2019-01-20T01:08:00Z')
    }]
    swap_data = [{
        'marketDataType': 'IR',
        'marketDataAsset': 'USD',
        'pointClass': 'Swap',
        'marketDataPoint': ('2Y', ),
        'quotingStyle': 'ATMRate',
        'ATMRate': 0.02592,
        'time': pd.to_datetime('2019-01-20T01:09:45Z')
    }]
    bond_expected_result = [{
        'marketDataType': 'Prime',
        'marketDataAsset': '335320934',
        'field': 'price',
        'value': 1.0139,
        'time': pd.to_datetime('2019-01-20T01:03:00Z')
    }, {
        'marketDataType': 'Prime',
        'marketDataAsset': '335320934',
        'field': 'price',
        'value': 1.0141,
        'time': pd.to_datetime('2019-01-20T01:08:00Z')
    }]
    swap_expected_result = [{
        'marketDataType': 'IR',
        'marketDataAsset': 'USD',
        'pointClass': 'Swap',
        'marketDataPoint': ('2Y', ),
        'quotingStyle': 'ATMRate',
        'value': 0.02592,
        'time': pd.to_datetime('2019-01-20T01:09:45Z')
    }]

    bond_expected_df = sort_risk(pd.DataFrame(bond_expected_result))
    bond_expected_df = bond_expected_df.set_index(
        pd.DatetimeIndex(bond_expected_df.time.values))

    swap_expected_df = sort_risk(pd.DataFrame(swap_expected_result))
    swap_expected_df = swap_expected_df.set_index(
        pd.DatetimeIndex(swap_expected_df.time.values))

    # mock GsSession
    mocker.patch.object(GsSession.__class__,
                        'current',
                        return_value=GsSession.get(Environment.QA, 'client_id',
                                                   'secret'))
    mocker.patch.object(GsSession.current,
                        '_post',
                        side_effect=[{
                            'responses': [{
                                'data': bond_data
                            }]
                        }, {
                            'responses': [{
                                'data': bond_data
                            }, {
                                'data': swap_data
                            }]
                        }])

    coord_data_result = GsDataApi.coordinates_data(
        coordinates=test_coordinates[0],
        start=dt.datetime(2019, 1, 2, 1, 0),
        end=dt.datetime(2019, 1, 2, 1, 10))
    assert_frame_equal(coord_data_result, bond_expected_df)

    coords_data_result = GsDataApi.coordinates_data(
        coordinates=test_coordinates,
        start=dt.datetime(2019, 1, 2, 1, 0),
        end=dt.datetime(2019, 1, 2, 1, 10),
        as_multiple_dataframes=True)
    assert len(coords_data_result) == 2
    assert_frame_equal(coords_data_result[0], bond_expected_df)
    assert_frame_equal(coords_data_result[1], swap_expected_df)