コード例 #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
ファイル: 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