...face
Hi, Below code is to extract implied volatility data for SP500 index. However, I want to pull data for multiple stocks and indices for multiple time horizon using single run. How can I amend the code to do that?
import refinitiv.data as rd
from refinitiv.data.content.ipa import surfaces
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
rd.open_session()
request_definition = rd.delivery.endpoint_request.Definition(
url="https://api.refinitiv.com/data/quantitative-analytics-curves-and-surfaces/v1/surfaces",
method=rd.delivery.endpoint_request.RequestMethod.POST,
body_parameters={
"universe": [
{
"surfaceTag": "SPX",
"underlyingType": "Eti",
"underlyingDefinition": {
"instrumentCode": ".SPX@RIC"
},
"surfaceParameters": {
"inputVolatilityType": "Quoted",
"timeStamp": "Default",
"priceSide": "Mid",
"volatilityModel": "SSVI",
"xAxis": "Tenor",
"yAxis": "Moneyness",
"calculationDate": "2024-03-21"
},
"surfaceLayout": {
"format": "Matrix",
}
}],
"outputs": ["Data", "ForwardCurve", "MoneynessStrike"]
}
)
response = request_definition.get_data()
surface_tag = response.data.raw['data'][0]['surfaceTag']
_surface_df = pd.DataFrame(
data=response.data.raw['data'][0]['surface'])
surface_df_title = f"{surface_tag} Equity Volatility Surface"
surface_df = pd.DataFrame(
data=_surface_df.loc[1:,1:].values,
index=_surface_df[0][1:],
columns=_surface_df.iloc[0][1:])
surface_df.columns.name = "Moneyness"
surface_df.index.name = "Tenor"
surface_df.loc[["3M","6M"],["1"]]