コード例 #1
0
ファイル: core.py プロジェクト: imbalog/gs-quant
def instrument_formatter(result: List, pricing_key: PricingKey, instrument: InstrumentBase):
    # TODO Handle these correctly in the risk service
    invalid_defaults = ('-- N/A --', 'NaN')
    value_mappings = {'Payer': 'Pay', 'Rec': 'Receive', 'Receiver': 'Receive'}
    instruments_by_date = {}

    for field_values in result:
        field_values = {field: value_mappings.get(value, value) for field, value in field_values.items()
                        if value not in invalid_defaults}

        new_instrument = instrument.from_dict(field_values)
        new_instrument.unresolved = instrument

        if len(result) > 1 and 'date' in field_values:
            date = dt.date.fromtimestamp(field_values['date'] / 1e9) + dt.timedelta(days=1)
            as_of = next((a for a in pricing_key.pricing_market_data_as_of if date == a.pricing_date), None)

            if as_of:
                date_key = pricing_key.clone(pricing_market_data_as_of=as_of)
                new_instrument.resolution_key = date_key
                instruments_by_date[date] = new_instrument
        else:
            new_instrument.resolution_key = pricing_key
            return new_instrument

    return instruments_by_date
コード例 #2
0
def leg_definition_handler(result: dict, risk_key: RiskKey,
                           instrument: InstrumentBase) -> InstrumentBase:
    new_instrument = instrument.from_dict(result)
    new_instrument.unresolved = instrument
    new_instrument.name = instrument.name
    new_instrument.resolution_key = risk_key
    return new_instrument
コード例 #3
0
ファイル: result_handlers.py プロジェクト: jsyzc2019/gs-quant
def leg_definition_handler(result: List, pricing_key: PricingKey, instrument: InstrumentBase)\
        -> Union[InstrumentBase, Mapping[dt.date, InstrumentBase]]:
    instruments_by_date = {}

    for date_key, field_values in zip(pricing_key, result):
        new_instrument = instrument.from_dict(field_values)
        new_instrument.unresolved = instrument
        new_instrument.name = instrument.name
        new_instrument.resolution_key = date_key
        instruments_by_date[date_key.pricing_market_data_as_of[0].pricing_date] = new_instrument

    return instruments_by_date if len(pricing_key) > 1 else next(iter(instruments_by_date.values()))
コード例 #4
0
ファイル: core.py プロジェクト: cottrell/gs-quant
def instrument_formatter(result: List, pricing_key: PricingKey, instrument: InstrumentBase):
    instruments_by_date = {}

    for field_values in result:
        new_instrument = instrument.from_dict(field_values)
        new_instrument.unresolved = instrument
        new_instrument.name = instrument.name

        if len(result) > 1 and 'date' in field_values:
            date = dt.date.fromtimestamp(field_values['date'] / 1e9) + dt.timedelta(days=1)
            as_of = next((a for a in pricing_key.pricing_market_data_as_of if date == a.pricing_date), None)

            if as_of:
                date_key = pricing_key.clone(pricing_market_data_as_of=as_of)
                new_instrument.resolution_key = date_key
                instruments_by_date[date] = new_instrument
        else:
            new_instrument.resolution_key = pricing_key
            return new_instrument

    return instruments_by_date
コード例 #5
0
def leg_definition_handler(result: dict, risk_key: RiskKey,
                           instrument: InstrumentBase) -> InstrumentBase:
    return instrument.resolved(result, risk_key)
コード例 #6
0
def leg_definition_handler(result: dict,
                           risk_key: RiskKey,
                           instrument: InstrumentBase,
                           request_id: Optional[str] = None) -> InstrumentBase:
    return instrument.resolved(result, risk_key)