question

Upvotes
Accepted
31 7 7 17

When using rd.content.ipa.financial_contracts.option, how can I overwrite multiple arguments at once in `extended_params`?

With this python code using RDP, I am trying to sent 100 requests in one go (the max this endpoint accepts). How can I entre several dictionaries in `extended_params`?


definition = rd.content.ipa.financial_contracts.option.Definition(  # IPA = instrument Pricing Analytics
    instrument_code=instrument,
    underlying_type=rd.content.ipa.financial_contracts.option.UnderlyingType.ETI,  # ETI = Exchange Traded Instrument
    fields=requestFields,
    extended_params=ATuniverseL)
response = definition.get_data()


AttributeError: 'list' object has no attribute 'item


FYI:


instrument, requestFields


('STXE42500C3.EX',
 ['MarketValueInDealCcy',
  'RiskFreeRatePercent',
  'UnderlyingPrice',
  'PricingModelType',
  'DividendType',
  'VolatilityType',
  'UnderlyingTimeStamp',
  'ReportCcy',
  'VolatilityType',
  'Volatility',
  'DeltaPercent',
  'GammaPercent',
  'RhoPercent',
  'ThetaPercent',
  'VegaPercent'])



ATuniverseL[0]


[{'instrumentType': 'Option',
  'instrumentDefinition': {'buySell': 'Buy',
   'underlyingType': 'Eti',
   'instrumentCode': 'STXE42500C3.EX',
   'strike': '4250'},
  'pricingParameters': {'marketValueInDealCcy': '62.0',
   'riskFreeRatePercent': '2.621',
   'underlyingPrice': '4180.51',
   'pricingModelType': 'BlackScholes',
   'dividendType': 'ImpliedYield',
   'volatilityType': 'Implied',
   'underlyingTimeStamp': 'Default',
   'reportCcy': 'EUR'}},
 {'instrumentType': 'Option',
  'instrumentDefinition': {'buySell': 'Buy',
   'underlyingType': 'Eti',
   'instrumentCode': 'STXE42500C3.EX',
   'strike': '4250'},
  'pricingParameters': {'marketValueInDealCcy': '61.8',
   'riskFreeRatePercent': '2.621',
   'underlyingPrice': '4188.74',
   'pricingModelType': 'BlackScholes',
   'dividendType': 'ImpliedYield',
   'volatilityType': 'Implied',
   'underlyingTimeStamp': 'Default',
   'reportCcy': 'EUR'}}]




I tried to play round with the library, but there seem not to be a way to have multiple values for - say - market_value_in_deal_ccy:

import refinitiv.data.content.ipa.financial_contracts.option as option

definition = option.Definition(  # IPA = instrument Pricing Analytics
    instrument_code=instrument,
    underlying_type=option.UnderlyingType.ETI,  # ETI = Exchange Traded Instrument,
    pricing_parameters=option._option_pricing_parameters.PricingParameters(
        market_value_in_deal_ccy=62.0),
    fields=requestFields)
response = definition.get_data()


And apparently the only available types for this argument are floats, lo list, tuples or dictionaries that are itteratable:

market_value_in_deal_ccy : float, optional

pythonrdp-apiderivativesfuturesipaeti
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvote
Accepted
4.7k 13 2 7

Hi @danieluphromes ,


Here is another solution using the content layer instead:

import refinitiv.data as rd
import refinitiv.data.content.ipa.financial_contracts as rdf
from refinitiv.data.content.ipa.financial_contracts import option
rd.open_session()
response = rdf.Definitions(

    universe=[
        option.Definition(
            underlying_type=option.UnderlyingType.ETI,
            buy_sell = 'Buy',
            instrument_code="STXE42500C3.EX",
            strike= 4250,
            pricing_parameters=option.PricingParameters(
            market_value_in_deal_ccy=62,
            risk_free_rate_percent = 2.621,
            underlying_price =4180.51,
            pricing_model_type= 'BlackScholes',
            volatility_type= 'Implied',
            underlying_time_stamp= 'Default',
            report_ccy='EUR'),

            
        ),

       option.Definition(
            underlying_type=option.UnderlyingType.ETI,
            buy_sell = 'Buy',
            instrument_code="STXE42500C3.EX",
            strike= 4250,
            pricing_parameters=option.PricingParameters(
            market_value_in_deal_ccy=61.8,
            risk_free_rate_percent=2.621,
            underlying_price=4188.74,
            pricing_model_type= 'BlackScholes',
            volatility_type='Implied',
            underlying_time_stamp= 'Default',
            report_ccy= 'EUR'),

        )
    ],
    

    fields=["ValuationDate",
            "OptionType",
            "ExerciseType",
            "ExerciseStyle",
            "DividendType",
            "EndDate",
            "StrikePrice",
            "VolatilityPercent",
            "DeltaPercent",
            "GammaPercent"]
).get_data()

response.data.df

Above I request 2 option definitions with different pricing parameters, you may add more following the logic above. here is the output:

screenshot-2023-02-17-at-183327.png


Hope this is of any help.


Best regards,

Haykaz


icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
1.4k 5 3 6

Hi @danieluphromes

You can try with directly reaching the endpoint:

financial_contracts_endpoint = "https://api.refinitiv.com/data/quantitative-analytics/v1/financial-contracts"
body = {"fields": requestFields,
        "universe": [{'instrumentType': 'Option',
                      'instrumentDefinition': {'buySell': 'Buy',
                                               'underlyingType': 'Eti',
                                               'instrumentCode': instrument,
                                               'strike': '4250'},
                      'pricingParameters': {'marketValueInDealCcy': '62.0',
                                               'riskFreeRatePercent': '2.621',
                                               'underlyingPrice': '4180.51',
                                               'pricingModelType': 'BlackScholes',
                                               'dividendType': 'ImpliedYield',
                                               'volatilityType': 'Implied',
                                               'underlyingTimeStamp': 'Default',
                                               'reportCcy': 'EUR'}
                         },
                     {'instrumentType': 'Option',
                      'instrumentDefinition': {'buySell': 'Buy',
                                                'underlyingType': 'Eti',
                                                'instrumentCode': instrument,
                                                'strike': '4250'},
                          'pricingParameters': {'marketValueInDealCcy': '61.8',
                                                'riskFreeRatePercent': '2.621',
                                                'underlyingPrice': '4188.74',
                                                'pricingModelType': 'BlackScholes',
                                                'dividendType': 'ImpliedYield',
                                                'volatilityType': 'Implied',
                                                'underlyingTimeStamp': 'Default',
                                                'reportCcy': 'EUR'}
                         }]
                }
response = rd.delivery.endpoint_request.Definition(
            url=financial_contracts_endpoint,
            method=rd.delivery.endpoint_request.RequestMethod.POST,
            body_parameters=body
        ).get_data()

Then the raw data can be displayed in a form of a pandas frame

import pandas as pd
names = [i['name'] for i in response.data.raw['headers']]
pd.DataFrame(response.data.raw['data'],columns=names)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Hi @marcin.bunkowski01 , I already tried that but I keep getting random KeyError and ReadTimeout errors. When I don't get them it works fine, but I do at least once when I run my code and it makes it near unusable. I was trying to create try loops to circumvent the issue, but then saw that you build a Python module for just this which - I assumed - handled errors like these.
Long story short: I already tried...

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.