Esempio n. 1
0
 def _get_esg_breakdown(self,
                        card: ESGCard,
                        measure: ESGMeasure,
                        pricing_date: dt.date = None) -> pd.DataFrame:
     sector_data = GsEsgApi.get_esg(entity_id=self.id,
                                    pricing_date=pricing_date,
                                    cards=[card],
                                    measures=[measure]).get(card.value)[0].get('results')
     df = pd.DataFrame(sector_data)
     return df.set_index('name')
Esempio n. 2
0
 def _get_esg_ranked_card(self,
                          card: ESGCard,
                          measure: ESGMeasure,
                          pricing_date: dt.date = None) -> pd.DataFrame:
     data = GsEsgApi.get_esg(entity_id=self.id,
                             pricing_date=pricing_date,
                             cards=[card],
                             measures=[measure]).get(card.value)[0].get('results')
     df = pd.DataFrame(data)
     return df.set_index('assetId')
Esempio n. 3
0
 def get_esg_quintiles(self,
                       measure: ESGMeasure,
                       pricing_date: dt.date = None) -> pd.DataFrame:
     """
     Get breakdown of entity by weight in each percentile quintile for requested ESG measure
     :param measure: ESG Measure
     :param pricing_date: optional pricing date; defaults to last previous business day
     :return: a Pandas DataFrame with results
     """
     quintile_data = GsEsgApi.get_esg(entity_id=self.id,
                                      pricing_date=pricing_date,
                                      cards=[ESGCard.QUINTILES],
                                      measures=[measure]).get('quintiles')[0].get('results')
     df = pd.DataFrame(quintile_data)
     df = df.filter(items=['description', 'gross', 'long', 'short'])
     return df.set_index('description')
Esempio n. 4
0
 def get_all_esg_data(self,
                      measures: List[ESGMeasure] = None,
                      cards: List[ESGCard] = None,
                      pricing_date: dt.date = None,
                      benchmark_id: str = None) -> Dict:
     """
     Get all ESG Data
     :param measures: list of ESG Measures to include in results
     :param cards: list of ESG Cards to include in results
     :param pricing_date: optional pricing date; defaults to last previous business day
     :param benchmark_id: optional benchmark asset ID to include in results
     :return: a dictionary of results
     """
     return GsEsgApi.get_esg(entity_id=self.id,
                             pricing_date=pricing_date,
                             cards=cards if cards else [c for c in ESGCard],
                             measures=measures if measures else [m for m in ESGMeasure],
                             benchmark_id=benchmark_id)
Esempio n. 5
0
 def get_esg_summary(self, pricing_date: dt.date = None) -> pd.DataFrame:
     summary_data = GsEsgApi.get_esg(entity_id=self.id,
                                     pricing_date=pricing_date,
                                     cards=[ESGCard.SUMMARY]).get('summary')
     return pd.DataFrame(summary_data)
Esempio n. 6
0
def test_get_risk_models(mocker):
    mock_response = {
        'pricingDate': '2021-04-08',
        'summary': {
            'gross': {
                'gPercentile': 97.57,
                'gRegionalPercentile': 88.94,
                'esPercentile': 89.52,
                'esDisclosurePercentage': 83.33,
                'esMomentumPercentile': 28.15
            },
            'long': {
                'gPercentile': 97.57,
                'gRegionalPercentile': 88.94,
                'esPercentile': 89.52,
                'esDisclosurePercentage': 83.33,
                'esMomentumPercentile': 28.15},
            'short': {
                'gPercentile': None,
                'gRegionalPercentile': None,
                'esPercentile': None,
                'esDisclosurePercentage': None,
                'esMomentumPercentile': None
            },
            'benchmark': {
                'gPercentile': 76.30923829640506,
                'gRegionalPercentile': 54.3718544735162,
                'esPercentile': 51.677217204614415,
                'esDisclosurePercentage': 54.89969169789053,
                'esMomentumPercentile': 48.186284955203256
            }
        },
        'bottomTenRanked': [
            {
                'measure': 'gPercentile',
                'results': [
                    {
                        'assetId': 'MA4B66MW5E27UAHKG34',
                        'name': 'The Goldman Sachs Group, Inc.',
                        'value': 97.57
                    }
                ]
            }, {
                'measure': 'esDisclosurePercentage',
                'results': [
                    {
                        'assetId': 'MA4B66MW5E27UAHKG34',
                        'name': 'The Goldman Sachs Group, Inc.',
                        'value': 83.33
                    }
                ]
            }
        ],
        'noESGData': {
            'gross': {
                'weight': 0.0,
                'assets': []
            },
            'long': {
                'weight': 0.0,
                'assets': []
            },
            'short': {
                'weight': 0.0,
                'assets': []
            },
            'benchmark': {
                'weight': 2.5402270308391683,
                'assets': [
                    {
                        'assetId': 'MA4B66MW5E27UALNB96',
                        'name': 'News Corp - Class B',
                        'weight': 0.026140889953506573
                    }, {
                        'assetId': 'MA4B66MW5E27UANLXX3',
                        'name': 'Under Armour Inc-Class C',
                        'weight': 0.02019587639265163
                    }, {
                        'assetId': 'MA4B66MW5E27UAGYZ49',
                        'name': 'Alphabet Inc-CL C',
                        'weight': 2.4141476728491242
                    }, {
                        'assetId': 'MA4B66MW5E27UAE4MGB',
                        'name': 'Discovery Inc-C',
                        'weight': 0.03970496421509619
                    }, {
                        'assetId': 'MA4B66MW5E27UAGEHL4',
                        'name': 'Fox Corp - Class A',
                        'weight': 0.040037627428790246
                    }
                ]
            }
        }
    }

    # 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 = GsEsgApi.get_esg(entity_id='MPM9Y3434RDFVKA3',
                                benchmark_id='MA4B66MW5E27U8P32SB',
                                pricing_date=dt.date(2021, 4, 8),
                                measures=[Measure.G_PERCENTILE, Measure.ES_DISCLOSURE_PERCENTAGE],
                                cards=[Card.SUMMARY, Card.BOTTOM_TEN_RANKED])
    GsSession.current._get.assert_called_with(
        '/esg/MPM9Y3434RDFVKA3?&date=2021-04-08&benchmark=MA4B66MW5E27U8P32SB&measure=gPercentile&'
        'measure=esDisclosurePercentage&card=summary&card=bottomTenRanked')
    assert response == mock_response