When using rd.content.ipa.financial_contracts.option, how can I overwrite multiple arguments at o...

...nce 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
Best Answer
-
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.dfAbove I request 2 option definitions with different pricing parameters, you may add more following the logic above. here is the output:
Hope this is of any help.
Best regards,
Haykaz
0
Answers
-
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)0 -
Hi @m.bunkowski , 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...0
Categories
- All Categories
- 3 Polls
- 6 AHS
- 36 Alpha
- 166 App Studio
- 6 Block Chain
- 4 Bot Platform
- 18 Connected Risk APIs
- 47 Data Fusion
- 34 Data Model Discovery
- 685 Datastream
- 1.4K DSS
- 615 Eikon COM
- 5.2K Eikon Data APIs
- 10 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- 3 Trading API
- 2.9K Elektron
- 1.4K EMA
- 252 ETA
- 556 WebSocket API
- 38 FX Venues
- 14 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 23 Messenger Bot
- 3 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 60 Open Calais
- 275 Open PermID
- 44 Entity Search
- 2 Org ID
- 1 PAM
- PAM - Logging
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 22 RDMS
- 1.9K Refinitiv Data Platform
- 652 Refinitiv Data Platform Libraries
- 4 LSEG Due Diligence
- LSEG Due Diligence Portal API
- 4 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.2K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 12 World-Check Customer Risk Screener
- 1K World-Check One
- 46 World-Check One Zero Footprint
- 45 Side by Side Integration API
- 2 Test Space
- 3 Thomson One Smart
- 10 TR Knowledge Graph
- 151 Transactions
- 143 REDI API
- 1.8K TREP APIs
- 4 CAT
- 27 DACS Station
- 121 Open DACS
- 1.1K RFA
- 104 UPA
- 193 TREP Infrastructure
- 228 TRKD
- 917 TRTH
- 5 Velocity Analytics
- 9 Wealth Management Web Services
- 90 Workspace SDK
- 11 Element Framework
- 5 Grid
- 18 World-Check Data File
- 1 Yield Book Analytics
- 46 中文论坛