Need a Python code to pull 6 month Implied Volatility for ticker ADYEN.AS
Hi anonymous user,
I'm going to guess that none of the Datastream datasets were convenient for you:
Specifically field 'O6' for 'DADYC.SERIESC'.
If so: do you have access to RD? I'm asking because you used the related 'refinitiv-dataplatform-eikon' tag. If you do not know of RD, or how it relates to Datastream in our line of products, I suggest you read this article. If so, you can access individual Implied Volatility values for ATM (At The Money) Options in Python using RD. To do so, 1st find the RIC you're after with the search bar in Workspace:
2nd, use the DIB to find the field you're after.
Not all-time windows are available there though, and it looks like there aren't 6-month ATM options. In that case, Haykaz's answer above is what you'll be after. If you do not want to specify the expiration day and want it to be simply just the option expiring in 6 months, then I advise you use the Search API (available in RD) in the way shown in this article.If RD is an option for you, please try the below and let us know if it returns the values you expect (I imported too many libraries in a hurry):
import refinitiv.data as rd # This is LSEG's Data and Analytics' API wrapper, called the Refinitiv Data Library for Python.from refinitiv.data.content import historical_pricing # We will use this Python Class in `rd` to show the Implied Volatility data already available before our work.from refinitiv.data.content import search # We will use this Python Class in `rd` to fid the instrument we are after, closest to At The Money.import refinitiv.data.content.ipa.financial_contracts as rdf # We're going to need thtis to use the content layer of the RD library and the calculators of greeks and Impl Volat in Instrument Pricing Analytics (IPA) and Exchange Traded Instruments (ETI)from refinitiv.data.content.ipa.financial_contracts import option # We're going to need thtis to use the content layer of the RD library and the calculators of greeks and Impl Volat in IPA & ETIimport pandas as pd # We need `pandas` for datafame and array manipilations.from datetime import datetime, timedelta, timezone # We use these to manipulate time valuesfrom dateutil.relativedelta import relativedelta # We use `relativedelta` to manipulate time values aiding `calendar` library.# Let's authenticate ourseves to LSEG's Data and Analytics service, Refinitiv:try: # The following libraries are not available in Codebook, thus this try loop rd.open_session(config_name="C:\\Example.DataLibrary.Python-main\\Example.DataLibrary.Python-main\\Configuration\\refinitiv-data.config.json") rd.open_session("desktop.workspace")except: rd.open_session()print(f"Here we are using the refinitiv Data Library version {rd.__version__}")strike = rd.get_history( universe="ADYEN.AS", fields=["TRDPRC_1"], interval="tick").iloc[-1][0]print(f"Strike Price found was {strike}, and we are looking for Options " + f"closest to that price to be At The Money. We are calculating Implied " + f"Volatility as of {datetime.today().strftime('%Y-%m-%d')}." + f" This is the Option used for the calculation:")response1 = search.Definition( view = search.Views.SEARCH_ALL, # To see what views are available: `help(search.Views)` & `search.metadata.Definition(view = search.Views.SEARCH_ALL).get_data().data.df.to_excel("SEARCH_ALL.xlsx")` query="ADYEN.AS", select="DocumentTitle, RIC, StrikePrice, ExchangeCode, ExpiryDate, UnderlyingAsset, " + "UnderlyingAssetName, UnderlyingAssetRIC, ESMAUnderlyingIndexCode, RCSUnderlyingMarket" + "UnderlyingQuoteName, UnderlyingQuoteRIC", filter="RCSAssetCategoryLeaf eq 'Option' and RIC eq 'ADYEN*' and DocumentTitle ne '*Weekly*' " + "and CallPutOption eq 'Call' and ExchangeCode eq 'EUX' and " + f"ExpiryDate ge {(datetime.today() + relativedelta(months=+5)).strftime('%Y-%m-%d')} and " + # https://stackoverflow.com/questions/546321/how-do-i-calculate-the-date-six-months-from-the-current-date-using-the-datetime f"ExpiryDate lt {(datetime.today() + relativedelta(months=+7)).strftime('%Y-%m-%d')}", # ge (greater than or equal to), gt (greater than), lt (less than) and le (less than or equal to). These can only be applied to numeric and date properties. top=100,).get_data()searchDf1 = response1.data.df # This is your result from searchOptionDets = searchDf1.iloc[(searchDf1['StrikePrice']-strike).abs().argsort()[:1]]display(OptionDets)response2 = option.Definition( underlying_type=option.UnderlyingType.ETI, instrument_code=OptionDets.RIC.iloc[0], pricing_parameters=option.PricingParameters( valuation_date=datetime.today().strftime('%Y-%m-%d'), volatility_type="Implied"), fields=["Volatility", "InstrumentCode", "ExerciseType", "OptionType", "ExerciseStyle", "EndDate", "StrikePrice", "MarketValueInDealCcy", "VolatilityPercent", "DeltaPercent", "GammaPercent", "ThetaPercent", "RhoPercent", "ErrorMessage"]).get_data()print(f"Our {OptionDets.RIC.iloc[0]} Implied Volatility is: {response2.data.df.Volatility.iloc[0]}, as per the below:")display(response2.data.df)
Hi anonymous user ,
Thank you for your question. Just to clarify, do you want the implied volatility for the past 6 month period for all active options on ADYEN.AS?
Best regards,
Haykaz
it should be single value based on 6 month time horizon and not a series for 6 month data.
Thank you for the clarification. I am not a content expert on this, but If my understanding is right financial contracts endpoint from IPA might be helpful:
import refinitiv.data as rdfrom refinitiv.data.content.ipa.financial_contracts import optionrd.open_session()
response = option.Definition( underlying_type=option.UnderlyingType.ETI, instrument_code="ADYEN80000F4.E", pricing_parameters=option.PricingParameters( valuation_date="2023-08-12T00:00:00Z", volatility_type="Implied"), fields=["InstrumentCode", "ExerciseType", "OptionType", "ExerciseStyle", "EndDate", "StrikePrice", "MarketValueInDealCcy", "VolatilityPercent", "DeltaPercent", "GammaPercent", "ThetaPercent", "RhoPercent", "ErrorMessage"]).get_data()response.data.df
Is this something you were after?
I do not want to mention any date or strike or any specific feature. Example :
For ticker SX5E we have a reference (100 moneyness) ticker: GXEMONEY100. And we can pull the data using DataStream. Below is the code for the same.
I need same thing for ADYEN.AS
ds.get_data(tickers = 'GXEMONEY100',fields = ["O6"],kind = 0)
This is what the code returned: