For a deeper look into our Eikon Data API, look into:

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
86 2 3 7

volatility surface

Hi,

I am trying to get this function to work in eikon but I was not able to make it work. Could you advice how to retrieve this?

Eikon excel:

TR("SAN.MC","TR.SurfVolMoneyness","CH:Range RH:Tenor Range:50;150 Tenor:1M;10M VolType:MID",,)

Python:

case 1:

case 2:

eikoneikon-data-apiworkspaceworkspace-data-apirefinitiv-dataplatform-eikonpythonvolatility
untitled1.png (11.0 KiB)
untitled2.png (14.6 KiB)
icon clock
10 |1500

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

Upvote
Accepted
39.2k 75 11 27

@daniel.fernandez
Here's an alternative syntax to the one provided by @nick.zincone.1, which is probably more suitable for your use case.

df, err = ek.get_data("SAN.MC",["TR.SurfVolMoneyness.tenor","TR.SurfVolMoneyness.range","TR.SurfVolMoneyness"],{"Range":"50;150", "Tenor":"1M;10M", "VolType":"MID"})

The caveat here is that Eikon Python library does not provide capability to control what labels are returned as column and row headers the way =TR Excel worksheet function does. get_data method ignores RH and CH parameters. This is why you need to include in the field list TR.SurfVolMoneyness.tenor and TR.SurfVolMoneyness.range.
And then if you'd like to format the resulting table the same way the table returned by =TR function is formatted, you need to do a bit of manipulation with the dataframe returned by get_data method.
First remove the Instrument column.

df = df.drop('Instrument', axis=1)

Then reshape or pivot the table using tenor as row headers and moneyness range as column headers.

df = df.pivot(index='Tenor', columns='Range', values='Moneyness')

Finally you'll notice that index labels are ordered lexicographically, which means that "10M" comes before "1M" and "100%" comes before "50%". To produce the same table as the one returned by =TR function we need to reindex the dataframe. To reorder the rows you can use

df = df.iloc[df.index.str.extract('(\d+)', expand=False).astype(int).argsort()]

and to reorder the columns use

df = df.reindex(columns = df.columns[df.columns.str.extract('(\d+)', expand=False).astype(int).argsort()])

Now the dataframe fully conforms to the table returned by =TR function. This said, unless the objective is to display the data as a table, all this dataframe manipulation is probably quite unnecessary. If you are looking to do some calcs based on the values retrieved, the values can be easily accessed from the dataframe returned by get_data method without any reshaping and reindexing.

icon clock
10 |1500

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

Upvote
9.7k 49 38 60

Hi @daniel.fernandez,

When formulating syntax, the DIB - Data Item Browser within Eikon can be extremely useful. For example, pulling up the details above within DIB, click on Parameters

You can pull out the specification detailed within the bottom right corner and paste this into you field specific, i.e.

df, err = tr.get_data("IBM.N", 
     ["TR.SurfVolMONEYNESS(Tenor=1M:10M,Range=50:100,VolType=Mid)"])


ahs.png (40.1 KiB)
ahs2.png (19.4 KiB)
icon clock
10 |1500

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

Upvotes
86 2 3 7

Great feedback, than you both for all the information it was very useful!

icon clock
10 |1500

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

Click below to post an Idea Post Idea