def _value_for_date(result: Union[DataFrameWithInfo, SeriesWithInfo], date: Union[Iterable, dt.date]) -> \ Union[DataFrameWithInfo, ErrorValue, FloatWithInfo]: from gs_quant.markets import CloseMarket raw_value = result.loc[date] key = result.risk_key risk_key = RiskKey( key.provider, date if isinstance(date, dt.date) else tuple(date), CloseMarket(date=date, location=key.market.location if isinstance( key.market, CloseMarket) else None), key.params, key.scenario, key.risk_measure) if isinstance(raw_value, ErrorValue): return raw_value elif isinstance(raw_value, DataFrameWithInfo): raw_df = raw_value.raw_value.set_index('dates') return DataFrameWithInfo(raw_df.reset_index( drop=True) if isinstance(date, dt.date) else raw_df, risk_key=risk_key, unit=result.unit, error=result.error) elif isinstance(raw_value, SeriesWithInfo): return SeriesWithInfo(raw_value.raw_value, risk_key=risk_key, unit=result.unit, error=result.error) else: return FloatWithInfo( risk_key, raw_value, unit=result.unit.get(date, '') if result.unit else None, error=result.error)
def extract_market_data(this_result: DataFrameWithInfo): market_data = {} for _, row in this_result.iterrows(): coordinate_values = {p: row.get(p) for p in properties} mkt_point = coordinate_values.get('mkt_point') if mkt_point is not None: coordinate_values['mkt_point'] = tuple(coordinate_values['mkt_point'].split(';')) # return 'redacted' as coordinate value if its a redacted coordinate market_data[MarketDataCoordinate.from_dict(coordinate_values)] = row['value'] if \ row['permissions'] == 'Granted' else 'redacted' return market_data