Пример #1
0
        def handle_result(result: Optional[Union[DataFrameWithInfo, ErrorValue, PricingFuture]]) -> \
                [OverlayMarket, dict]:
            if isinstance(result, ErrorValue):
                return result

            properties = MarketDataCoordinate.properties()
            is_historical = result.index.name == 'date'
            location = PricingContext.current.market_data_location

            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

            if is_historical:
                return {date: OverlayMarket(
                    base_market=CloseMarket(date=date, location=location),
                    market_data=extract_market_data(result.loc[date]))
                    for date in set(result.index)}
            else:
                return OverlayMarket(base_market=result.risk_key.market,
                                     market_data=extract_market_data(result))
Пример #2
0
        def handle_result(result: Optional[Union[DataFrameWithInfo, ErrorValue, PricingFuture]]) ->\
                [OverlayMarket, dict]:
            properties = MarketDataCoordinate.properties()
            is_historical = isinstance(PricingContext.current,
                                       HistoricalPricingContext)
            location = PricingContext.current.market_data_location

            def extract_market_data(this_result: DataFrameWithInfo):
                market_data = {}

                for _, row in result.iterrows():
                    coordinate_values = {p: row.get(p) for p in properties}
                    if 'mkt_point' in coordinate_values:
                        coordinate_values['mkt_point'] = tuple(
                            coordinate_values['mkt_point'].split(';'))
                    market_data[MarketDataCoordinate.from_dict(
                        coordinate_values)] = row['value']

                return market_data

            if is_historical:
                return {
                    date: OverlayMarket(
                        base_market=CloseMarket(date=date, location=location),
                        market_data=extract_market_data(result.loc[date]))
                    for date in set(result.index)
                }
            else:
                return OverlayMarket(base_market=result.risk_key.market,
                                     market_data=extract_market_data(result))