Beispiel #1
0
def test_get_reports(mocker):
    id_1 = 'RX1'
    id_2 = 'RX2'

    mock_response = {'results': (
        Report.from_dict({'id': id_1, 'positionSourceType': 'Portfolio', 'positionSourceId': 'MP1',
                          'type': 'Portfolio Performance Analytics', 'parameters': {'transactionCostModel': 'FIXED'}}),
        Report.from_dict({'id': id_2, 'positionSourceType': 'Portfolio', 'positionSourceId': 'MP2',
                          'type': 'Portfolio Performance Analytics', 'parameters': {'transactionCostModel': 'FIXED'}})
    ), 'totalResults': 2}

    expected_response = (
        Report(id=id_1, positionSourceType='Portfolio', positionSourceId='MP1', type='Portfolio Performance Analytics',
               parameters=ReportParameters(transactionCostModel='FIXED')),
        Report(id=id_2, positionSourceType='Portfolio', positionSourceId='MP2', type='Portfolio Performance Analytics',
               parameters=ReportParameters(transactionCostModel='FIXED'))
    )

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

    # run test
    response = GsReportApi.get_reports()
    GsSession.current._get.assert_called_with('/reports?limit=100', cls=Report)
    assert response == expected_response
Beispiel #2
0
def test_get_report_jobs(mocker):
    id_1 = 'RJW55950MF0S0HKN'

    mock_response = {'results': (
        ReportJob.from_dict({'id': id_1, 'positionSourceType': 'Portfolio', 'positionSourceId': 'MP1',
                             'parameters': {'transactionCostModel': 'FIXED'}}),
        ReportJob.from_dict({'id': id_1, 'positionSourceType': 'Portfolio', 'positionSourceId': 'MP2',
                             'parameters': {'transactionCostModel': 'FIXED'}})
    ), 'totalResults': 2}

    expected_response = (
        ReportJob(id=id_1, positionSourceType='Portfolio', positionSourceId='MP1',
                  parameters=ReportParameters(transactionCostModel='FIXED')),
        ReportJob(id=id_1, positionSourceType='Portfolio', positionSourceId='MP2',
                  parameters=ReportParameters(transactionCostModel='FIXED'))
    )

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

    # run test
    response = GsReportApi.get_report_jobs(id_1)
    GsSession.current._get.assert_called_with('/reports/{id}/jobs'.format(id=id_1))
    assert response == expected_response
Beispiel #3
0
def test_set_position_target():
    factor_report = FactorRiskReport(
        report_id='PFRID',
        position_source_type=PositionSourceType.Portfolio,
        position_source_id='PORTFOLIOID',
        report_type=ReportType.Portfolio_Factor_Risk,
        parameters=ReportParameters(fx_hedged=True, risk_model='AXUS4M'),
        status=ReportStatus.done)
    factor_report.set_position_target('MA3FMSN9VNMD')
    assert factor_report.position_source_type == PositionSourceType.Asset
    assert factor_report.type == ReportType.Asset_Factor_Risk
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'
            }
        })
    ]

    # mock PerformanceReport.get()
    mock = replace('gs_quant.markets.report.PerformanceReport.get', Mock())
    mock.return_value = PerformanceReport(
        report_id='RP1',
        position_source_type='Portfolio',
        position_source_id='MP1',
        report_type='Portfolio Performance Analytics',
        parameters=ReportParameters(transaction_cost_model='FIXED'))

    with DataContext(datetime.date(2020, 1, 1), datetime.date(2019, 1, 3)):
        actual = mp.portfolio_pnl('MP1')
        assert actual.index.equals(idx)
        assert all(actual.values == data['pnl'])
    replace.restore()
Beispiel #5
0
def test_get_factor_risk_report(mocker):
    # mock GsSession
    mocker.patch.object(GsSession.__class__,
                        'default_value',
                        return_value=GsSession.get(Environment.QA, 'client_id',
                                                   'secret'))
    mocker.patch.object(GsSession.current,
                        '_get',
                        return_value=Report(
                            id='PFRID',
                            position_source_type=PositionSourceType.Portfolio,
                            position_source_id='PORTFOLIOID',
                            parameters=ReportParameters(risk_model='AXUS4M',
                                                        fx_hedged=True),
                            type=ReportType.Portfolio_Factor_Risk,
                            status=ReportStatus.done))
    # run test
    response = FactorRiskReport.get('PFRID')
    assert response.type == ReportType.Portfolio_Factor_Risk
Beispiel #6
0
def test_report_job(mocker):
    id_1 = 'RX1'
    mock_response = ReportJob(id=id_1, positionSourceType='Portfolio', positionSourceId='MP1',
                              parameters=ReportParameters(transactionCostModel='FIXED'))

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

    # run test
    response = GsReportApi.get_report_job(id_1)
    GsSession.current._get.assert_called_with('/reports/jobs/{id}'.format(id=id_1))
    assert response == mock_response
Beispiel #7
0
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
"""

import pytest

from gs_quant.markets.report import FactorRiskReport, PerformanceReport
from gs_quant.session import *
from gs_quant.target.reports import ReportStatus, PositionSourceType, ReportType, ReportParameters, Report

fake_pfr = FactorRiskReport(report_id='PFRID',
                            position_source_type=PositionSourceType.Portfolio,
                            position_source_id='PORTFOLIOID',
                            report_type=ReportType.Portfolio_Factor_Risk,
                            parameters=ReportParameters(fx_hedged=True,
                                                        risk_model='AXUS4M'),
                            status=ReportStatus.done)

fake_ppa = PerformanceReport(
    report_id='PPAID',
    position_source_type=PositionSourceType.Portfolio,
    position_source_id='PORTFOLIOID',
    report_type=ReportType.Portfolio_Performance_Analytics,
    parameters=None,
    status=ReportStatus.done)

factor_risk_results = [{
    'date': '2021-01-02',
    'factor': 'factor1',
    'pnl': 123,
    'proportionOfRisk': 100,