When using rd.content.ipa.financial_contracts.option, how can I overwrite multiple arguments at once
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
1
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 @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...0
Categories
- All Categories
- 6 AHS
- 37 Alpha
- 161 App Studio
- 4 Block Chain
- 4 Bot Platform
- 16 Connected Risk APIs
- 47 Data Fusion
- 30 Data Model Discovery
- 608 Datastream
- 1.3K DSS
- 577 Eikon COM
- 4.9K Eikon Data APIs
- 7 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- Trading API
- 2.7K Elektron
- 1.3K EMA
- 236 ETA
- 519 WebSocket API
- 33 FX Venues
- 10 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 20 Messenger Bot
- 2 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 59 Open Calais
- 264 Open PermID
- 39 Entity Search
- 2 Org ID
- PAM
- PAM - Logging
- 8.4K Private Comments
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 20 RDMS
- 1.4K Refinitiv Data Platform
- 367 Refinitiv Data Platform Libraries
- 3 Refinitiv Due Diligence
- LSEG Due Diligence Portal API
- 3 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.1K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 10 World-Check Customer Risk Screener
- 990 World-Check One
- 44 World-Check One Zero Footprint
- 45 Side by Side Integration API
- Test Space
- 3 Thomson One Smart
- 1.2K TR Internal
- Global Hackathon 2015
- 2 Specialists Who Code
- 10 TR Knowledge Graph
- 150 Transactions
- 142 REDI API
- 1.7K TREP APIs
- 4 CAT
- 21 DACS Station
- 117 Open DACS
- 1.1K RFA
- 103 UPA
- 172 TREP Infrastructure
- 224 TRKD
- 886 TRTH
- 5 Velocity Analytics
- 5 Wealth Management Web Services
- 59 Workspace SDK
- 9 Element Framework
- 5 Grid
- 13 World-Check Data File
- Yield Book Analytics
- 46 中文论坛