How to resolve the error 'The service failed to build the volatility surface'
When I executed the following script on CodeBook using RDP Libraries, I could plot a 3D chart of volatility surface, but I can NOT do so today having the following error message.
Can you please let me know the root cause of the error and how to resolve it?
INPUT:
import refinitiv.dataplatform as rdp
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d, Axes3D
import matplotlib.cm as cm
%matplotlib inline
session = rdp.open_desktop_session('DEFAULT_CODE_BOOK_APP_KEY')
endpoint = rdp.Endpoint(session, "https://api.refinitiv.com/data/quantitative-analytics-curves-and-surfaces/v1/surfaces")
request_body={
"universe": [
{ "surfaceTag": "RENAULT",
"underlyingType": "Eti",
"underlyingDefinition": {
"instrumentCode": "RENA.PA"
},
"surfaceParameters": {
"inputVolatilityType": "settle",
"volatilityModel": "SSVI",
"xAxis": "Date",
"yAxis": "Moneyness"
},
"surfaceLayout": { "format": "Matrix" }
},
{ "surfaceTag": "PEUGEOT",
"underlyingType": "Eti",
"underlyingDefinition": {
"instrumentCode": "PEUP.PA"
},
"surfaceParameters": {
"inputVolatilityType": "settle",
"volatilityModel": "SSVI",
"xAxis": "Date",
"yAxis": "Moneyness"
},
"surfaceLayout": { "format": "Matrix" }
},
{ "surfaceTag": "BMW",
"underlyingType": "Eti",
"underlyingDefinition": {
"instrumentCode": "BMWG.DE"
},
"surfaceParameters": {
"inputVolatilityType": "settle",
"volatilityModel": "SSVI",
"xAxis": "Date",
"yAxis": "Moneyness"
},
"surfaceLayout": { "format": "Matrix" }
},
{ "surfaceTag": "VW",
"underlyingType": "Eti",
"underlyingDefinition": {
"instrumentCode": "VOWG.DE"
},
"surfaceParameters": {
"inputVolatilityType": "settle",
"volatilityModel": "SSVI",
"xAxis": "Date",
"yAxis": "Moneyness"
},
"surfaceLayout": { "format": "Matrix" }
}]
}
response = endpoint.send_request(
method = rdp.Endpoint.RequestMethod.POST,
body_parameters = request_body
)
def convert_yyyymmdd_to_float(time_axis):
float_time_axis = []
for time in time_axis:
time = time.replace('-', '')
float_time_axis.append(float(time))
return float_time_axis
def plot_surface(surfaces, surfaceTag):
#various imports removed for brevity
surfaces = pd.DataFrame(data=surfaces)
surfaces.set_index('surfaceTag', inplace=True)
surface = surfaces[surfaces.index == surfaceTag]['surface'][0]
strike_axis = surface[0][1:]
surface = surface[1:]
time_axis = []
surface_grid = []
for line in surface:
time_axis.append(line[0])
surface_grid_line = line[1:]
surface_grid.append(surface_grid_line)
time_axis = convert_yyyymmdd_to_float(time_axis)
x = np.array(strike_axis, dtype=float)
y = np.array(time_axis, dtype=float)
ero = np.array(surface_grid, dtype=float)
X,Y = np.meshgrid(x,y)
Z = ero
fig = plt.figure(figsize=[15,10])
ax = plt.axes(projection='3d')
ax.set_xlabel('moneyness')
ax.set_ylabel('time to expiry')
ax.set_zlabel('volatilities')
surf = ax.plot_surface(X,Y,Z, cmap=cm.coolwarm, linewidth=0, antialiased=False)
plt.show()
surfaces = response.data.raw['data']
plot_surface(surfaces, 'VW')
OUTPUT:
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
/opt/conda/lib/python3.7/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
2894 try:
-> 2895 return self._engine.get_loc(casted_key)
2896 except KeyError as err:
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'surface'
The above exception was the direct cause of the following exception:
KeyError Traceback (most recent call last)
<ipython-input-35-aa5486f52eab> in <module>
1 surfaces = response.data.raw['data']
----> 2 plot_surface(surfaces, 'VW')
3 # plot_surface(surfaces, 'BMW')
<ipython-input-16-d9df2e95c642> in plot_surface(surfaces, surfaceTag)
10 surfaces = pd.DataFrame(data=surfaces)
11 surfaces.set_index('surfaceTag', inplace=True)
---> 12 surface = surfaces[surfaces.index == surfaceTag]['surface'][0]
13
14 strike_axis = surface[0][1:]
/opt/conda/lib/python3.7/site-packages/pandas/core/frame.py in __getitem__(self, key)
2904 if self.columns.nlevels > 1:
2905 return self._getitem_multilevel(key)
-> 2906 indexer = self.columns.get_loc(key)
2907 if is_integer(indexer):
2908 indexer = [indexer]
/opt/conda/lib/python3.7/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
2895 return self._engine.get_loc(casted_key)
2896 except KeyError as err:
-> 2897 raise KeyError(key) from err
2898
2899 if tolerance is not None:
KeyError: 'surface'
INPUT:
surfaces
OUTPUT:
[{'surfaceTag': 'RENAULT',
'error': {'id': '3b6ecb24-f876-4b9c-a965-9e05400fb629/e7b8fa38-c5b3-40b3-b1bb-8f7fad66fcde',
'status': 'Error',
'message': 'The service failed to build the volatility surface',
'code': 'VolSurf.10300'}},
{'surfaceTag': 'PEUGEOT',
'error': {'id': '3b6ecb24-f876-4b9c-a965-9e05400fb629/4b652a29-ff3b-4277-9e44-d933273c8888',
'status': 'Error',
'message': 'Unknown underlying : PEUP.PA@RIC',
'code': 'VolSurf.10008'}},
{'surfaceTag': 'BMW',
'error': {'id': '3b6ecb24-f876-4b9c-a965-9e05400fb629/854b01f4-a046-4340-a16e-8b5830496185',
'status': 'Error',
'message': 'The service failed to build the volatility surface',
'code': 'VolSurf.10300'}},
{'surfaceTag': 'VW',
'error': {'id': '3b6ecb24-f876-4b9c-a965-9e05400fb629/2bee51a2-780f-40db-871b-15cdb883fc41',
'status': 'Error',
'message': 'The service failed to build the volatility surface',
'code': 'VolSurf.10300'}}]
Best Answer
-
If the code was working previously and has now stopped working - this is most likely due to a temporary issue with the IPA service.
I have just tried your code both in Codebook and as a standalone script connecting directly to RDP - and both are working fine.
If you are still having issues, and you have an RDP machineID + password etc, then I would recommend you try your code outside of Codebook.
If you continue to have issues, please raise a MyRefinitiv ticket for the 'Instrument Pricing Analytics - Refinitiv Data Platform ' Product or for Codebook - depending on whether your code works outside of Codebook or not.
Please attach your source code and output to the ticket.
0
Answers
-
I've confirmed I can retrieve the data successful again now. Thank you for looking into it!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 中文论坛